获取WordNet的指定单词的域名

时间:2012-12-14 15:18:17

标签: nlp cluster-analysis semantic-web wordnet document-classification

我知道WordNet有域名层次结构:例如sport->足球

1)是否可以列出与“sport-> football”子域相关的所有单词?

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

2)获取给定单词的域名,例如'守门员'?

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

用于文档分类任务。

1 个答案:

答案 0 :(得分:6)

WordNet有一个上位词/下位词层次结构,但这不是你想要的,就像你一样 当你查找守门员时可以看到:

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

其中一个结果是:

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

有两种方法称为usage_domains()topic_domains(),但它们会为大多数单词返回一个空列表:

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

The WordNet Domains project可能就是你想要的。它提供了一个文本文件,其中包含普林斯顿WordNet 2.0同义词及其相应域之间的映射。您必须注册您的电子邮件地址才能访问数据。 然后,您可以读取与您的WordNet版本相对应的文件(它们提供2.0和3.2),例如使用anydbm模块:

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()

然后,您可以使用synset的offset属性来查找其域。也许你必须在开头添加一个零:

dbdomains.get('0' + str(wordnet.synsets('travel_guidebook')[0].offset))
>>> 'linguistics\n'