/** * @param KnowledgeBase $knowledgeBase * * @return WorkingMemory */ public function run(KnowledgeBase $knowledgeBase) { $workingMemory = new WorkingMemory(); $workingMemory->setFacts($knowledgeBase->getFacts()); $this->inferenceProfiler && $this->inferenceProfiler->startInference($knowledgeBase->getFacts()); while ($matchedRules = $this->getMatchedRules($knowledgeBase, $workingMemory)) { /** @var RuleRunDecorator $selectedRuleDecorator */ $selectedRuleDecorator = $this->conflictResolutionStrategy->selectPreferredRule($matchedRules, $workingMemory); $this->ruleExecutor->execute($selectedRuleDecorator, $workingMemory); } $this->inferenceProfiler && $this->inferenceProfiler->endInference($knowledgeBase->getFacts()); $knowledgeBase->setFacts($workingMemory->getAllFacts()); return $workingMemory; }