0

I'm trying to use the similar function in NLTK with python but it keeps returning 'No Matches', even when I put in a similar word that's in the sentence.

My code is here

from nltk.tokenize import word_tokenize
import nltk
raw = "Analyzing text to find common terms using Python and NLTK"
text = nltk.Text(raw)
text.similar('mutual')

Any ideas?

ascripter
  • 5,665
  • 12
  • 45
  • 68

1 Answers1

0

Text takes a list of words, not a string:

text = nltk.Text(word_tokenize(raw))
DYZ
  • 55,249
  • 10
  • 64
  • 93
  • Thanks for your answer. I am trying to use your code. But still similar function return 'No Matches' result. Any other ideas? – Sathyapriya Jun 14 '18 at 05:32
  • Sometimes there are indeed no matches. Like in your original example, because the word 'mutual' is not even in the text. – DYZ Jun 14 '18 at 05:44
  • Similar function return the similar word of a given word, not exact word of a given word. Is that correct or not? In my example the word 'common' is in the text. Its a similar word of 'mutual'. So my example need to return the word 'common'. But always return 'No Matches'. – Sathyapriya Jun 14 '18 at 06:57
  • Your interpretation of the function `similar()` is incorrect. Please see https://stackoverflow.com/questions/43438008/difference-between-similar-and-concordance-in-nltk – DYZ Jun 14 '18 at 17:53
  • Thanks for your answer. Now i am clear in similar() function. – Sathyapriya Jun 18 '18 at 05:55