这取决于你的"选择限制"是什么,或者我称之为语义特征,因为在经典语义中,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)
归档时间: |
|
查看次数: |
754 次 |
最近记录: |