예제 #1
0
 public static function deduceFromState(KnowledgeState $state)
 {
     $domain = new self();
     // Obtain all the FactConditions from the rules that test
     // or conclude some value.
     foreach ($state->rules as $rule) {
         $fact_conditions = array_filter_type('FactCondition', array_flatten($rule->condition->asArray()));
         foreach ($fact_conditions as $condition) {
             $domain->values[$condition->name]->push($condition->value);
         }
         foreach ($rule->consequences as $fact_name => $value) {
             $domain->values[$fact_name]->push($value);
         }
     }
     // Obtain all the possible answers from the questions
     foreach ($state->questions as $question) {
         foreach ($question->options as $option) {
             foreach ($option->consequences as $fact_name => $value) {
                 $domain->values[$fact_name]->push($value);
             }
         }
     }
     return $domain;
 }
예제 #2
0
{
    public $inferringRules;
    public $dependingRules;
    public $inferringQuestions;
    public function __construct()
    {
        $this->inferringRules = new Set();
        $this->dependingRules = new Set();
        $this->inferringQuestions = new Set();
    }
}
$stats = new Map(function ($fact_name) {
    return new FactStatistics($fact_name);
});
foreach ($state->rules as $rule) {
    $fact_conditions = array_filter_type('FactCondition', array_flatten($rule->condition->asArray()));
    foreach ($fact_conditions as $condition) {
        $stats[$condition->name]->values[$condition->value]->dependingRules->push($condition->value);
    }
    foreach ($rule->consequences as $fact_name => $value) {
        $stats[$fact_name]->values[$value]->inferringRules->push($rule);
    }
}
foreach ($state->questions as $question) {
    foreach ($question->options as $option) {
        foreach ($option->consequences as $fact_name => $value) {
            $stats[$fact_name]->values[$value]->inferringQuestions->push($question);
        }
    }
}
foreach ($state->goals as $goal) {