当前位置: 首页>>代码示例>>PHP>>正文


PHP Term::getVariables方法代码示例

本文整理汇总了PHP中Term::getVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP Term::getVariables方法的具体用法?PHP Term::getVariables怎么用?PHP Term::getVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Term的用法示例。


在下文中一共展示了Term::getVariables方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: eval_term

 private function eval_term(Term $term)
 {
     $rel = $term->getName();
     $vars = $term->getVariables();
     // $vars: [Variable]
     // all variables have value, no need to generate/iterate candidates
     if ($term->readyForResolve()) {
         return $this->isTrue($rel, $term->getInstances());
     }
     /* ---------Have to fill the variables with a candidate value ----------- */
     try {
         if ($this->isRule($rel)) {
             $candidates = $this->instance_generator_for_rule($term);
         } else {
             $candidates = $this->instance_generator_for_fact($term);
         }
     } catch (Exception $e) {
         //echo "no candidates for: \n"; echo "  " . $term->toString() . "\n";
         return FALSE;
     }
     foreach ($candidates as $_instances) {
         //echo $term->toString() . "\n";
         //print_r($_instances);
         $term->assignValues($_instances);
         // if $term is fact, isTrue() will not assign value for
         // variables, it could make wrong variable value for next
         // term. for example:
         // hasDesc(A, C) :- hasChild(A, B) o hasDesc(A, C)
         // assign A = 'x', C = 'z'
         // hasDesc('x', 'z') :- hasChild('x', ?) o hasDesc(?, 'z')
         // assign ? = 'y'
         // hasDesc('x', 'z') :- hasChild('x', 'y') o hasDesc('y', 'z')
         // if we don't assigin value to ?
         // hasDesc(?, 'z') will be evaulated
         // the candicate of ? could be ['x', 'y', 'z'], then
         // hasDesc('x', 'z') cause infinite loop
         if ($this->isTrue($rel, $_instances)) {
             // recursive eval next, if return true, return true
             // if next term false, continue the iteration
             if (NULL == $term->next()) {
                 return TRUE;
             }
             // no more for eval
             if ($this->eval_term($term->next())) {
                 return TRUE;
             }
         }
     }
     return FALSE;
     // all candidate are false.
 }
开发者ID:318io,项目名称:318-io,代码行数:51,代码来源:reasoner.php


注:本文中的Term::getVariables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。