NLTK Wordnet 获取 Python 中的 Synsets 列表
NLTK Wordnet getting the list of Synsets in Python
我正在使用 NLTK Wordnet 为意大利语创建引理和同义词集,看起来不错:
from nltk.corpus import wordnet as wn
ll=wn.synsets('carta', lang='ita')
ll
[Synset('card.n.01'),
Synset('map.n.01'),
Synset('sheet.n.02'),
Synset('document.n.01'),
Synset('charter.n.01'),
Synset('menu.n.01'),
Synset('paper.n.01')]
hypernyms[0].lemmas(lang="ita")
[Lemma('paper.n.01.carta')]
但我试图在最后一次操作后不仅接收一个列表值,而且还列出了我在 ll
.
中所有同义词集的所有值
使用了几种方法但它们不起作用:
第一个,仍在使用 NLTK:
lemmas = wn.lemmas(ll, lang="ita")
'list' object has no attribute 'lower'
还有一个循环:
i = iter(list(range(6)))
for i in ll[i].lemmas(lang='ita'):
print(ll[i].lemmas(lang='ita'))
list indices must be integers or slices, not list_iterator
如何解决?
使用列表理解
[synset.lemmas(lang='ita') for synset in ll]
输出
[[Lemma('card.n.01.carta')],
[Lemma('map.n.01.carta'),
Lemma('map.n.01.carta_geografica'),
Lemma('map.n.01.cartina'),
Lemma('map.n.01.mappa')],
[Lemma('sheet.n.02.carta'), Lemma('sheet.n.02.foglio')],
[Lemma('document.n.01.atto'),
Lemma('document.n.01.carta'),
Lemma('document.n.01.documento'),
Lemma('document.n.01.incartamento'),
Lemma('document.n.01.scrittura')],
[Lemma('charter.n.01.carta'), Lemma('charter.n.01.statuto')],
[Lemma('menu.n.01.carta'), Lemma('menu.n.01.menu'), Lemma('menu.n.01.menù')],
[Lemma('paper.n.01.carta')]]
我正在使用 NLTK Wordnet 为意大利语创建引理和同义词集,看起来不错:
from nltk.corpus import wordnet as wn
ll=wn.synsets('carta', lang='ita')
ll
[Synset('card.n.01'),
Synset('map.n.01'),
Synset('sheet.n.02'),
Synset('document.n.01'),
Synset('charter.n.01'),
Synset('menu.n.01'),
Synset('paper.n.01')]
hypernyms[0].lemmas(lang="ita")
[Lemma('paper.n.01.carta')]
但我试图在最后一次操作后不仅接收一个列表值,而且还列出了我在 ll
.
使用了几种方法但它们不起作用:
第一个,仍在使用 NLTK:
lemmas = wn.lemmas(ll, lang="ita")
'list' object has no attribute 'lower'
还有一个循环:
i = iter(list(range(6)))
for i in ll[i].lemmas(lang='ita'):
print(ll[i].lemmas(lang='ita'))
list indices must be integers or slices, not list_iterator
如何解决?
使用列表理解
[synset.lemmas(lang='ita') for synset in ll]
输出
[[Lemma('card.n.01.carta')],
[Lemma('map.n.01.carta'),
Lemma('map.n.01.carta_geografica'),
Lemma('map.n.01.cartina'),
Lemma('map.n.01.mappa')],
[Lemma('sheet.n.02.carta'), Lemma('sheet.n.02.foglio')],
[Lemma('document.n.01.atto'),
Lemma('document.n.01.carta'),
Lemma('document.n.01.documento'),
Lemma('document.n.01.incartamento'),
Lemma('document.n.01.scrittura')],
[Lemma('charter.n.01.carta'), Lemma('charter.n.01.statuto')],
[Lemma('menu.n.01.carta'), Lemma('menu.n.01.menu'), Lemma('menu.n.01.menù')],
[Lemma('paper.n.01.carta')]]