function testPlurality()
 {
     $m = new MammalClassifier();
     $testData = '[{"buffalo":1,"antelope":1},{"buffalo":2},{"cat":2},{"buffalo":1},{"cat":2},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":2},{"giraffe":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":2,"antelope":1},{"buffalo":2,"antelope":1},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"nothing_here":0},{"buffalo":1,"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2}]';
     $result = $m->onDataSet(json_decode($testData, true))->classify()->getResult();
     $this->assertArrayHasKey('classification', $result);
     $this->assertArrayHasKey('antelope', $result['classification']);
     $this->assertArrayHasKey('buffalo', $result['classification']);
     $this->assertEquals(1, $result['classification']['antelope']);
     $this->assertEquals(1, $result['classification']['buffalo']);
 }
 /**
  * @param $imageId integer Run the algorithm on a single image
  * @param boolean $store Store the result
  * @param MammalClassifier|null $classifier An instance of MammalClassifier
  * @param $classification
  * @param bool $scientistDataset Whether to store in the scientist dataset table
  * @return array|string The result
  */
 public function runOnClassification($imageId, $store, $classifier, $classification, $scientistDataset = false)
 {
     if (!$classifier) {
         $classifier = new MammalClassifier(null, $scientistDataset);
     }
     try {
         if ($store) {
             return $classifier->onDataSet($classification)->classify()->store()->getResult();
         } else {
             return $classifier->onDataSet($classification)->classify()->getResult();
         }
     } catch (Exception $e) {
         return "No classifications.";
     }
 }
Beispiel #3
0
<?php

require '../../src/core.php';
$classifier = new MammalClassifier();
$testJson = '[{"buffalo":1,"antelope":2},{"buffalo":2},{"cat":2},{"buffalo":1},{"cat":2},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":2},{"giraffe":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":2,"antelope":1},{"buffalo":2,"antelope":1},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"nothing_here":0},{"buffalo":1,"antelope":1},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2}]';
if (isset($_POST['data'])) {
    echo '<pre>';
    $classifications = json_decode($_POST['data'], true);
    echo "\nResult: \n";
    print_r($classifier->onDataSet($classifications)->classify()->getResult());
    echo '</pre>';
} else {
    $classifications = json_decode($testJson, true);
    echo "\nResult: \n";
    print_r($classifier->onDataSet($classifications)->classify()->getResult());
}