Last active
August 21, 2022 09:14
-
-
Save ahmedbesbes/8f69146a4ad450290c1cb555c7fe48e0 to your computer and use it in GitHub Desktop.
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 | |
nlp = spacy.blanc("en") | |
doc_before = nlp("John lives in Atlanta") | |
# No entities are detected | |
print(doc_before.ents) | |
# () | |
# Create an entity ruler and add it some patterns | |
entity_ruler = nlp.add_pipe("entity_ruler") | |
patterns = [ | |
{ | |
"label": "PERSON", | |
"pattern": "John", | |
"id": "john", | |
}, | |
{ | |
"label": "GPE", | |
"pattern": [{"LOWER": "atlanta"}], | |
"id": "atlanta", | |
}, | |
] | |
entity_ruler.add_patterns(patterns) | |
doc_after = nlp("Jonh lives in Atlanta.") | |
for ent in doc.ents: | |
print(ent.text, ":", ent.label_) | |
# John : PERSON | |
# atlanta : GPE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment