可以使用Python中的NLTK(自然语言处理工具包)和知网情感分析词典来进行情感分类。
以下是一个使用知网情感分析词典进行情感分类的Python代码示例:
首先,导入所需的库和词典文件:
import jieba
from nltk.corpus import CategorizedPlaintextCorpusReader
from nltk.tokenize import word_tokenize
# 加载知网情感分析词典
pos_dict_file = 'path/to/pos_dict.txt'
neg_dict_file = 'path/to/neg_dict.txt'
pos_dict = set([line.strip() for line in open(pos_dict_file, encoding='utf-8') if line.strip()])
neg_dict = set([line.strip() for line in open(neg_dict_file, encoding='utf-8') if line.strip()])