示例#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
function page_edit($in_category_id)
{
    $inputs = JxBotUtil::inputs('input');
    $category = JxBotNLData::category_fetch($in_category_id);
    ?>

<input type="hidden" name="category" value="<?php 
    print $in_category_id;
    ?>
">


<h2>Edit Category</h2>


<h3>Context</h3>

<p><?php 
    JxWidget::textfield(array('name' => 'topic', 'label' => 'Topic', 'max' => 255, 'value' => $category['topic']));
    ?>
</p>

<p><?php 
    JxWidget::textfield(array('name' => 'that', 'label' => 'That', 'max' => 255, 'value' => $category['that']));
    ?>
</p>

<p><?php 
    JxWidget::button('Update Context', 'action', 'save-ctx');
    ?>
</p>


<h3>Patterns</h3>

<?php 
    $stmt = JxBotDB::$db->prepare('SELECT id,value FROM pattern WHERE category=?');
    $stmt->execute(array($in_category_id));
    $rows = $stmt->fetchAll(PDO::FETCH_NUM);
    JxWidget::grid(array(array('label' => 'ID', 'id' => 0, 'visible' => false, 'key' => true), array('label' => 'Pattern', 'id' => 1, 'encode' => true), array('label' => 'Delete', 'id' => ':delete', 'link' => '?page=database&action=del-pat&pat-id=$$')), $rows);
    ?>

<p><?php 
    JxWidget::textfield(array('name' => 'new-pat', 'label' => 'New Pattern', 'max' => 255, 'value' => $inputs['input']));
    ?>
</p>

<p><?php 
    JxWidget::button('Add Pattern', 'action', 'add-pat');
    ?>
</p>



<h3>Templates</h3>

<?php 
    $rows = JxBotNLData::fetch_templates($in_category_id);
    JxWidget::grid(array(array('label' => 'Template', 'id' => 1, 'link' => '?page=database&action=edit-tmpl&template=$$', 'encode' => true), array('label' => 'ID', 'id' => 0, 'visible' => false, 'key' => true), array('label' => 'Delete', 'id' => ':delete', 'link' => '?page=database&action=del-tmpl&template=$$')), $rows);
    ?>

<p><?php 
    JxWidget::memofield('new-tmpl', 'New Template', '', 5, true);
    ?>
</p>

<p><?php 
    JxWidget::button('Add Template', 'action', 'add-tmpl');
    ?>
</p>



<p><?php 
    JxWidget::button('Lookup Another', 'action', '');
    ?>
 <?php 
    JxWidget::button('Delete Category', 'action', 'del-cat');
    ?>
</p>


<?php 
}