python-2.7nltkdisambiguationword-sense-disambiguation

Python 2.7: Lesk algorithm returns None


I am creating a program that will disamiguate ambiguos words and I was using nltk. Now, when I came to the stage to use lesk algorithm I am having some trouble.

For example, if I try:

c = lesk('There sign bothered consider inverse logic namely mental illness   substance abuse might degree consequence rather cause homelessness ','consider')

c will be None, which means that algorithm will return none.

I tried to give in place of sentence a list of word: i.e:

sent = word_tokenize('There sign bothered consider inverse logic namely mental illness substance abuse might degree consequence rather cause homelessness ')
c = lesk(sent, 'consider')

or even list of lemmatas instead of full words, but it still returns None.

Does anyone know if this is a feature of lesk (when it cannot disambiguate the word to return None), or am I doing something wrong? Also if it is a feature, then can it be removed (to return me a word instead of None)?

Thanks!


Solution

  • Yes, the method returns None if no word sense was found. You may increase the size of the context. As far as I can see in the methods source code the context sentence must be tokenized.