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

时间:2015-03-05 11:07:42

标签: python nltk wordnet

wordnet演示为shown here,在其搜索结果中显示文件的词汇信息。例如,运动这个词有许多词汇类别(因为它有许多“感官”),其中一个是“动词。运动”。我见过另一个questions但他们没有解释你如何做到这一点在NLTK。如何使用NLTK获取该信息。

2 个答案:

答案 0 :(得分:3)

@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语料库。

答案 1 :(得分:0)

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

要添加到404pio的答案中,

代替此:

synset.lexname

您想要这个:

synset.lexname()

原因:他们只是更新并更改了nltk。

来源:https://stackoverflow.com/a/27796656