コード例 #1
0
 public function removeIrrelevant(NodeInterface $input, RecommendationEngine $engine, Recommendations $recommendations)
 {
     foreach ($recommendations->getItems() as $recommendation) {
         foreach ($engine->filters() as $filter) {
             if (!$filter->doInclude($input, $recommendation->item())) {
                 $recommendations->remove($recommendation);
             }
         }
     }
 }
コード例 #2
0
 private function buildBlacklistedNodes(ResultCollection $result, RecommendationEngine $engine)
 {
     $set = [];
     foreach ($engine->getBlacklistBuilders() as $blacklist) {
         $res = $result->get($blacklist->name());
         foreach ($res->records() as $record) {
             if ($record->hasValue($blacklist->itemResultName())) {
                 $node = $record->get($blacklist->itemResultName());
                 if ($node instanceof Node) {
                     $set[$node->identity()] = $node;
                 }
             }
         }
     }
     return $set;
 }
コード例 #3
0
 public function execute(NodeInterface $input, Recommendations $recommendations, RecommendationEngine $recommendationEngine)
 {
     $this->stack = $this->databaseService->getDriver()->stack('post_process_' . $recommendationEngine->name());
     foreach ($recommendationEngine->postProcessors() as $postProcessor) {
         if ($postProcessor instanceof CypherAwarePostProcessor) {
             foreach ($recommendations->getItems() as $recommendation) {
                 $this->prepareQuery($input, $recommendation, $postProcessor);
             }
         }
     }
     try {
         $results = $this->databaseService->getDriver()->runStack($this->stack);
         $this->stack = null;
         return $results;
     } catch (\Exception $e) {
         throw new \RuntimeException('PostProcess Query Exception - ' . $e->getMessage());
     }
 }
コード例 #4
0
 /**
  * @param \GraphAware\Common\Type\NodeInterface $input
  * @param \GraphAware\Reco4PHP\Result\Recommendations $recommendations
  * @param \GraphAware\Reco4PHP\Engine\RecommendationEngine $recommendationEngine
  *
  * @return \GraphAware\Common\Result\ResultCollection
  */
 public function execute(NodeInterface $input, Recommendations $recommendations, RecommendationEngine $recommendationEngine)
 {
     $stack = $this->databaseService->getDriver()->stack('post_process_' . $recommendationEngine->name());
     foreach ($recommendationEngine->postProcessors() as $postProcessor) {
         if ($postProcessor instanceof CypherAwarePostProcessor) {
             foreach ($recommendations->getItems() as $recommendation) {
                 $tag = sprintf('post_process_%s_%d', $postProcessor->name(), $recommendation->item()->identity());
                 $statement = $postProcessor->buildQuery($input, $recommendation);
                 $stack->push($statement->text(), $statement->parameters(), $tag);
             }
         }
     }
     try {
         $results = $this->databaseService->getDriver()->runStack($stack);
         return $results;
     } catch (\Exception $e) {
         throw new \RuntimeException('PostProcess Query Exception - ' . $e->getMessage());
     }
 }
コード例 #5
0
 /**
  * @param \GraphAware\Reco4PHP\Engine\RecommendationEngine $recommendationEngine
  */
 public function registerRecommendationEngine(RecommendationEngine $recommendationEngine)
 {
     $recommendationEngine->setDatabaseService($this->databaseService);
     $this->engines[$recommendationEngine->name()] = $recommendationEngine;
 }