Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 1.01 KB

NOTES.md

File metadata and controls

29 lines (24 loc) · 1.01 KB

Notes

NLTK

Getting a list of sinonyms for word

>>> go_sets = [s for s in wordnet.synsets('go') if 'go.v' in s.name()]
>>> go_sets
[Synset('go.v.02'), Synset('go.v.03'), Synset('go.v.05'), Synset('go.v.09'), Synset('go.v.10'), Synset('go.v.16'), Synset('go.v.19'), Synset('go.v.22'), Synset('go.v.23'), Synset('go.v.25'), Synset('go.v.28')]
>>> [s.lemma_names() for s in go_sets]
[['go', 'proceed', 'move'], ['go', 'go_away', 'depart'], ['go'], ['go'], ['go'], ['go'], ['go'], ['go'], ['go'], ['go', 'lead'], ['go']]
>>> [s.lemma_names() for s in go_sets]

Filtering words

>>> from nltk.corpus import stopwords
>>> from nltk.tokenize import word_tokenize
>>>
>>> command_sentence = "Arnold, go forward for 3 seconds"
>>> stop_words = set(stopwords.words('english'))
>>> word_tokens = word_tokenize(command_sentence)
>>>
>>> filtered_command_sentence = [w for w in word_tokens if not w.lower() in stop_words]
>>> filtered_command_sentence
['Arnold', ',', 'go', 'forward', '3', 'seconds']