TTT
TTT

Reputation: 317

Python: Adjective Synsets in NLTK

Is there a method in NLTK to be able to find certain adjective attributes that describe the word? For example, if I typed in the word "Skyscraper", attributes such as 'tall', 'structured', etc. would appear. I'm more so interested in the reverse, where if I type in the word 'tall' then it will list the semantic relations with other words.

I believe the attribute method on NLTK is meant for this, but it doesn't work particularly the way I described above and this is the code that I'm using for it:

from nltk.corpus import wordnet as wn
synsets = wn.synsets('skyscraper')
print[str(syns.attributes()) for syns in synsets]

I've tried using the part_meronyms and attributes methods, but this doesn't always result the adjective attributes of a word. I know of other Python tools that would allow me to do this, but I would prefer to use only NLTK as of now.

Upvotes: 3

Views: 1796

Answers (1)

Ram Narasimhan
Ram Narasimhan

Reputation: 22516

Using purely NLTK, you can achieve this as a two-step process, with your own functions.

Basic Idea

  • Step 1. Find all meaningful collocations for your target word ("skyscraper" or "tall")
  • Step 2. For the adjectives identified in those collocations that are of interest to you, parse the POS to get the semantic relations.

For Step 1. this SO question on Scoring bigrams has defs that are very relevant. You'll have to tweak the BigramAssocMeasures to your problem. (It uses the brown corpus, but you can use many others.)

For Step 2. you could use something like pos_tag() or even Tree.parse() to get the associations that you are looking for to your target adjective.

For a (simpler) and alternative approach, this link has examples of text.similar() that should be relevant.

Hope that helps.

Upvotes: 2

Related Questions