Exemple #1
0
function main($argc, $argv)
{
    if ($argc < 2 || $argc > 3) {
        usage($argv[0]);
    }
    // Als '-v' is meegegeven tijdens het starten, ga in verbose mode
    if ($argv[1] == '-v') {
        verbose(true);
        $argc--;
        array_shift($argv);
    } else {
        verbose(false);
    }
    // Reader voor de XML-bestanden
    $reader = new KnowledgeBaseReader();
    // Parse een xml-bestand (het eerste argument) tot knowledge base
    $state = $reader->parse($argv[1]);
    // Start de solver, dat ding dat kan infereren
    $solver = new Solver();
    // leid alle goals in de knowledge base af.
    $goals = $state->goals;
    // Begin met de doelen die we hebben op de goal stack te zetten
    foreach ($goals as $goal) {
        $state->goalStack->push($goal->name);
    }
    // Zo lang we nog vragen kunnen stellen, stel ze
    while (($question = $solver->solveAll($state)) instanceof AskedQuestion) {
        $answer = cli_ask($question);
        if ($answer instanceof Option) {
            $state->apply($answer->consequences, Yes::because("User answered '{$answer->description}' to '{$question->description}'"));
        }
    }
    // Geen vragen meer, print de gevonden oplossingen.
    foreach ($goals as $goal) {
        printf("%s: %s\n", $goal->description, $goal->answer($state)->description);
    }
}
Exemple #2
0
 public function evaluate(KnowledgeState $state)
 {
     $state_value = $state->value($this->name);
     if ($state_value instanceof Maybe) {
         return $state_value;
     }
     return $state_value == $this->value ? Yes::because([$this->name]) : No::because([$this->name]);
 }