def apply_lesk(sent, head_word, pos_arr, index, method='adapted',stop=True):
    if method == "adapted":
        answer = LESK.adapted_lesk(sent, head_word, pos_arr[index],stop=False)
    elif method == 'new':
        answer = LESK.new_lesk(sent, head_word, pos_arr[index],stop=stop)
    elif method == 'original':
        answer = LESK.original_lesk(sent, head_word)
    elif method == 'simple':
        answer = LESK.simple_lesk(sent, head_word)

    # no synset of answer
    if answer is None:
        return ''

    if (head_word in answer.lemma_names):
        answer.lemma_names.remove(head_word)

    if not answer.lemma_names:
        return ''
    else:
        return answer.lemma_names[0]
示例#2
0
                     nbest=True, keepscore=True, normalizescore=True)
print "Senses ranked by #overlaps:", answer
best_sense = answer[0][1]
try:
    definition = best_sense.definition()
except:
    definition = best_sense.definition
print "Definition:", definition
print

print "======== TESTING adapted_lesk ===========\n"
from lesk import adapted_lesk

print "#TESTING adapted_lesk() ..."
print "Context:", bank_sents[0]
answer = adapted_lesk(bank_sents[0], 'bank')
print "Sense:", answer
try:
    definition = answer.definition()
except:
    definition = answer.definition
print "Definition:", definition
print

print "#TESTING adapted_lesk() with pos, stem, nbest and scores."
print "Context:", bank_sents[0]
answer = adapted_lesk(bank_sents[0],'bank','n', True, \
                     nbest=True, keepscore=True)
print "Senses ranked by #overlaps:", answer
best_sense = answer[0][1]
try:
示例#3
0
文件: test_wsd.py 项目: dav009/pywsd
print "#TESTING simple_lesk() with nbest results and normalized scores"
print "Context:", plant_sents[0]
answer = simple_lesk(plant_sents[0],'plant','n', True, \
                     nbest=True, keepscore=True, normalizescore=True)
print "Senses ranked by #overlaps:", answer
best_sense = answer[0][1]
print "Definition:",best_sense.definition()
print

print "======== TESTING adapted_lesk ===========\n"
from lesk import adapted_lesk

print "#TESTING adapted_lesk() ..."
print "Context:", bank_sents[0]
answer = adapted_lesk(bank_sents[0],'bank')
print "Sense:", answer
print "Definition:",answer.definition()
print

print "#TESTING adapted_lesk() with pos, stem, nbest and scores."
print "Context:", bank_sents[0]
answer = adapted_lesk(bank_sents[0],'bank','n', True, \
                     nbest=True, keepscore=True)
print "Senses ranked by #overlaps:", answer
best_sense = answer[0][1]
print "Definition:",best_sense.definition()
print

print "======== TESTING cosine_lesk ===========\n"
from lesk import cosine_lesk
示例#4
0
print "Definition:",answer.definition
print

print "#TESTING simple_lesk() with POS and stems ..."
print "Context:", plant_sents[0]
answer = simple_lesk(plant_sents[0],'plant','n', True)
print "Sense:", answer
print "Definition:",answer.definition
print

print "======== TESTING adapted_lesk ===========\n"
from lesk import adapted_lesk

print "#TESTING adapted_lesk() ..."
print "Context:", bank_sents[0]
answer = adapted_lesk(bank_sents[0],'bank')
print "Sense:", answer
print "Definition:",answer.definition
print

print "======== TESTING cosine_lesk ===========\n"
from lesk import cosine_lesk

print "#TESTING adapted_lesk() ..."
print "Context:", bank_sents[0]
answer = cosine_lesk(bank_sents[0],'bank')
print "Sense:", answer
print "Definition:",answer.definition
print

print "======== TESTING baseline ===========\n"