[英]Get the type of a NLTK Tree()
我正在使用 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']),
['.']]
當我在此列表中使用索引時,我得到以下 output:
semcor.tagged_sents(tag="sem")[0][1][0]
>>> Tree('NE', ['Fulton', 'County', 'Grand', 'Jury'])
當我再使用一個索引時,我會從列表中獲取標記為 output:
semcor.tagged_sents(tag="sem")[0][1][0][0]
>>> 'Fulton'
我的目標有兩個:
我可以使用什么代碼來獲得引理為 output? 所以 output 將是:
>>> Tree(Lemma('group.n.01.group')
我可以使用什么代碼來獲取 output 的樹類型? 在此示例中:
>>> 'NE'
semcor.tagged_sents(tag="sem")[0][1].label()
#'group.n.01'
semcor.tagged_sents(tag="sem")[0][1][0].label()
#'NE'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.