Hi, please let me congratulate for the job I have done with the Mastering Spacy book, I just wonder if you managed to run the example that is under "Combining linguistic features and named entities" section:
Here is the code, but I get an error.
import spacy
nlp = spacy.load("en_core_web_md")#we created a Language object, nlp
doc = nlp("Einstein lived in Zurich.")
person_ents = [ent for ent in doc.ents if ent.label_ == "PERSON"]
for person_ent in person_entities:
#We use head of the entity's last token
head = person_ent[-1].head if head.lemma_ == "live":
#Check if the children of live contains prepositionalattachment
preps = [token for token in head.children if token.dep_ == "prep"]
for prep in preps:
places = [token for token in prep.children if token.ent_type_ == "GPE"]
# Verb is in past or present tense
print({'person': person_ent, 'city': places, 'past': head.tag_ == "VBD"})