pip install snownlp
python
from snownlp import SnowNLP
import jieba
import matplotlib.pyplot as plt
python
SnowNLP.train("corpus.txt")
python
s = SnowNLP(text)
sentiment = s.sentiments
python
scores = [sentiment, 1 - sentiment]
labels = ["Positive", "Negative"]
plt.bar(labels, scores, color=["green", "red"])
plt.xlabel("Sentiment")
plt.ylabel("Score")
plt.title("Sentiment Analysis Result")
plt.show()