示例#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);
    }
}
示例#2
0
 /**
  * Ask the same question over and over again until the user says NO :)
  *
  * @param $string
  *
  * @return bool
  */
 function cli_wait_for_no($string)
 {
     while (cli_ask($string)) {
     }
     return false;
 }