Get WordNet's domain name for the specified word
Asked Answered
B

1

5

I know WordNet has Domains Hierarchy: e.g. sport->football.

1) Is it possible to list all words related, for example, to the 'sport->football' sub-domain?

  Response: goalkeeper, forward, penalty, ball, field, stadium, referee and so on.

2) Get domain's name for a given word , e.g. 'goalkeeper'?

 Need something like [sport->football; sport->hockey] or [football;hockey] or just 'football'.

It is for a document classification task.

Bubo answered 14/12, 2012 at 15:18 Comment(0)
C
8

WordNet has a hypernym / hyponym hierarchy but that is not what you want here, as you can see when you look up goalkeeper:

from nltk.corpus import wordnet
s = wordnet.synsets('goalkeeper')[0]
s.hypernym_paths()

One of the results is:

[Synset('entity.n.01'),
Synset('physical_entity.n.01'),
Synset('causal_agent.n.01'),
Synset('person.n.01'),
Synset('contestant.n.01'),
Synset('athlete.n.01'),
Synset('soccer_player.n.01'),
Synset('goalkeeper.n.01')]

There are two methods called usage_domains() and topic_domains() but they return an empty list for most words:

s = wordnet.synsets('football')[0]
s.topic_domains()
>>> []
s.usage_domains()
>>> []

The WordNet Domains project however could be what you are looking for. It offers a text file that contains the mapping between Princeton WordNet 2.0 synsets and their corresponding domains. You have to register your email address to get access to the data. Then you can read in the file that corresponds to your WordNet version (they offer 2.0 and 3.2), for example with the anydbm module:

import anydbm
fh = open('wn-domains-2.0-20050210', 'r')
dbdomains = anydbm.open('dbdomains', 'c')
for line in fh:
    offset, domain = line.split('\t')
    dbdomains[offset[:-2]] = domain
fh.close()

You can then use the offset attribute of a synset to find out its domain. Maybe you have to add a zero at the beginning:

dbdomains.get('0' + str(wordnet.synsets('travel_guidebook')[0].offset))
>>> 'linguistics\n'
Crissman answered 17/12, 2012 at 17:43 Comment(5)
Thank you, Suzana! I have downloaded WordNet Domains but it is not clear for me how to integrate it with WordNet..(((Bubo
I got this version of WordNet Domains for my WordNet 2.0 and copied your code exactly, but dbdomains.get(whatever) returns None for every whatever I've tried that is of the given form. dbdomains does have kosher-looking key/domain pairs in it (99330 of them to be precise) but it seems no WordNet offsets with a leading 0 correspond to any of those keys. Any insights?Deandre
Dear @Suzana_K, you seem to really master the subject, do you have an idea to answer my question ? I will try to get the domain of every important words in one query and detect if there is a dominant common domain in one given cluster of queries, but this approach doesn't take into account semantic context inferred by the use of multiple words in some queries. What do you think ? Thank you so much by advanceMalaise
@Deandre did you find an answer to your question ? I have the exactly same problem... no word I have in my set seems to be linked with a domain...Malaise
Maybe contacting the authors of the WordNet Domains project could help. It could be that the project is not continued anymore.Crissman

© 2022 - 2024 — McMap. All rights reserved.