首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >WordNet中单词的同义词集

WordNet中单词的同义词集
EN

Stack Overflow用户
提问于 2019-04-25 03:16:45
回答 1查看 1.5K关注 0票数 1

我正在尝试使用python在WordNet (which is Lexical database for English)中查找Synsets

下面是我试图查找的同义词集和同义词集示例(作为参数传递):

 from nltk.corpus import wordnet
synonynm=wordnet.synsets('friend')[2]#? wt does[0] mean
synonynm.name() #related synonyms wrds
synonynm.definition() #definition of passed words
wordnet.synsets('friend')[0].examples()

当我使用索引wordnet.synsets('friend')[0]wordnet.synsets('friend')[1]wordnet.synsets('friend')[2]

它给出了可以在此处查看的相同输出

['he was my best friend at the university']

但是,如果确实将大括号放空,则会显示错误[]

所以我只想知道这两者的区别是什么

synonynm=wordnet.synsets('friend')[0]

还有这个

wordnet.synsets('friend')[1]

如果能得到您的指导我将不胜感激

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-25 03:37:03

wordnet.synsets('friend')返回一个同义词集列表:

[Synset('friend.n.01'), Synset('ally.n.02'), Synset('acquaintance.n.03'), Synset('supporter.n.01'), Synset('friend.n.05')]

然后你可以通过索引访问列表中的每个同义词集,例如。列表中的第一个同义词集是:

wordnet.synsets('friend')[0] # Synset('friend.n.01')
wordnet.synsets('friend')[0].name() # friend.n.01
wordnet.synsets('friend')[0].definition() # a person you know well and regard with affection and trust
wordnet.synsets('friend')[0].examples() # ['he was my best friend at the university']

下面是打印列表中每个同义词集的名称、定义和示例的代码片段:

from nltk.corpus import wordnet
for result in wordnet.synsets('friend'):
    print(result.name(), result.definition(), result.examples())

输出:

friend.n.01 a person you know well and regard with affection and trust ['he was my best friend at the university']
ally.n.02 an associate who provides cooperation or assistance ["he's a good ally in fight"]
acquaintance.n.03 a person with whom you are acquainted ['I have trouble remembering the names of all my acquaintances', 'we are friends of the family']
supporter.n.01 a person who backs a politician or a team etc. ['all their supporters came out for the game', 'they are friends of the library']
friend.n.05 a member of the Religious Society of Friends founded by George Fox (the Friends have never called themselves Quakers) []

请注意,在您的代码中,如果希望在同义词集列表中包含索引2的示例,则应执行以下操作:

from nltk.corpus import wordnet
synonynm=wordnet.synsets('friend')[2]
synonynm.name() #related synonyms words
synonynm.definition() #definition of passed words
synonynm.examples()
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55837113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档