Synsets для слова в WordNet - PullRequest
       25

Synsets для слова в WordNet

1 голос
/ 24 апреля 2019

Я пытаюсь найти Synsets в WordNet (which is Lexical database for English), используя python.

Вот код, который я пытаюсь найти наборов и пример этих наборов (передается в качестве параметра):

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

, но если бы поставили фигурные скобкипусто показало ошибку []

, поэтому я просто хочу знать, есть ли разница в uasge между

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

и этим

wordnet.synsets('friend')[1]

Я был бы благодарен заваше руководство

1 Ответ

2 голосов
/ 24 апреля 2019

wordnet.synsets('friend') возвращает список Synsets:

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

Затем вы можете получить доступ к каждому Synset в списке по его индексу, например.первый Synset в списке:

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

Вот фрагмент кода, который печатает имя, определение и примеры для каждого Synset в списке:

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 в списке Synsets, вы должны сделать:

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