Exemplo n.º 1
0
 public function testRecommendCosineHailey()
 {
     $data = new Data($this->set);
     $recommendations = $data->recommend('Hailey', new Cosine());
     $this->assertEquals(3, count($recommendations));
     $this->assertEquals('Blues Traveler', $recommendations[0]['key']);
     $this->assertEquals(5.0, $recommendations[0]['value']);
     $this->assertEquals('Phoenix', $recommendations[1]['key']);
     $this->assertEquals(5.0, $recommendations[1]['value']);
 }
Exemplo n.º 2
0
 /**
  * @param string $for
  * @param object $strategy
  */
 public function findNearest($for, $strategy = null)
 {
     if ($strategy === null) {
         $strategy = new Cosine();
     }
     return parent::findNearest($for, $strategy);
 }
Exemplo n.º 3
0
 public function testFromReadme()
 {
     $artistRatings = ['Abe' => ['Blues Traveler' => 3, 'Broken Bells' => 2, 'Norah Jones' => 4, 'Phoenix' => 5, 'Slightly Stoopid' => 1, 'The Strokes' => 2, 'Vampire Weekend' => 2], 'Blair' => ['Blues Traveler' => 2, 'Broken Bells' => 3, 'Deadmau5' => 4, 'Phoenix' => 2, 'Slightly Stoopid' => 3, 'Vampire Weekend' => 3], 'Clair' => ['Blues Traveler' => 5, 'Broken Bells' => 1, 'Deadmau5' => 1, 'Norah Jones' => 3, 'Phoenix' => 5, 'Slightly Stoopid' => 1]];
     $data = new \stojg\recommend\Data($artistRatings);
     $recommendations = $data->recommend('Blair', new \stojg\recommend\strategy\Manhattan());
     $this->assertEquals('Norah Jones', $recommendations[0]['key']);
     $this->assertEquals(4, $recommendations[0]['value']);
 }