本文整理匯總了Python中rivescript.RiveScript.train方法的典型用法代碼示例。如果您正苦於以下問題:Python RiveScript.train方法的具體用法?Python RiveScript.train怎麽用?Python RiveScript.train使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rivescript.RiveScript
的用法示例。
在下文中一共展示了RiveScript.train方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RiveScript
# 需要導入模塊: from rivescript import RiveScript [as 別名]
# 或者: from rivescript.RiveScript import train [as 別名]
#!/usr/bin/python
import re
from flask import Flask, jsonify, render_template, request
from rivescript import RiveScript
from rivescript import sentences
rs = RiveScript(debug=False, utf8=True)
rs.load_directory("./brain_zh")
rs.sort_replies()
rs.train()
app = Flask(__name__)
@app.route('/reply')
def get_reply():
user = re.sub(ur'\W', '', request.remote_addr)
line = request.args.get('l','')
user = user.strip()
res = []
req = []
if user != '':
for msg in sentences(line):
if msg.strip() == '':
continue
reply = rs.reply(user, msg)
req.append(msg)
res.append(reply)
return jsonify(req=req, reply=res)