问题
I tried to get the morphological attributes of the verb using Spacy like below:
import spacy
from spacy.lang.it.examples import sentences
nlp = spacy.load('it_core_news_sm')
doc = nlp('Ti è piaciuto il film?')
token = doc[2]
nlp.vocab.morphology.tag_map[token.tag_]
output was:
{'pos': 'VERB'}
But I want to extract
V__Mood=Cnd|Number=Plur|Person=1|Tense=Pres|VerbForm=Fin": {POS: VERB}
Is it possible to extract the mood, tense,number,person information as specified in the tag-map https://github.com/explosion/spacy/blob/master/spacy/lang/it/tag_map.py like above using Spacy?
回答1:
The nlp.vocab.morphology.tag_map
maps from the detailed tag to the dict with simpler tag, so you just need to skip that step and inspect the tag directly:
import spacy
nlp = spacy.load('it')
doc = nlp('Ti è piaciuto il film?')
print(doc[2].tag_)
should return
VA__Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin
(with spacy 2.0.11, it_core_news_sm-2.0.0)
来源:https://stackoverflow.com/questions/53755559/how-to-extract-tag-attributes-using-spacy