Skip to content

Instantly share code, notes, and snippets.

from snownlp import SnowNLP
s = SnowNLP(u'在茂密的大森林里,一只饥饿的老虎逮住了一只狐狸。老虎张开大嘴就要把狐狸吃掉。"慢着"!狐狸虽然很害怕但还是装出一副很神气的样子说,"你知道我是谁吗?我可是玉皇大帝派来管理百兽的兽王,你要是吃了我,玉皇大帝是决不会放过你的"。')
s.summary(5)
from snownlp import SnowNLP
text = SnowNLP(u'这个产品很好用,这个产品不好用,这个产品是垃圾,这个也太贵了吧,超级垃圾,是个垃圾中的垃圾')
sent = text.sentences
for sen in sent:
s = SnowNLP(sen)
print(s.sentiments)
from snownlp import sentiment
sentiment.train('snownlp/sentiment/custom_neg.txt', 'snownlp/sentiment/custom_pos.txt')
sentiment.save('custom_sentiment.marshal')
from snownlp import tag
tag.train('custom_tag.txt')
tag.save('tag.marshal')
from snownlp import seg
seg.train('custom_seg.txt')
seg.save('seg.marshal')
## intent:goodbye
- bye
- goodbye
- see you around
- see you later
- talk to you later
## intent:ask_identity
- who are you
- what is your name
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//custom action to process this.responseText
}
};
xhttp.open("POST", "http://localhost:5005/model/parse");
xhttp.setRequestHeader("Content-Type", "application/json");
//replace Hello with input message
with open('name.txt') as f:
f.readlines()
with open('name.txt', 'w') as f:
f.write('Hello world!')
with open('name.txt', 'a', encoding='utf8') as f:
f.write('你好!')