示例#1
0
function do_add_pat()
{
    $inputs = JxBotUtil::inputs('category,new-pat,topic,that,override');
    if (!$inputs['override']) {
        /* check if there are any existing patterns that match the proposed new pattern */
        // todo
    }
    /* go ahead and add the new pattern */
    try {
        JxBotNLData::pattern_add($inputs['category'], $inputs['new-pat'], $inputs['that'], $inputs['topic']);
    } catch (Exception $err) {
        // pattern already exists?
        print '<p>' . $err->getMessage() . '</p>';
    }
    page_edit($inputs['category']);
}
示例#2
0
 public static function category_update($in_category_id, $in_that, $in_topic)
 {
     /* check inputs and apply defaults */
     if (trim($in_that) == '') {
         $in_that = '*';
     }
     if (trim($in_topic) == '') {
         $in_topic = '*';
     }
     /* update the main category record */
     $stmt = JxBotDB::$db->prepare('UPDATE category SET that=?, topic=? WHERE id=?');
     $stmt->execute(array($in_that, $in_topic, $in_category_id));
     /* ! NOTE:  unlike a standard AIML interpreter, JxBot allows multiple patterns 
     		for each category - see file ENGINEERING for more information */
     /* re-add all the patterns, whose that & topic values will have changed;
     		this is not efficient for AIML load but necessary for some admin operations,
     		thus AIML load should collate patterns, that and topic and only add at completion
     		of a category. */
     $stmt = JxBotDB::$db->prepare('SELECT that,topic FROM category WHERE id=?');
     $stmt->execute(array($in_category_id));
     $row = $stmt->fetchAll(PDO::FETCH_NUM)[0];
     $that = $row[0];
     $topic = $row[1];
     $stmt = JxBotDB::$db->prepare('SELECT id,value FROM pattern WHERE category=?');
     $stmt->execute(array($in_category_id));
     $patterns = $stmt->fetchAll(PDO::FETCH_NUM);
     foreach ($patterns as $row) {
         $text = $row[1];
         $pattern = $row[0];
         /* remove the pattern */
         JxBotNLData::pattern_delete($pattern);
         /* reinsert the pattern */
         JxBotNLData::pattern_add($in_category_id, $text, $that, $topic);
     }
     return $in_category_id;
 }
示例#3
0
文件: aiml.php 项目: jhawcroft/jxbot
 public function _element_end($in_parser, $in_name)
 {
     set_time_limit(JxBotAimlImport::IMPORT_TIMEOUT_EXTEND);
     //print '/ '.$in_name.'  '.JxBotAiml::$state.'<br>';
     switch ($this->state) {
         case JxBotAimlImport::STATE_CATEGORY:
             if ($in_name == 'category') {
                 $this->state = JxBotAimlImport::STATE_AIML;
                 $topic = trim($this->cat_topic === null ? $this->aiml_topic : $this->cat_topic);
                 $that = trim($this->cat_that);
                 $category_id = JxBotNLData::category_new($that, $topic);
                 foreach ($this->cat_patterns as $pattern) {
                     try {
                         JxBotNLData::pattern_add($category_id, trim($pattern), $that, $topic);
                     } catch (Exception $err) {
                         // pattern already exists?
                         // ignore, but do a notice
                         $this->notice($err->getMessage());
                     }
                 }
                 foreach ($this->cat_templates as $template) {
                     JxBotNLData::template_add($category_id, $template);
                 }
                 if (count($this->cat_patterns) > 1 || count($this->cat_templates) > 1) {
                     $this->has_multi_pattern_cats = true;
                 }
             }
             break;
         case JxBotAimlImport::STATE_AIML_TOPIC:
             if ($in_name == 'topic') {
                 $this->state = JxBotAimlImport::STATE_AIML;
             }
             break;
         case JxBotAimlImport::STATE_CATEGORY_TOPIC:
             if ($in_name == 'topic') {
                 $this->state = JxBotAimlImport::STATE_CATEGORY;
             }
             break;
         case JxBotAimlImport::STATE_THAT:
             if ($in_name == 'that') {
                 $this->state = JxBotAimlImport::STATE_CATEGORY;
             }
             break;
         case JxBotAimlImport::STATE_PATTERN:
             if ($in_name == 'pattern') {
                 $this->cat_patterns[] = $this->content;
                 $this->state = JxBotAimlImport::STATE_CATEGORY;
             } else {
                 if ($in_name == 'bot' || $in_name == 'set' || $in_name == 'name') {
                     $this->content .= '</' . $in_name . '>';
                 }
             }
             break;
         case JxBotAimlImport::STATE_TEMPLATE:
             if ($in_name == 'template') {
                 $this->cat_templates[] = $this->content;
                 $this->state = JxBotAimlImport::STATE_CATEGORY;
             } else {
                 $this->content .= '</' . $in_name . '>';
             }
             break;
     }
 }