public function testExtract()
 {
     $pb = new \Fieg\PC\PropositionBuilder();
     $pb->atom('light_1');
     $pb->atom('light_1');
     $pb->atom('light_2');
     $this->assertFalse(isset($light_1));
     extract($pb->getAtoms());
     $this->assertInstanceOf('Fieg\\PC\\Proposition\\Atomic', $light_1);
     $this->assertFalse(isset($light_0));
 }
 public function testQuery()
 {
     $pb = new \Fieg\PC\PropositionBuilder();
     $kb = new \Fieg\PC\KnowledgeBase();
     // atomic clauses
     $kb->addProposition($pb->atom('light_l1'));
     $kb->addProposition($pb->atom('light_l2'));
     $kb->addProposition($pb->atom('ok_l1'));
     $kb->addProposition($pb->atom('ok_l2'));
     $kb->addProposition($pb->atom('ok_cb1'));
     $kb->addProposition($pb->atom('ok_cb2'));
     $kb->addProposition($pb->atom('live_outside'));
     // rules
     $kb->addProposition($pb->implies($pb->atom('live_l1'), $pb->atom('live_w0')));
     $kb->addProposition($pb->implies($pb->atom('live_w0'), $pb->andX($pb->atom('live_w1'), $pb->atom('up_s2'))));
     $kb->addProposition($pb->implies($pb->atom('live_w0'), $pb->andX($pb->atom('live_w2'), $pb->atom('down_s2'))));
     $kb->addProposition($pb->implies($pb->atom('live_w1'), $pb->andX($pb->atom('live_w3'), $pb->atom('up_s1'))));
     $kb->addProposition($pb->implies($pb->atom('live_w2'), $pb->andX($pb->atom('live_w3'), $pb->atom('down_s1'))));
     $kb->addProposition($pb->implies($pb->atom('live_l2'), $pb->atom('live_w4')));
     $kb->addProposition($pb->implies($pb->atom('live_w4'), $pb->andX($pb->atom('live_w3'), $pb->atom('up_s3'))));
     $kb->addProposition($pb->implies($pb->atom('live_p1'), $pb->atom('live_w3')));
     $kb->addProposition($pb->implies($pb->atom('live_w3'), $pb->andX($pb->atom('live_w5'), $pb->atom('ok_cb1'))));
     $kb->addProposition($pb->implies($pb->atom('live_p2'), $pb->atom('live_w6')));
     $kb->addProposition($pb->implies($pb->atom('live_w6'), $pb->andX($pb->atom('live_w5'), $pb->atom('ok_cb2'))));
     $kb->addProposition($pb->implies($pb->atom('live_w5'), $pb->atom('live_outside')));
     $kb->addProposition($pb->implies($pb->atom('lit_l1'), $pb->andX($pb->atom('light_l1'), $pb->atom('live_l1'), $pb->atom('ok_l1'))));
     $kb->addProposition($pb->implies($pb->atom('lit_l2'), $pb->andX($pb->atom('light_l2'), $pb->atom('live_l2'), $pb->atom('ok_l2'))));
     // observations
     $kb->addProposition($pb->atom('down_s1'));
     $kb->addProposition($pb->atom('up_s2'));
     $kb->addProposition($pb->atom('up_s3'));
     extract($pb->getAtoms());
     /** @var $light_l1 \Fieg\PC\Proposition */
     $this->assertTrue($kb->query($light_l1));
     $this->assertFalse($kb->query($pb->atom('light_l6')));
     // light_l6 is not in KB
     $this->assertTrue($kb->query($lit_l2));
 }