Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77aa5b7

Browse filesBrowse files
feat: text_analysis - Analyse text using TextBlob
1 parent 5afcdcc commit 77aa5b7
Copy full SHA for 77aa5b7

File tree

9 files changed

+65
-10
lines changed
Filter options

9 files changed

+65
-10
lines changed

‎ebook/chapters/third_party_chapters/non_categorized.tex

Copy file name to clipboardExpand all lines: ebook/chapters/third_party_chapters/non_categorized.tex
+16Lines changed: 16 additions & 0 deletions
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

Copy file name to clipboard
424 Bytes
Binary file not shown.

‎ebook/python-snippets.mobi

Copy file name to clipboard
655 Bytes
Binary file not shown.

‎ebook/python-snippets.pdf

Copy file name to clipboard
2.23 KB
Binary file not shown.

‎third_party/Pipfile

Copy file name to clipboardExpand all lines: third_party/Pipfile
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboardExpand all lines: third_party/Pipfile.lock
+25-10Lines changed: 25 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎third_party/README.md

Copy file name to clipboardExpand all lines: third_party/README.md
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
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

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.