function page_lookup_results() { $inputs = JxBotUtil::inputs('input,that,topic'); if (trim($inputs['that']) === '') { $inputs['that'] = '*'; } if (trim($inputs['topic']) === '') { $inputs['topic'] = '*'; } JxWidget::hidden($inputs, 'input,that,topic'); ?> <h2>Categories</h2> <p>For input: <strong><?php print $inputs['input']; ?> : <?php print $inputs['that']; ?> : <?php print $inputs['topic']; ?> </strong></p> <?php $match = JxBotEngine::match($inputs['input'], $inputs['that'], $inputs['topic']); if ($match === false) { ?> <h3>No Exact Match</h3> <?php } else { print '<h3>Exact Match</h3>'; $category_id = $match->matched_category(); $patterns = JxBotNLData::fetch_patterns($category_id); JxWidget::grid(array(array('label' => 'ID', 'id' => 0, 'key' => true, 'visible' => false), array('label' => 'Pattern', 'id' => 1, 'link' => '?page=database&action=edit&category=' . $category_id, 'encode' => true)), $patterns); } ?> <!--<h3>Similar</h3>--> <p><?php JxWidget::button('Lookup Another', 'action', ''); ?> <?php JxWidget::button('New Category', 'action', 'new-cat'); ?> </p> <?php }
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; }
public static function match($in_input, $in_that, $in_topic) { if ($in_that === null) { $in_that = ''; } if ($in_topic === null) { $in_topic = ''; } $context = new JxBotEngine(); $context->tags = JxBotEngine::compute_tags($in_input); //var_dump($context->tags); $search_terms = JxBotNL::normalise($in_input); $search_terms[] = ':'; $terms = JxBotNL::normalise($in_that); if (count($terms) == 0) { $search_terms[] = '*'; } else { $search_terms = array_merge($search_terms, $terms); } $search_terms[] = ':'; $terms = JxBotNL::normalise($in_topic); if (count($terms) == 0) { $search_terms[] = '*'; } else { $search_terms = array_merge($search_terms, $terms); } /*print 'Search: <pre>'; var_dump($search_terms); print '</pre>';*/ $context->input_terms = $search_terms; $context->term_index = 0; $context->term_limit = count($search_terms); $context->wild_values = array(); $context->wild_that_values = array(); $context->wild_topic_values = array(); $context->unwind_stage = 2; $context->search_depth = 0; //var_dump($search_terms); //print '<br>'; $matched_pattern = $context->walk(0, 0); if ($matched_pattern === false) { return false; } //print 'Matched pattern: '.$matched_pattern.' ('.$context->search_depth.')<br>'; $stmt = JxBotDB::$db->prepare('SELECT category,term_count FROM pattern WHERE id=?'); $stmt->execute(array($matched_pattern)); $category = $stmt->fetchAll(PDO::FETCH_NUM); $context->matched_category_id = $category[0][0]; $context->term_count = $category[0][1]; return $context; }