I want to check in a Python program if a given english sentence contains all non-meaning words.
Return true if sentence has all words that have no meaning
e.g. sdfsdf sdf ssdf fsdf dsd sd
Return false if sentence contains at least one word that has meaning
e.g. Hello asdf
Here is the code I wrote.
Updated the code for is_meaningless variable
import nltk
nltk.download('words')
from nltk.corpus import words
def is_sentence_meaningless(sentence):
is_meaningless = True
for word in sentence.split():
if(word in words.words()):
is_meaningless = False
break
return is_meaningless
print(is_sentence_meaningless("sss sss asdfasdf asdfasdfa asdfasfsd"))
print(is_sentence_meaningless(" sss sss asdfasdf asdfasdfa asdfasfsd TEST"))
Is there a better alternative to this code? Also, how can I add my own corpus to it? For example I have few domain specific words that I want it to return as true, is that possible?