preface

Read/analyze a novel in Python

If you don’t want to see the process, please scroll down to the end to see the result

# Development tools

Python version: 3.6.4

Related modules:

Gensim module;

Jieba module;

Scipy module;

Snownlp module;

Matplotlib module;

Numpy module.

Environment set up

Install Python and add it to the environment variable, and the PIP will install the appropriate module.

Additional Notes:

PIP download speed is too slow:

Temporary/permanent source switch ~~~ (there are many tutorials on Baidu T_T)

PIP installation failed:

To similar https://www.lfd.uci.edu/~gohl… Such sites download WHL files to install.

The main idea

(1) Analysis of main characters in the novel

Count the number of appearances of each character in the novel, and assume that the more appearances, the higher the status of the character in the novel.

(2) Analysis of the relationship between characters in the novel

Gensim is used to generate a word vector model to analyze the relationship between people.

T_T model was developed by Google in 2013, and the specific implementation details have not been read yet. It is not deep learning, but a shallow neural network ~~~

(3) Sentiment analysis of novels

It mainly utilizes the SNOWNLP library.

See the source code for the detailed implementation process.

added

Before analyzing the novel, it is necessary to download the text file of the novel from the relevant website and create a new text file containing the names of all the characters in the novel.

Modify the source code (analysis.py) :

if name== ‘__main__’ :(line 98)

After the following novel file path in the CMD window can run.

Python magenta floor

First let’s take a look at the first of the Four Great Classical Novels of China which I have read for 20 years and only read the first 3 pages!!

Main Characters (Top10) :

The first few names are still familiar??

Relationship Graph:

Also do not know to rely on the spectrum, clustering to get the graph ~~~

T_T also conveniently reaches the following conclusion (escape) :

The overall emotional tone of the novel (negative or positive?) :

Bounded by 0.5, the left is negative and the right is positive ~~~

This is too much. T_T

There are eight Python products

Only watched TV series ~~~

Main Characters (Top10) :

Maybe it is Qiao Feng in some places, and Xiao Feng in some places. After all, I think Qiao Feng is the protagonist!

Relationship Graph:

And the conclusions that come to mind:

Ah ~ ruin the view ah ~~~

The overall emotional tone of the novel (negative or positive?) :

That’s the end of the article. Thank you for watching. Follow me for my daily Python Case Series.

To thank you readers, I’d like to share with you some of my recent collection of dry programming goodies and give something back to every reader in the hope of helping you out.

Dry goods mainly include:

① More than 2000 Python e-books (mainstream and classic books are available)

(2) The Python Standard Library (Chinese version)

③ project source code (40 or 50 interesting and classic hands-on project and source code)

④Python basic introduction, crawler, web development, big data analysis video (suitable for small white learning)

⑤ Python Learning Roadmap (Goodbye to Slow Learning)

All done~ complete source code + dry goods see personal profile or private message to obtain the relevant files.