/ AIML

基于Program-o的AIML改进版本

原生的AIML只支持简单的*和_匹配,有时候不能很好的满足需求,所以希望修改成用正则表达式来匹配。

今天思考了下这个问题,目前已经初步解决,但仅仅是修改了匹配的代码,评分代码尚未修改。

主要的处理还是在response_handler.php这个文件里。

在findMatch函数中,把原来的SQL语句替换掉

SELECT * FROM $dbn.aiml WHERE ( ((pattern = '') OR (pattern = '*') OR (pattern = '$input') OR ((pattern LIKE '$firstInput %') AND (pattern LIKE '% $lastInput')) OR ((pattern LIKE '$firstInput %') AND (pattern LIKE '% ')) OR ((pattern LIKE '$firstInput %') AND (pattern LIKE '% _')) OR ((pattern LIKE ' %') AND (pattern LIKE '% $lastInput')) OR ((pattern LIKE ' %') AND (pattern LIKE '% $lastInput')) OR ((pattern LIKE '* %') AND (pattern LIKE '% ')) OR ((pattern LIKE ' %') AND (pattern LIKE '% ')) OR (pattern = 'RANDOM PICKUP LINE' )) ) AND ( (thatpattern = '_') OR (thatpattern = '') OR (thatpattern = '') OR (thatpattern = '$thatPattern') $thatPatternSQL ) AND ( (topic='') OR (topic='".$storedtopic."') )

修改成

SELECT * FROM $dbn.aiml WHERE ('$input' regexp replace(pattern,'','.')) AND ( (thatpattern = '_') OR (thatpattern = '*') OR (thatpattern = '') OR (thatpattern = '$thatPattern') $thatPatternSQL ) AND ( (topic='') OR (topic='".$storedtopic."') )

也就是直接把原来的like查询修改成正则匹配,但是目前不知道效率和之前相比怎么样……

过几天可能会有后续修改,看有没有时间了……

基于Program-o的AIML改进版本
Share this