public function blacklistQuery(Node $input)
 {
     $query = 'MATCH (input) WHERE id(input) = {inputId}
     MATCH (input)-[:RATED]->(movie)
     RETURN movie as item';
     return Statement::create($query, ['inputId' => $input->identity()]);
 }
Esempio n. 2
0
 public function discoveryQuery(Node $input, Context $context) : StatementInterface
 {
     $query = 'MATCH (n) WHERE id(n) = {id}
     MATCH (n)-[:FRIEND]->(friend)-[:FRIEND]->(reco)
     WHERE NOT (n)-[:FRIEND]->(reco)
     RETURN reco, count(*) as score';
     return Statement::prepare($query, ['id' => $input->identity()]);
 }
Esempio n. 3
0
 public function discoveryQuery(Node $input, Context $context)
 {
     $query = 'MATCH (input:User) WHERE id(input) = {id}
     MATCH (input)-[:RATED]->(m)<-[:RATED]-(o)
     WITH distinct o
     MATCH (o)-[:RATED]->(reco)
     RETURN distinct reco LIMIT 500';
     return Statement::create($query, ['id' => $input->identity()]);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function containsNode(NodeInterface $node)
 {
     foreach ($this->nodes as $n) {
         if ($n->identity() === $node->identity()) {
             return true;
         }
     }
     return false;
 }
Esempio n. 5
0
 /**
  * @param \GraphAware\Common\Type\Node $item
  *
  * @return \GraphAware\Reco4PHP\Result\Recommendation
  */
 public function getOrCreate(Node $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 final function buildQuery(Node $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()]);
 }
Esempio n. 7
0
 public function discoveryQuery(Node $input, Context $context)
 {
     $query = 'MATCH (input) WHERE id(input) = {id}
     MATCH (input)-[r:RATED]->(movie)-[:HAS_GENRE]->(genre)
     WITH distinct genre, sum(r.rating) as score
     ORDER BY score DESC
     LIMIT 15
     MATCH (genre)<-[:HAS_GENRE]-(reco)
     RETURN reco
     LIMIT 200';
     return Statement::create($query, ['id' => $input->identity()]);
 }
Esempio n. 8
0
 public function doInclude(Node $input, Node $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;
 }
 public function discoveryQuery(Node $input, Context $context) : StatementInterface
 {
     $query = "MATCH (n) WHERE id(n) <> {inputId} RETURN n";
     return Statement::create($query, ['inputId' => $input->identity()]);
 }
