How to extract tag attributes using Spacy

浪子不回头ぞ 提交于 2020-01-15 07:20:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!