Skip to content

Instantly share code, notes, and snippets.

@ahmedbesbes
Created August 23, 2022 21:44
Show Gist options
  • Save ahmedbesbes/d541a28bbaab1668d39db620241a50c6 to your computer and use it in GitHub Desktop.
Save ahmedbesbes/d541a28bbaab1668d39db620241a50c6 to your computer and use it in GitHub Desktop.
from spacy.matcher import Matcher
nlp = spacy.load("en_core_web_sm")
doc = nlp("You should definitely buy Bitcoin")
pattern = [
{"LEMMA": {"IN": ["buy", "sell"]}},
{"LOWER": {"IN": ["bitcoin", "dogecoin"]}},
]
matcher = Matcher(nlp.vocab)
matcher.add("HelloWorld", [pattern])
matcher(doc)
# [(15578876784678163569, 3, 5)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment