jieba库分词怎么去除共性比较多的
时间: 2023-11-01 17:11:50 浏览: 67
jieba库默认使用了基于词频的分词方法,因此可能会出现一些常用的、无意义的词汇被分割出来,这会影响分词的准确性。为了去除这些共性比较多的词汇,可以考虑使用停用词表。
停用词表是指一些常见但无实际意义的词汇,例如“的”、“是”、“在”等。在分词过程中,你可以将停用词表加载到程序中,并在分词时过滤掉这些词汇。
使用jieba库实现停用词过滤的示例代码如下:
```python
import jieba
# 加载停用词表
stop_words = set()
with open('stop_words.txt', 'r', encoding='utf-8') as f:
for line in f:
stop_words.add(line.strip())
# 分词并过滤停用词
text = '今天天气真好,我们去公园玩。'
words = jieba.cut(text)
result = []
for word in words:
if word not in stop_words:
result.append(word)
print(result)
```
其中,stop_words.txt 是一个存储停用词的文件,每行一个词汇。你可以根据需要自行编写。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)