In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Python to analyze keywords of Dream of Red Mansions". In daily operation, I believe that many people have doubts about how to use Python to analyze keywords of Dream of Red Mansions. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use Python to analyze keywords of Dream of Red Mansions". Next, please follow the editor to study!
Python toolkit preparation
To complete a text segmentation, we need a word segmentation tool, and to draw the word segmentation statistics using a word cloud map, we need a word cloud tool:
0 1 word Segmentation tool jieba
Jieba is a Chinese word segmentation tool based on Python, which is very convenient to install and use.
We use pip to install:
02 word cloud tool wordcloud
Wordcloud library, it can be said that python is a very excellent word cloud display third-party library. The word cloud, which takes words as the basic unit, is a more intuitive and artistic display of the text word cloud, also known as the word cloud, which visually shows the "keywords" that appear frequently in the text, and the word cloud map filters out a large number of low-frequency and low-quality text information. so that visitors can appreciate the gist of the text as long as they scan the text at a glance.
Examples of effects:
We use pip to install:
Text and picture preparation
0 1 Dream of Red Mansions. Txt
In order to allow the word segmentation tool to analyze, we download the txt format of the novel A Dream of Red Mansions. For convenience, we put the Dream of Red Mansions document in the txt folder under "participle" in the directory where the program "fenci.py" is located:
0 2 background .jpg
Like the shape of the word cloud picture above is a whale, we need to prepare a patterned background image so that the final word cloud map fits the background pattern.
We chose this beautiful man portrait of Baoyu as the background picture:
The file is saved in the img directory of the current folder of the program:
0 3 stop word .txt
In information retrieval, in order to save storage space and improve search efficiency, some words or words are automatically filtered out before or after processing natural language data (or text). These words or words are called StopWords.
However, as there are many special words in A Dream of Red Mansions, such as "this moment", "tomorrow" and so on, we can choose to add some stop words by ourselves. For example, I added some words:
We put the stop words under the words folder:
Program running
We set the maximum number to 500, in order to make the background pattern more obvious:
Judging from the results, Baoyu is a well-deserved protagonist. Sister Feng, Lady Jia, Mrs. Wang and others also played a lot. As Daiyu and Lin Daiyu are divided into two words, so there is very little play, do you think there is any way to solve this problem? In addition, we can see that the word "this Huizi" appears frequently, from which we can get a glimpse of the feeling of the dialect at that time.
At this point, the study on "how to use Python to analyze the keywords of A Dream of Red Mansions" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.