我使用的是NLTK的Semcor模块:
nltk.download('semcor')
from nltk.corpus import semcor
semcor.tagged_sents()
使用附加注释(包括WordNet引理标识符)迭代相同的句子。
semcor.tagged_sents(tag="sem")[0]
>>> [['The'],
Tree(Lemma('group.n.01.group'), [Tree('NE', ['Fulton', 'County', 'Grand', 'Jury'])]),
Tree(Lemma('state.v.01.say'), ['said']),
Tree(Lemma('friday.n.01.Friday'), ['Friday']),
['an'],
Tree(Lemma('probe.n.01.investigation'), ['investigation']),
['of'],
Tree(Lemma('atlanta.n.01.Atlanta'), ['Atlanta']),
["'s"],
Tree(Lemma('late.s.03.recent'), ['recent']),
Tree(Lemma('primary.n.01.primary_election'), ['primary', 'election']),
Tree(Lemma('produce.v.04.produce'), ['produced']),
['``'],
['no'],
Tree(Lemma('evidence.n.01.evidence'), ['evidence']),
["''"],
['that'],
['any'],
Tree(Lemma('abnormality.n.04.irregularity'), ['irregularities']),
Tree(Lemma('happen.v.01.take_place'), ['took', 'place']),
['.']]
当我在这个列表中使用索引时,我得到以下输出:
semcor.tagged_sents(tag="sem")[0][1][0]
>>> Tree('NE', ['Fulton', 'County', 'Grand', 'Jury'])
当我再使用一个索引时,我从列表中获取标记作为输出:
semcor.tagged_sents(tag="sem")[0][1][0][0]
>>> 'Fulton'
我的目标有两个:
我可以使用什么代码来获得引理作为输出? 因此输出将是:
>>> Tree(Lemma('group.n.01.group')
我可以使用什么代码来获取作为输出的树的类型? 在本例中:
>>> 'NE'
semcor.tagged_sents(tag="sem")[0][1].label()
#'group.n.01'
semcor.tagged_sents(tag="sem")[0][1][0].label()
#'NE'