Created
July 14, 2022 11:45
-
-
Save koaning/ae2fc2eee2fe5e45acd6eda84aaead36 to your computer and use it in GitHub Desktop.
Demonstration of Operators and Quantifiers from spaCy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spacy | |
from spacy import displacy | |
def show_results(text, patterns): | |
nlp = spacy.blank("en") | |
ruler = nlp.add_pipe("entity_ruler") | |
ruler.add_patterns(patterns) | |
doc = nlp(text) | |
displacy.render(doc, style="ent") | |
patterns = [ | |
{ | |
"label":"MUSEUM", | |
"pattern":[ | |
{"IS_UPPER": True, "OP": "*"}, | |
{"IS_TITLE": True, "OP": "*"}, | |
{"LOWER": {"IN": ["gallery", "museum"]}}, | |
{"LOWER": "of", "OP": "?"}, | |
{"IS_TITLE": True, "OP": "*"}, | |
] | |
} | |
] | |
text = "On my trip to Amsterdam I visited the National Museum of Arts, the Museum of Natural Sciences, the NEMO Science Museum and the Royal Gallery." | |
show_results(text, patterns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment