Skip to content

Commit 77aa5b7

Browse files
feat: text_analysis - Analyse text using TextBlob
1 parent 5afcdcc commit 77aa5b7

File tree

9 files changed

+65
-10
lines changed

9 files changed

+65
-10
lines changed

ebook/chapters/third_party_chapters/non_categorized.tex

+16
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,19 @@ \subsection{Simple Debugger}
176176

177177
The output is too long to be covered here.
178178
Feel free to run the snippet from your terminal and get a sense of how amazing and helpful this little package can be.
179+
180+
181+
\subsection{Text Analysis}
182+
183+
If you want a simple way to perform text analysis, you can use \lstinline{TextBlob}.
184+
The following snippet shows you a sample usage.
185+
Make sure to read the docs of the package as it provides functionality for translations and further analysis, too.
186+
187+
\lstinputlisting[caption=text\_analysis.py]{../third_party/text_analysis.py}
188+
189+
\textbf{Note:} Make sure to download the needed data before hand, otherwise an exception is thrown telling you to download it.
190+
191+
\begin{lstlisting}[caption=Download data using NLTK]
192+
>>> import nltk
193+
>>> nltk.download('averaged_perceptron_tagger')
194+
\end{lstlisting}

ebook/python-snippets.epub

424 Bytes
Binary file not shown.

ebook/python-snippets.mobi

655 Bytes
Binary file not shown.

ebook/python-snippets.pdf

2.23 KB
Binary file not shown.

third_party/Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ requests = "*"
4040
xlrd = "*"
4141
pysnooper = "*"
4242
cooked-input = "*"
43+
textblob = "*"
4344

4445
[dev-packages]
4546

third_party/Pipfile.lock

+25-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third_party/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ A collection of useful snippets using third party packages.
4343
| test_asyncio | Example on how to use asyncio |
4444
| test_gevent | Demonstrates the usage of gevent |
4545
| test_tornado | Reveales the usage of tornado |
46+
| text_analysis | Analyse text using TextBlob |
4647
| timing_tool | Illustrates the usage of boxx.timeit() reveilling the time a certain code block takes to run |
4748
| world_bank_data | Using official world bank data to demonstrate the usage of `zipfile` and `csv` |

third_party/src/text.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The titular threat of The Blob has always struck me as the ultimate movie
2+
monster: an insatiably hungry, amoeba-like mass able to penetrate
3+
virtually any safeguard, capable of--as a doomed doctor chillingly
4+
describes it--"assimilating flesh on contact.
5+
Snide comparisons to gelatin be damned, it's a concept with the most
6+
devastating of potential consequences, not unlike the grey goo scenario
7+
proposed by technological theorists fearful of
8+
artificial intelligence run rampant.

third_party/text_analysis.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
3+
from textblob import TextBlob
4+
5+
6+
path = Path("src/text.txt")
7+
8+
with open(path) as f:
9+
text = f.read()
10+
11+
blob = TextBlob(text)
12+
13+
for sentence in blob.sentences:
14+
print(sentence.sentiment.polarity)

0 commit comments

Comments
 (0)