상속: implements GraphAware\Common\Type\Node
예제 #1
0
 public function testConfigExtendsKeyValue()
 {
     $config = new SimpleConfig();
     $config->add('month', 'june');
     $config->add('obj', FakeNode::createDummy());
     $this->assertEquals('june', $config->get('month'));
     $this->assertInstanceOf(Node::class, $config->get('obj'));
 }
예제 #2
0
 public function testComputeSimilarity2()
 {
     $instance = new KNNModelBuilder(null, new CosineSimilarity());
     $source = new ObjectSet(Rating::class);
     $destination = new ObjectSet(Rating::class);
     $node1 = new FakeNode(1);
     $node2 = new FakeNode(2);
     $node3 = new FakeNode(3);
     $node4 = new FakeNode(4);
     $node5 = new FakeNode(5);
     $source->add(new Rating(1, $node1->identity()));
     $source->add(new Rating(3, $node4->identity()));
     $destination->add(new Rating(1, $node2->identity()));
     $destination->add(new Rating(2, $node4->identity()));
     $destination->add(new Rating(5, $node5->identity()));
     $similarity = $instance->computeSimilarity($source, $destination);
     $this->assertTrue($similarity >= 0.34641016 && $similarity <= 0.346410161514);
 }
 public function testOverride()
 {
     $engine = new OverrideDiscoveryEngine();
     $input = FakeNode::createDummy();
     $this->assertCount(2, $engine->discoveryQuery($input)->parameters());
     $this->assertEquals($input->identity(), $engine->discoveryQuery($input)->parameters()['input']);
     $this->assertEquals("recommendation", $engine->recoResultName());
     $this->assertEquals("rate", $engine->scoreResultName());
     $this->assertEquals("source", $engine->idParamName());
     $this->assertEquals(10, $engine->defaultScore());
 }
 public function testResultGetTwoScoresIfDiscoveredTwice()
 {
     $node = FakeNode::createDummy();
     $list = new Recommendations();
     $list->add($node, 'e1', new SingleScore(1));
     $list->add($node, 'e2', new SingleScore(1));
     $this->assertEquals(1, $list->size());
     $this->assertEquals(2, $list->getItems()[0]->totalScore());
     $this->assertCount(2, $list->get(0)->getScores());
     $this->assertArrayHasKey('e1', $list->get(0)->getScores());
     $this->assertArrayHasKey('e2', $list->get(0)->getScores());
 }
 public function testReasons()
 {
     $node = FakeNode::createDummy();
     $list = new Recommendations(new SimpleContext());
     $list->add($node, 'disc1', new SingleScore(1, 'reason1'));
     $list->add($node, 'disc1', new SingleScore(1, 'reason2'));
     $list->add($node, 'disc2', new SingleScore(3, 'reason3'));
     for ($i = 0; $i < 10; ++$i) {
         $list->add($node, 'disc3', new SingleScore(1, 'reasond' . $i));
     }
     $reco = $list->get(0);
     $this->assertEquals(15, $reco->totalScore());
     $this->assertArrayHasKey('disc3', $reco->getScores());
     $this->assertCount(10, $reco->getScore('disc3')->getScores());
 }
예제 #6
0
 public function testDefault()
 {
     $input = FakeNode::createDummy();
     $context = new SimpleContext();
     $this->assertInstanceOf(Config::class, $context->config());
 }