Esempio n. 10
0
 private function hydrateNode(Node $node, $className = null, $andProxy = false)
 {
     if ($entity = $this->entityManager->getUnitOfWork()->getEntityById($node->identity())) {
         return $entity;
     }
     $cl = $className !== null ? $className : $this->className;
     $cm = $className === null ? $this->classMetadata : $this->entityManager->getClassMetadataFor($cl);
     $pmVersion = !method_exists(Version::class, 'getVersion') ? 1 : (int) Version::getVersion()[0];
     $em = $this->entityManager;
     if ($andProxy) {
         if ($pmVersion >= 2) {
             $initializer = function ($ghostObject, $method, array $parameters, &$initializer, array $properties) use($cm, $node, $em, $pmVersion) {
                 $initializer = null;
                 /*
                 foreach ($cm->getPropertiesMetadata() as $field => $meta) {
                     if ($node->hasValue($field)) {
                 
                         $key = null;
                         if ($meta->getReflectionProperty()->isPrivate()) {
                             $key = '\\0' . $cm->getClassName() . '\\0' . $meta->getPropertyName();
                         } else if($meta->getReflectionProperty()->isProtected()) {
                             $key = '' . "\0" . '*' . "\0" . $meta->getPropertyName();
                         } else if ($meta->getReflectionProperty()->isPublic()) {
                             $key = $meta->getPropertyName();
                         }
                 
                         if (null !== $key) {
                             $properties[$key] = $node->value($field);
                         }
                 
                         foreach ($cm->getLabeledProperties() as $labeledProperty) {
                             //$v = $node->hasLabel($labeledProperty->getLabelName()) ? true : false;
                             //$labeledProperty->setLabel($instance, $v);
                         }
                     }
                 }
                 */
                 foreach ($cm->getSimpleRelationships(false) as $relationship) {
                     if (!$relationship->isCollection()) {
                         $finder = new RelationshipsFinder($em, $relationship->getTargetEntity(), $relationship);
                         $instances = $finder->find($node->identity());
                         if (count($instances) > 0) {
                             $properties[ProxyUtils::getPropertyIdentifier($relationship->getReflectionProperty(), $cm->getClassName())] = $instances[0];
                         }
                     }
                 }
                 return true;
             };
         } else {
             $initializer = function ($ghostObject, $method, array $parameters, &$initializer) use($cm, $node, $em, $pmVersion) {
                 $initializer = null;
                 foreach ($cm->getPropertiesMetadata() as $field => $meta) {
                     if ($node->hasValue($field)) {
                         $meta->setValue($ghostObject, $node->value($field));
                     }
                 }
                 foreach ($cm->getSimpleRelationships(false) as $relationship) {
                     if (!$relationship->isCollection()) {
                         $finder = new RelationshipsFinder($em, $relationship->getTargetEntity(), $relationship);
                         $instances = $finder->find($node->identity());
                         if (count($instances) > 0) {
                             $relationship->setValue($ghostObject, $instances[0]);
                         }
                     }
                 }
                 $cm->setId($ghostObject, $node->identity());
                 return true;
             };
         }
         $proxyOptions = ['skippedProperties' => ['' . "" . '*' . "" . 'id']];
         $instance = 2 === $pmVersion ? $this->lazyLoadingFactory->createProxy($cm->getClassName(), $initializer, $proxyOptions) : $this->lazyLoadingFactory->createProxy($cm->getClassName(), $initializer);
         foreach ($cm->getPropertiesMetadata() as $field => $propertyMetadata) {
             if ($node->hasValue($field)) {
                 $propertyMetadata->setValue($instance, $node->value($field));
             }
         }
         $cm->setId($instance, $node->identity());
         foreach ($cm->getRelationships() as $relationship) {
             if (!$relationship->isRelationshipEntity()) {
                 if ($relationship->isCollection()) {
                     $lazyCollection = new LazyRelationshipCollection($this->entityManager, $instance, $relationship->getTargetEntity(), $relationship);
                     $relationship->setValue($instance, $lazyCollection);
                     continue;
                 }
             }
             if ($relationship->isRelationshipEntity()) {
                 if ($relationship->isCollection()) {
                     $lazyCollection = new LazyRelationshipCollection($this->entityManager, $instance, $relationship->getRelationshipEntityClass(), $relationship);
                     $relationship->setValue($instance, $lazyCollection);
                 } else {
                 }
             }
         }
         $i2 = clone $instance;
         $this->entityManager->getUnitOfWork()->addManaged($i2);
         return $i2;
     }
     $instance = $cm->newInstance();
     foreach ($cm->getPropertiesMetadata() as $field => $meta) {
         if ($meta instanceof EntityPropertyMetadata) {
             if ($node->hasValue($field)) {
                 $meta->setValue($instance, $node->value($field));
             }
         } elseif ($meta instanceof Label) {
             $label = $meta->name;
             /*
             $v = $node->hasLabel($label);
             if ($property = $reflClass->getProperty($field)) {
                 $property->setAccessible(true);
                 $property->setValue($instance, $v);
             }
             */
         }
     }
     foreach ($cm->getLabeledProperties() as $labeledProperty) {
         $v = $node->hasLabel($labeledProperty->getLabelName()) ? true : false;
         $labeledProperty->setLabel($instance, $v);
     }
     foreach ($cm->getRelationships() as $relationship) {
         if ($relationship->isCollection()) {
             $relationship->initializeCollection($instance);
         }
     }
     $cm->setId($instance, $node->identity());
     $this->entityManager->getUnitOfWork()->addManaged($instance);
     return $instance;
 }
Esempio n. 11
0
 public function doInclude(Node $input, Node $item)
 {
     return $input->identity() !== $item->identity();
 }
 public function discoveryQuery(Node $input, Context $context) : StatementInterface
 {
     $query = "MATCH (n) WHERE id(n) <> {input}\n        RETURN n LIMIT {limit}";
     return Statement::create($query, ['input' => $input->identity(), 'limit' => 300]);
 }
Esempio n. 13
0
 public function blacklistQuery(Node $input)
 {
     $query = 'MATCH (n) WHERE n.name = "Zoe" RETURN n as item';
     return Statement::prepare($query, ['id' => $input->identity()]);
 }
Esempio n. 14
0
 /**
  * @param \GraphAware\Common\Type\Node $node
  *
  * @return bool
  */
 public function contains(Node $node)
 {
     return array_key_exists($node->identity(), $this->elements);
 }