Exemple #1
0
def get_sentiment(testtxt):
    # 情感分析 example 1
    xm = XmNLP(testtxt)
    if xm.sentiment() < 0.2:
        return 0
    elif xm.sentiment() < 0.4:
        return 1
    elif xm.sentiment() < 0.6:
        return 2
    elif xm.sentiment() < 0.8:
        return 3
    else:
        return 4
Exemple #2
0
    def get(self, text):
        xm = XmNLP(text)
        time_stamp = str(int(time.time()))
        data = get_tc_res(text, time_stamp)

        result = {'polar': 0, 'confd': 0, 'sentiment': 0}
        result['sentiment'] = xm.sentiment()
        if data['polar'] == 0:
            result['polar'] = 1
        else:
            result['polar'] = data['polar']
        # result['polar'] = data['polar'] if data['polar'] == 0 else 1
        result['confd'] = data['confd']
        return jsonify(result)
Exemple #3
0
    情感计算
/ naive bayes / 
"""
print(descr)


doc = """真伤心"""
doc2 = """天气太好了,我们去钓鱼吧"""

print('\n++++++++++++++++++++++++ usage 1 ++++++++++++++++++++++++\n')

"""
 1. 使用类来进行操作

"""
from xmnlp import XmNLP 

xm = XmNLP(doc, stopword=True)
print('Text: ', doc)
print('Score: ', xm.sentiment())
print('Text: ', doc2)
print('Score: ', xm.sentiment(doc2))


print('\n++++++++++++++++++++++++ usage 2 ++++++++++++++++++++++++\n')

import xmnlp
print('Text: ', doc)
print('Score: ', xmnlp.sentiment(doc))
print('Text: ', doc2)
print('Score: ', xmnlp.sentiment(doc2))