-2

I'm trying to check and see if a word is an English word. Not sure if this is the best way to do it, any advice? It doesn't want to work.

from nltk import wordnet

word_to_test = input("Please enter a word: ")
if not wordnet.synsets(word_to_test):
    print("FALSE")
    #not english word
else:
    print("TRUE")
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
JMP
  • 3
  • 3
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [Minimal, complete, verifiable example](https://stackoverflow.com/help/minimal-reproducible-example) applies here. We cannot effectively help you until you post your MCVE code and accurately specify the problem. We should be able to paste your posted code into a text file and reproduce the problem you specified. StackOverflow is not a design, coding, research, or tutorial resource. – Prune Sep 25 '19 at 16:25
  • "It doesn't want to work" is not a problem specification. Your posted code doesn't ran as given: at least one syntax error, and it stalls awaiting input. – Prune Sep 25 '19 at 16:26
  • I tried running the code and got `AttributeError: module 'nltk.stem.wordnet' has no attribute 'synsets'` – EuRBamarth Sep 25 '19 at 16:27
  • Possible duplicate of [How to check if a word is an English word with Python?](https://stackoverflow.com/questions/3788870/how-to-check-if-a-word-is-an-english-word-with-python) – Trenton McKinney Sep 25 '19 at 16:43
  • The `enchant` package mentioned in the possible duplicate, is not longer maintained, however, there are other methods mentioned as well. – Trenton McKinney Sep 25 '19 at 17:00

1 Answers1

0

Use the following code:

  • from nltk.corpus import wordnet with wordnet.synsets did not successfully identify English words.
    • All of the words in word_list identified as True
  • Successfully identifying an English word, depends on the dictionary in use.
from nltk.corpus import words

def check_words(word_list: list):
    for word in word_list:
        print(word in words.words())

word_list = ['poisson', 'stark', 'nihongo', 'abstract', 'pedo']

Output:

check_words(word_list)

False
True
False
True
False
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158