请问大家,对文本数据进行分词处理后,使用python怎么进行停用词处理和词性过滤(假设只保留名词、动词、形容词),并将长度为1的字符去掉,不知道怎么将这三种操作结合,希望各位帮忙。
给你写了一个参考示例代码,希望对你有帮助,望采纳
# 导入必要的库
import jieba.posseg as pseg
# 加载停用词
stopwords = set()
with open("stopwords.txt", "r", encoding="utf-8") as f:
for line in f:
stopwords.add(line.strip())
# 进行词性过滤和停用词处理
filtered_words = []
for word, pos in pseg.cut(text):
# 只保留名词、动词、形容词
if pos in {"n", "v", "a"}:
# 去掉长度为1的字符
if len(word) > 1:
# 去除停用词
if word not in stopwords:
filtered_words.append(word)
# 打印结果
print(filtered_words)
你的数据是啥样的都不说,给你从哪说起