Natural Language Processing and sentiment analysis with TextBlob: a Python NLP library
What is NLP(Natural Language Processing)?
Natural language processing (NLP) is a subfield of computer science, information engineering, and artificial intelligence concerned with the interactions between computers and human (natural) languages, in particular how to program computers to process and analyze large amounts of natural language data. (Wikepedia)
Dependency to install:
$ pip install textblob
Some features of TextBlob:
Noun Phrase Extraction
from textblob import TextBlob
Install “brown” and “wordnet” using NLTK:
[nltk_data] Downloading package wordnet to /Users/frankdu/nltk_data...
[nltk_data] Package wordnet is already up-to-date!
[nltk_data] Downloading package brown to /Users/frankdu/nltk_data...
[nltk_data] Package brown is already up-to-date!
### sample text data: zen of Python
text1 = '''
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Errors should never pass silently.'''
[Sentence("Beautiful is better than ugly."),
Sentence("Explicit is better than implicit.")]
## 5. Words Lemmatization
lemmatization is a NLP technique to reduce inflectional or derivational forms of a word to be the base form so that they can be analyzed as one single word
Examples of lemmatization:
went > go
gone > go
organizes > organize
organized > organize
# import textblob Word object
from textblob import Word
word = "organizes"
word1 = "went"
# Convert a Python string to a textblob Word()
blob_word = Word(word)
## 6. Spell Check
blob = TextBlob("My spellin is aways corect")
Unfortunately only 50% accuracy. You will need a ML model to train for a better accuracy
TextBlob("By spelling is away correct")
## 7. Translation
blob = TextBlob("Beautiful is better than ugly. Explicit is better than implicit.")
# Translate to German from English
TextBlob("Schön ist besser als hässlich. Explicit ist besser als implizit.")