2019-12-16 19:46:34 星期一
最近接触到结巴分词项目, 就试试
用python的bottle库来当服务器监听localhost:8080
把请求的数据转给jieba来分词, 并返回分词结果
1. 安装 bottle 库 和 jieba 库
2. 代码
# encoding=utf-8 from bottle import route, run, template
import jieba @route('/fenci/<name>')
def index(name):
seg_list = jieba.cut(name) # 默认是精确模式
seg = ", ".join(seg_list)
return template('<b>结果: {{result}}</b>!', result=seg) run(host='localhost', port=8080)
3. 测试
D:\server\code\python>python fenci.py
Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
http://localhost:8080/fenci/这里是中国国家图书馆上海分馆 结果: 这里, 是, 中国, 国家图书馆, 上海, 分馆!
简单测试一版, 后续再优化成实用的