NLTK中的Wordnet选择限制

eri*_*krf 7 python nlp nltk wordnet

有没有办法通过NLTK从同义词集中捕获WordNet选择限制(例如+ animate,+ human等)?或者有没有其他方式提供有关synset的语义信息?我能得到的最接近的是上位词关系.

alv*_*vas 5

这取决于你的"选择限制"是什么,或者我称之为语义特征,因为在经典语义中,concepts我们必须找到的概念之间存在并进行比较

  • 区分特征(即用于将它们彼此区分的概念的特征)和
  • 相似特征(即概念的特征相似,并突出了区分它们的必要性)

例如:

Man is [+HUMAN], [+MALE], [+ADULT]
Woman is [+HUMAN], [-MALE], [+ADULT]

[+HUMAN] and [+ADULT] = similarity features
[+-MALE] is the discrimating features
Run Code Online (Sandbox Code Playgroud)

传统语义的常见问题是将这一理论应用于计算语义学中

"我们可以使用特定的功能列表来比较任何功能

"如果是这样,这份清单上有哪些功能?" 概念?"

(更多详情,请参见www.acl.ldc.upenn.edu/E/E91/E91-1034.pdf)

回到WordNet,我可以建议2种方法来解决"选择限制"

首先,检查上位词以区分特征,但首先必须确定区别特征是什么.为了区分动物和人类,我们将区分特征视为[+ -human]和[+ -animal].

from nltk.corpus import wordnet as wn

# Concepts to compare
dog_sense = wn.synsets('dog')[0] # It's http://goo.gl/b9sg9X
jb_sense = wn.synsets('James_Baldwin')[0] # It's http://goo.gl/CQQIG9

# To access the hypernym_paths()[0]
# It's weird for that hypernym_paths gives a list of list rather than a list, nevertheless it works.
dog_hypernyms = dog_sense.hypernym_paths()[0]
jb_hypernyms = jb_sense.hypernym_paths()[0]


# Discriminating features in terms of concepts in WordNet
human = wn.synset('person.n.01') # i.e. [+human]
animal = wn.synset('animal.n.01') # i.e. [+animal]

try:
  assert human in jb_hypernyms and animal not in jb_hypernyms
  print "James Baldwin is human"
except:
  print "James Baldwin is not human"

try:
  assert human in dog_hypernyms and animal not in dog_hypernyms
  print "Dog is an animal"
except:
  print "Dog is not an animal"
Run Code Online (Sandbox Code Playgroud)

其次,检查@Jacob建议的相似性度量.

dog_sense = wn.synsets('dog')[0] # It's http://goo.gl/b9sg9X
jb_sense = wn.synsets('James_Baldwin')[0] # It's http://goo.gl/CQQIG9

# Features to check against whether the 'dubious' concept is a human or an animal
human = wn.synset('person.n.01') # i.e. [+human]
animal = wn.synset('animal.n.01') # i.e. [+animal]

if dog_sense.wup_similarity(animal) > dog_sense.wup_similarity(human):
  print "Dog is more of an animal than human"
elif dog_sense.wup_similarity(animal) < dog_sense.wup_similarity(human):
  print "Dog is more of a human than animal"
Run Code Online (Sandbox Code Playgroud)