public function testFeatureCountInCategory() { for ($i = 1; $i < 4; $i++) { $this->storage->increaseFeatureCountInCategory('testCategory', 'testFeature'); $this->assertEquals($i, $this->storage->getFeatureCountInCategory('testCategory', 'testFeature')); } $this->storage->increaseFeatureCountInCategory('testCategory', 'testFeature2'); $this->assertEquals(1, $this->storage->getFeatureCountInCategory('testCategory', 'testFeature2')); $this->storage->increaseFeatureCountInCategory('testCategory2', 'testFeature'); $this->assertEquals(1, $this->storage->getFeatureCountInCategory('testCategory2', 'testFeature')); }
/** * Train classifier categorize given features to given category. * * @param string $category Category of features. * @param array $features Features of category. * * @return void */ public function learn($category, array $features) { $this->storage->increaseDocumentsCount(); $this->storage->increaseCategoryDocumentsCount($category); $uniqueFeatures = array_unique($features); foreach ($uniqueFeatures as $uniqueFeature) { $this->storage->increaseFeatureDocumentsCountInCategory($category, $uniqueFeature); } foreach ($features as $feature) { $this->storage->increaseFeaturesCount(); $this->storage->increaseFeatureCount($feature); $this->storage->increaseCategoryFeaturesCount($category); $this->storage->increaseFeatureCountInCategory($category, $feature); } }