예제 #1
0
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
bank_sents = [
    'I went to the bank to deposit my money',
    'The river bank was full of dead fishes'
]

plant_sents = [
    'The workers at the industrial plant were overworked',
    'The plant was no longer bearing flowers'
]

print "======== TESTING simple_lesk ===========\n"
from lesk import simple_lesk
print "#TESTING simple_lesk() ..."
print "Context:", bank_sents[0]
answer = simple_lesk(bank_sents[0], 'bank')
print "Sense:", answer
try:
    definition = answer.definition()
except:
    definition = answer.definition  # Using older version of NLTK.
print "Definition:", definition
print

print "#TESTING simple_lesk() with POS ..."
print "Context:", bank_sents[1]
answer = simple_lesk(bank_sents[1], 'bank', 'n')
print "Sense:", answer
try:
    definition = answer.definition()
except:
예제 #3
0
    if wordnet.synsets(t) != []:
        if (nltk.pos_tag([t])[0][1]) != "NNP":
            if t.lower() not in improved_stopwords:
                filtered_query.append(t)

print("The filtered query after removing the stop words is as follows :\n",
      filtered_query)

# printing the sysnset and the meaning
for f in filtered_query:
    print('The differnet forms and their meanings of "', f.upper(),
          '" are as follows : \n')
    syns = wordnet.synsets(f)
    i = 1
    for s in syns:
        print(i, "." "   " "Form : ", s, "\n   Meaning : ", s.definition())
        i = i + 1
    print('*' * 20)

# using the LESK algorithm to disambiguate the meaning of the word using the context.
print('Using the simple lesk algorithm to disambiguate the word sense')
print(' ' * 100)
for f in filtered_query:
    print('The correct sense of the word "', f.upper(), ' "is as follows:')
    print('-' * 50)
    print('Context:', input_query)
    correct_sense = simple_lesk(input_query, f)
    print('Sense:', correct_sense)
    print('Definition:', correct_sense.definition())
    print(' ' * 100)
예제 #4
0
파일: test_wsd.py 프로젝트: dav009/pywsd
#!/usr/bin/env python -*- coding: utf-8 -*-

bank_sents = ['I went to the bank to deposit my money',
'The river bank was full of dead fishes']

plant_sents = ['The workers at the industrial plant were overworked',
'The plant was no longer bearing flowers']

print "======== TESTING simple_lesk ===========\n"
from lesk import simple_lesk
print "#TESTING simple_lesk() ..."
print "Context:", bank_sents[0]
answer = simple_lesk(bank_sents[0],'bank')
print "Sense:", answer
print "Definition:",answer.definition()
print

print "#TESTING simple_lesk() with POS ..."
print "Context:", bank_sents[1]
answer = simple_lesk(bank_sents[1],'bank','n')
print "Sense:", answer
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
예제 #5
0
파일: simp.py 프로젝트: pocketman/nlp
def getSynset(s, word):
    return simple_lesk(s, word)
예제 #6
0
#!/usr/bin/env python -*- coding: utf-8 -*-

bank_sents = ['I went to the bank to deposit my money',
'The river bank was full of dead fishes']

plant_sents = ['The workers at the industrial plant were overworked',
'The plant was no longer bearing flowers']

print "======== TESTING simple_lesk ===========\n"
from lesk import simple_lesk
print "#TESTING simple_lesk() ..."
print "Context:", bank_sents[0]
answer = simple_lesk(bank_sents[0],'bank')
print "Sense:", answer
print "Definition:",answer.definition
print

print "#TESTING simple_lesk() with POS ..."
print "Context:", bank_sents[1]
answer = simple_lesk(bank_sents[1],'bank','n')
print "Sense:", answer
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