# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
import bottle
import urllib
import struct
from getscoretext import GetScore
def geturltoutf8(srcString):
unquotedString = urllib.unquote(srcString)
#print repr(unquotedString)
textString = unquotedString.decode('utf-8')
#print textString
return textString
@bottle.route('/score', method='POST')
def score():
data =bottle.request.body.readlines()#获取请求参数列表
#转换参数编码格式
pltext=geturltoutf8(data[0]) #第一个参数,URL编码转utf8
print pltext #打印请求参数值
#开始情感分析
result=GetScore(pltext) #这个功能是我写在getscoretext.py文件中的一个函数
print result
return result #返回参数
bottle.run(host='localhost', port=8083)
==================getscoretext.py代码
# coding=utf-8
'''
Created on 2017年5月9日
@author: chenkai
'''
from snownlp import SnowNLP
from nltk.collocations import BigramCollocationFinder
from nltk.metrics import BigramAssocMeasures
import re
import jieba
import jieba.analyse
import json
def GetScore(text):
#1.标点符号处理
text = re.sub("[\s+\.\!\/_,$
python 利用bottle提供post接口,供第三方调用
最新推荐文章于 2025-06-05 09:01:18 发布