About Lesson
In this Python NLP lesson we are going to learn about Enchant Library in NLP, so Enchant is a module in python which is used to check the spelling of a word, gives suggestions to correct words. Also gives antonym and synonym of words. It checks whether a word exists in dictionary or not. Other dictionaries can also be added.
First of all you need to install this library using pip.
1 |
pip install pyenchant |
Now let’s create a simple example.
1 2 3 4 5 6 7 8 |
import enchant dictionary = enchant.Dict('en_US') word = input("Please enter your word : ") print(dictionary.check(word)) print(dictionary.suggest(word)) |
Run the code and give a word, after that you will see suggestions for the word.
1 2 3 |
Please enter your word : climb True ['clomb', 'limb', 'climbs', 'clime', 'chimb', 'c limb'] |
Also you can tokenize words using Enchant library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# import the module from enchant.tokenize import get_tokenizer # the text to be tokenized text = ("Hello world, welcome to nlp tutorial,please subscribe my channel") # getting tokenizer class tokenizer = get_tokenizer("en_US") token_list =[] for words in tokenizer(text): token_list.append(words) # print the words with POS print(token_list) |
If you run the code this will be the result.
1 2 3 |
[('Hello', 0), ('world', 6), ('welcome', 13), ('to', 21), ('nlp', 24), ('tutorial', 28), ('please', 37), ('subscribe', 44), ('my', 54), ('channel', 57)] |