sloria / TextBlob

Simple, Pythonic, text processing--Sentiment analysis, part-of-speech tagging, noun phrase extraction, translation, and more.
https://textblob.readthedocs.io/
MIT License
9.02k stars 1.13k forks source link
natural-language-processing nlp nltk pattern python python-3

TextBlob: Simplified Text Processing

.. image:: https://badgen.net/pypi/v/TextBlob :target: https://pypi.org/project/textblob/ :alt: Latest version

.. image:: https://github.com/sloria/TextBlob/actions/workflows/build-release.yml/badge.svg :target: https://github.com/sloria/TextBlob/actions/workflows/build-release.yml :alt: Build status

Homepage: https://textblob.readthedocs.io/ <https://textblob.readthedocs.io/>_

TextBlob is a Python library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, and more.

.. code-block:: python

from textblob import TextBlob

text = """
The titular threat of The Blob has always struck me as the ultimate movie
monster: an insatiably hungry, amoeba-like mass able to penetrate
virtually any safeguard, capable of--as a doomed doctor chillingly
describes it--"assimilating flesh on contact.
Snide comparisons to gelatin be damned, it's a concept with the most
devastating of potential consequences, not unlike the grey goo scenario
proposed by technological theorists fearful of
artificial intelligence run rampant.
"""

blob = TextBlob(text)
blob.tags  # [('The', 'DT'), ('titular', 'JJ'),
#  ('threat', 'NN'), ('of', 'IN'), ...]

blob.noun_phrases  # WordList(['titular threat', 'blob',
#            'ultimate movie monster',
#            'amoeba-like mass', ...])

for sentence in blob.sentences:
    print(sentence.sentiment.polarity)
# 0.060
# -0.341

TextBlob stands on the giant shoulders of NLTK and pattern, and plays nicely with both.

Features

Get it now

::

$ pip install -U textblob
$ python -m textblob.download_corpora

Examples

See more examples at the Quickstart guide_.

.. _Quickstart guide: https://textblob.readthedocs.io/en/latest/quickstart.html#quickstart

Documentation

Full documentation is available at https://textblob.readthedocs.io/.

Project Links

License

MIT licensed. See the bundled LICENSE <https://github.com/sloria/TextBlob/blob/master/LICENSE>_ file for more details.

.. _pattern: https://github.com/clips/pattern/ .. _NLTK: http://nltk.org/