Пример #1
0
 private static function sentence_respond(&$in_input)
 {
     /* find a category for the input */
     $start_time = microtime(true);
     $match = JxBotEngine::match($in_input, JxBotConverse::history_response(0), JxBotConverse::predicate('topic'));
     $end_time = microtime(true);
     JxBotConverse::$match_time += $end_time - $start_time;
     /* check recursion */
     $category = $match === false ? -1 : $match->matched_category();
     $count = 0;
     foreach (JxBotConverse::$category_stack as $nested_category) {
         if ($nested_category == $category) {
             $count++;
         }
     }
     if ($count >= JxBotConverse::MAX_CATEGORY_NESTING) {
         //print 'CATEGORY LIMIT<br>';
         return '';
     }
     JxBotConverse::$category_stack[] = $category;
     if ($match === false) {
         /* no match was found; the input was not understood
         		and no default category is available */
         $output = '???';
     } else {
         /* select a template at random */
         //print 'MATCHED CATEGORY '.$category.'<br>';
         $template = JxBotNLData::fetch_templates($category);
         $count = count($template);
         if ($count == 0) {
             $output = '???';
         } else {
             if ($count == 1) {
                 $index = 0;
             } else {
                 $index = mt_rand(1, $count) - 1;
             }
             $output = $template[$index][1];
         }
         if (JxBotConverse::$srai_level == 1) {
             JxBotConverse::$iq_score += $match->iq_score();
         }
     }
     /* generate the template */
     $template = JxBotAiml::parse_template($output);
     $output = $template->generate($match);
     /* track recursion */
     array_pop(JxBotConverse::$category_stack);
     return $output;
 }
Пример #2
0
 public static function parse_template($in_template)
 {
     JxBotAiml::$error = '';
     JxBotAiml::$root = NULL;
     JxBotAiml::$stack = array();
     $parser = JxBotAiml::parser_create('_template_open', '_template_close', '_template_data');
     $in_template = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><template>" . $in_template . '</template>';
     xml_parse($parser, $in_template, true);
     xml_parser_free($parser);
     return JxBotAiml::$root;
 }