简体   繁体   中英

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

The wordnet demo as 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 but they do not explain as to how you could do this in NLTK. How can I obtain that information using NLTK.

@Kiran Yallabandi

I didn't know what you want. But now, I have example:

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) []

Is this that, what you need? You have to have wordnet corpus downloaded via nltk downloader.

Too bad it wont let me add comment, I have to submit as answer.

To add to 404pio's answer,

instead of this:

synset.lexname

you want this:

synset.lexname()

Reason: they have simply updated and made changes to nltk.

Source: https://stackoverflow.com/a/27796656

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM