如何使用Spacy提取标签属性 [英] How to extract tag attributes using Spacy

查看:481
本文介绍了如何使用Spacy提取标签属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Spacy来获取动词的词法属性,如下所示:

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_]

输出为:

{'pos':'VERB'}

{'pos': 'VERB'}

但是我要提取

V__Mood = Cnd | Number = Plur | Person = 1 | Tense = Pres | VerbForm = Fin:{POS:VERB}

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?

推荐答案

nlp.vocab.morphology.tag_map从详细标签映射到具有更简单标签的字典,因此您只需要跳过该步骤并直接检查标签:

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_)

应该返回

VA__Mood = Ind | Number = Sing | Person = 3 | Tense = Pres | VerbForm = Fin

VA__Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin

(使用spacy 2.0.11,it_core_news_sm-2.0.0)

(with spacy 2.0.11, it_core_news_sm-2.0.0)

这篇关于如何使用Spacy提取标签属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