public function discoveryQuery(NodeInterface $input) { $query = 'MATCH (n) WHERE id(n) = {id} MATCH (n)-[:CONTRIBUTED_TO]->(repo)<-[:CONTRIBUTED_TO]-(reco) RETURN reco, count(*) as score'; return Statement::create($query, ['id' => $input->identity()]); }
public function blacklistQuery(NodeInterface $input) { $query = 'MATCH (input) WHERE id(input) = {inputId} MATCH (input)-[:RATED]->(movie) RETURN movie as item'; return Statement::create($query, ['inputId' => $input->identity()]); }
public function prepareQuery(NodeInterface $input, Recommendation $recommendation, CypherAwarePostProcessor $postProcessor) { $query = 'MATCH (input), (reco) WHERE id(input) = {idInput} AND id(reco) = {idReco}' . PHP_EOL; $query .= $postProcessor->query(); $parameters = ['idInput' => $input->identity(), 'idReco' => $recommendation->item()->identity()]; $tag = sprintf('post_process_%s_%d', $postProcessor->name(), $recommendation->item()->identity()); $this->stack->push($query, $parameters, $tag); }
/** * @param \GraphAware\Common\Type\NodeInterface $item * * @return \GraphAware\Reco4PHP\Result\Recommendation */ public function getOrCreate(NodeInterface $item) { if (array_key_exists($item->identity(), $this->recommendations)) { return $this->recommendations[$item->identity()]; } $recommendation = new Recommendation($item); $this->recommendations[$item->identity()] = $recommendation; return $recommendation; }
public function discoveryQuery(NodeInterface $input) { $query = 'MATCH (input) WHERE id(input) = {id} MATCH (input)<-[:FOLLOWS]-(follower)-[:FOLLOWS]->(reco) WHERE size((follower)-[:FOLLOWS]->()) < {max_follows} RETURN reco, count(*) as score LIMIT 100'; return Statement::create($query, ['id' => $input->identity(), 'max_follows' => 200]); }
public final function buildQuery(NodeInterface $input, Recommendation $recommendation) { $relationshipPatterns = [Direction::BOTH => array('-[:%s]-', '-[:%s]-'), Direction::INCOMING => array('<-[:%s]-', '-[:%s]->'), Direction::OUTGOING => array('-[:%s]->', '<-[:%s]-')]; $relPattern = sprintf($relationshipPatterns[$this->relationshipDirection()][0], $this->relationshipType()); $inversedRelPattern = sprintf($relationshipPatterns[$this->relationshipDirection()][1], $this->relationshipType()); $query = 'MATCH (input) WHERE id(input) = {inputId}, (item) WHERE id(item) = {itemId} MATCH (input)' . $relPattern . '(shared)' . $inversedRelPattern . '(item) RETURN shared as sharedThing'; return Statement::create($query, ['inputId' => $input->identity(), 'itemId' => $recommendation->item()->identity()]); }
public function discoveryQuery(NodeInterface $input) { $query = 'MATCH (input:User) WHERE id(input) = {id} MATCH (input)-[:RATED]->(movie)<-[:RATED]-(other) WITH distinct other MATCH (other)-[:RATED]->(reco) RETURN reco, count(*) as score ORDER BY score DESC LIMIT 200'; return Statement::create($query, ['id' => $input->identity()]); }
public function doInclude(NodeInterface $input, NodeInterface $item) { $title = $item->value("title"); preg_match('/(?:\\()\\d+(?:\\))/', $title, $matches); if (isset($matches[0])) { $y = str_replace('(', '', $matches[0]); $y = str_replace(')', '', $y); $year = (int) $y; if ($year < 1999) { return false; } return true; } return false; }
/** * @param \GraphAware\Common\Type\NodeInterface $node * * @return bool */ public function contains(NodeInterface $node) { return array_key_exists($node->identity(), $this->elements); }
public final function buildParams(NodeInterface $input) { $this->query(); $this->addParameter($this->idParamName(), $input->identity()); }
public function discoveryQuery(NodeInterface $input) { $query = "MATCH (n) WHERE id(n) <> {inputId} RETURN n"; return Statement::create($query, ['inputId' => $input->identity()]); }
public function discoveryQuery(NodeInterface $input) { $query = "MATCH (n) WHERE id(n) <> {input}\n RETURN n LIMIT {limit}"; return Statement::create($query, ['input' => $input->identity(), 'limit' => 300]); }
public function doInclude(NodeInterface $input, NodeInterface $item) { return $input->identity() !== $item->identity(); }