public function processRecommendation(NodeInterface $input, RecommendationEngine $engine) { $recommendations = new Recommendations(); $this->stopwatch->start('discovery'); $discoveryResult = $this->discoveryExecutor->processDiscovery($input, $engine->engines()); foreach ($engine->engines() as $discoveryEngine) { $recommendations->merge($discoveryEngine->produceRecommendations($input, $discoveryResult)); } $discoveryTime = $this->stopwatch->stop('discovery'); echo $discoveryTime->getDuration() . PHP_EOL; $this->removeIrrelevant($input, $engine, $recommendations); $this->stopwatch->start('post_process'); $postProcessResult = $this->postProcessExecutor->execute($input, $recommendations, $engine); foreach ($engine->postProcessors() as $postProcessor) { foreach ($recommendations->getItems() as $recommendation) { if ($postProcessor instanceof CypherAwarePostProcessor) { $tag = sprintf('post_process_%s_%d', $postProcessor->name(), $recommendation->item()->identity()); $postProcessor->doPostProcess($input, $recommendation, $postProcessResult->get($tag)); } else { $postProcessor->postProcess($input, $recommendation); } } } $pPTime = $this->stopwatch->stop('post_process'); echo $pPTime->getDuration() . PHP_EOL; $recommendations->sort(); return $recommendations; }