如何使用 NLTK(python) 在 wordnet 中查找单词的词法类别

How to find the Lexical Category of a word in wordnet using NLTK(python)

wordnet 演示 shown here displays the lexical information of a file in its search result. for example the word motion has many lexical categories( as it has many "senses" ) one of them being "verb.motion".I have seen the other questions 但他们没有解释如何在 NLTK 中执行此操作。我如何使用 NLTK 获取该信息。

@Kiran Yallabandi

我不知道你想要什么。但是现在,我有例子:

In [1]: from nltk.corpus import wordnet as wn

In [35]: for synset in wn.synsets('move'):
    print "<%s> (%s) %s" % (synset.lexname, synset.definition, 

synset.examples)
   ....:     
<noun.act> (the act of deciding to do something) ["he didn't make a move to help", 'his first move was to hire a lawyer']
<noun.act> (the act of changing your residence or place of business) ['they say that three moves equal one fire']
<noun.act> (a change of position that does not entail a change of location) ['the reflex motion of his eyebrows revealed his surprise', 'movement is a sign of life', 'an impatient move of his hand', 'gastrointestinal motility']
<noun.act> (the act of changing location from one place to another) ['police controlled the motion of the crowd', 'the movement of people from the farms to the cities', 'his move put him directly in my path']
<noun.act> ((game) a player's turn to take some action permitted by the rules of the game) []
<verb.motion> (change location; move, travel, or proceed, also metaphorically) ['How fast does your new car go?', 'We travelled from Rome to Naples by bus', 'The policemen went from door to door looking for the suspect', 'The soldiers moved towards the city in an attempt to take it before night fell', 'news travelled fast']
<verb.motion> (cause to move or shift into a new position or place, both in a concrete and in an abstract sense) ['Move those boxes into the corner, please', "I'm moving my money to another bank", 'The director moved more responsibilities onto his new assistant']
<verb.motion> (move so as to change position, perform a nontranslational motion) ['He moved his hand slightly to the right']
<verb.motion> (change residence, affiliation, or place of employment) ['We moved from Idaho to Nebraska', 'The basketball player moved from one team to another']
<verb.social> (follow a procedure or take a course) ['We should go farther in this matter', 'She went through a lot of trouble', 'go about the world in a certain manner', 'Messages must go through diplomatic channels']
<verb.body> (be in a state of action) ['she is always moving']
<verb.change> (go or proceed from one point to another) ['the debate moved from family values to the economy']
<verb.social> (perform an action, or work out or perform (an action)) ['think before you act', 'We must move quickly', 'The governor should act on the new energy bill', 'The nanny acted quickly by grabbing the toddler and covering him with a wet towel']
<verb.emotion> (have an emotional or cognitive impact upon) ['This child impressed me as unusually mature', 'This behavior struck me as odd']
<verb.creation> (give an incentive for action) ['This moved me to sacrifice my career']
<verb.emotion> (arouse sympathy or compassion in) ['Her fate moved us all']
<verb.possession> (dispose of by selling) ['The chairman of the company told the salesmen to move the computers']
<verb.change> (progress by being changed) ['The speech has to go through several more drafts', 'run through your presentation before the meeting']
<verb.social> (live one's life in a specified environment) ['she moves in certain circles only']
<verb.competition> (have a turn; make one's move in a game) ['Can I go now?']
<verb.communication> (propose formally; in a debate or parliamentary meeting) []

这就是你需要的吗?您必须通过 nltk 下载器下载 wordnet 语料库。

太糟糕了,它不允许我添加评论,我必须提交作为答案。

要添加到 404pio 的答案,

而不是这个:

synset.lexname

你想要这个:

synset.lexname()

原因:他们只是对nltk进行了更新和修改。

来源: