Ejemplo n.º 1
0
 public function run()
 {
     $neo4j_config = \Config::get('database.connections.neo4j');
     // Create an admin user
     $client = new Everyman\Neo4j\Client($neo4j_config['host'], $neo4j_config['port']);
     $client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);
     foreach ($this->listNames as $listName) {
         $labels = [$client->makeLabel('E32'), $client->makeLabel('AuthorityDocument'), $client->makeLabel('MEDEA_NODE')];
         $nameLabel = $client->makeLabel($listName);
         $labels[] = $nameLabel;
         // Avoid duplicates
         $duplicates = $nameLabel->getNodes();
         foreach ($duplicates as $duplicate) {
             $relationships = $duplicate->getRelationships();
             foreach ($relationships as $rel) {
                 $rel->delete();
             }
             $this->command->info("Found duplicate for {$listName}, deleting it first in order to reseed.");
             $duplicate->delete();
         }
         $node = $client->makeNode();
         $node->save();
         $node->addLabels($labels);
         $functionName = 'get' . $listName;
         $node->setProperty('values', $this->{$functionName}());
         $node->save();
         $this->command->info("Seeded node, {$listName}");
     }
 }
Ejemplo n.º 2
0
 /**
  * Convert a model to a Node object.
  *
  * @param  \Vinelab\NeoEloquent\Eloquent\Model $model
  * @return \Everyman\Neo4j\Node
  */
 public function asNode(Model $model)
 {
     $node = $this->client->makeNode();
     // If the key name of the model is 'id' we will need to set it properly with setId()
     // since setting it as a regular property with setProperty() won't cut it.
     if ($model->getKeyName() == 'id') {
         $node->setId($model->getKey());
     } else {
         $node->setProperty($model->getKeyName(), $model->getKey());
     }
     return $node;
 }
Ejemplo n.º 3
0
 /**
  * @param $entity
  * @return Node|\Everyman\Neo4j\PropertyContainer
  */
 private function createNode($entity)
 {
     $meta = $this->getMeta($entity);
     $pk = $meta->getPrimaryKey();
     $id = $pk->getValue($entity);
     if ($id !== null) {
         $node = $this->client->getNode($id);
     } else {
         $node = $this->client->makeNode()->setProperty('class', $meta->getName());
     }
     foreach ($meta->getProperties() as $property) {
         $result = $property->getValue($entity);
         $node->setProperty($property->getName(), $result);
     }
     $currentDate = $this->getCurrentDate();
     if ($id === null) {
         $node->setProperty('creationDate', $currentDate);
     }
     $node->setProperty('updateDate', $currentDate);
     return $node;
 }
Ejemplo n.º 4
0
{$argv[0]} init
\tInitialize the data.  This only needs to be done once.

{$argv[0]} actors <movie_name>
\tGet a list of all actors in the movie.


HELP;
    exit(0);
}
$client = new Client();
$actors = new NodeIndex($client, 'actors');
// Initialize the data
if ($cmd == 'init') {
    $keanu = $client->makeNode()->setProperty('name', 'Keanu Reeves')->save();
    $laurence = $client->makeNode()->setProperty('name', 'Laurence Fishburne')->save();
    $jennifer = $client->makeNode()->setProperty('name', 'Jennifer Connelly')->save();
    $kevin = $client->makeNode()->setProperty('name', 'Kevin Bacon')->save();
    $actors->add($keanu, 'name', $keanu->getProperty('name'));
    $actors->add($laurence, 'name', $laurence->getProperty('name'));
    $actors->add($jennifer, 'name', $jennifer->getProperty('name'));
    $actors->add($kevin, 'name', $kevin->getProperty('name'));
    $matrix = $client->makeNode()->setProperty('title', 'The Matrix')->save();
    $higherLearning = $client->makeNode()->setProperty('title', 'Higher Learning')->save();
    $mysticRiver = $client->makeNode()->setProperty('title', 'Mystic River')->save();
    $keanu->relateTo($matrix, 'IN')->save();
    $laurence->relateTo($matrix, 'IN')->save();
    $laurence->relateTo($higherLearning, 'IN')->save();
    $jennifer->relateTo($higherLearning, 'IN')->save();
    $laurence->relateTo($mysticRiver, 'IN')->save();
Ejemplo n.º 5
0
#!/usr/bin/env php
<?php 
use Everyman\Neo4j\Client, Everyman\Neo4j\Index\NodeIndex, Everyman\Neo4j\Index\RelationshipIndex, Everyman\Neo4j\Index\NodeFulltextIndex, Everyman\Neo4j\Node, Everyman\Neo4j\Batch;
require_once 'example_bootstrap.php';
$client = new Client();
$actorIndex = new NodeIndex($client, 'actors');
$roleIndex = new RelationshipIndex($client, 'roles');
$plotIndex = new NodeFulltextIndex($client, 'plots');
$plotIndex->save();
$leslie = $client->makeNode()->setProperty('name', 'Leslie Nielsen')->save();
$airplane = $client->makeNode()->setProperty('title', 'Airplane')->save();
$rumack = $leslie->relateTo($airplane, 'PLAYED')->setProperty('character', 'Dr. Rumack')->save();
$actorIndex->add($leslie, 'name', $leslie->getProperty('name'));
$roleIndex->add($rumack, 'character', $rumack->getProperty('character'));
$plotIndex->add($airplane, 'synopsis', 'An airplane crew takes ill. Surely the only person capable of landing the plane is an ex-pilot afraid to fly. But don\'t call him Shirley.');
echo $actorIndex->queryOne('name:Leslie*')->getProperty('name') . "\n";
echo $roleIndex->queryOne('character:*u*')->getProperty('character') . "\n";
echo $plotIndex->queryOne('synopsis:lend~0.2')->getProperty('title') . "\n";
Ejemplo n.º 6
0
\t\tall:     Find all paths, regardless of length.


HELP;
    exit(0);
}
$client = new Client();
$intersections = new NodeIndex($client, 'intersections1');
$inters = array('A' => null, 'B' => null, 'C' => null, 'D' => null, 'E' => null, 'F' => null);
$streets = array(array('A', 'B', array('direction' => 'east', 'distance' => 2.1, 'name' => 'AB')), array('A', 'D', array('direction' => 'south', 'distance' => 2.1, 'name' => 'AD')), array('A', 'E', array('direction' => 'south', 'distance' => 3.1, 'name' => 'AE')), array('B', 'A', array('direction' => 'west', 'distance' => 2.1, 'name' => 'AB')), array('B', 'C', array('direction' => 'east', 'distance' => 2.1, 'name' => 'BC')), array('B', 'E', array('direction' => 'south', 'distance' => 2.1, 'name' => 'BE')), array('C', 'B', array('direction' => 'west', 'distance' => 2.1, 'name' => 'BC')), array('C', 'F', array('direction' => 'south', 'distance' => 1.1, 'name' => 'CF')), array('D', 'A', array('direction' => 'north', 'distance' => 2.1, 'name' => 'AD')), array('D', 'E', array('direction' => 'east', 'distance' => 2.1, 'name' => 'DE')), array('E', 'D', array('direction' => 'west', 'distance' => 2.1, 'name' => 'DE')), array('E', 'B', array('direction' => 'north', 'distance' => 2.1, 'name' => 'BE')), array('F', 'C', array('direction' => 'north', 'distance' => 1.1, 'name' => 'CF')), array('F', 'E', array('direction' => 'west', 'distance' => 2.1, 'name' => 'FE')));
$turns = array('east' => array('north' => 'left', 'south' => 'right', 'west' => 'u-turn'), 'west' => array('north' => 'right', 'south' => 'left', 'east' => 'u-turn'), 'north' => array('east' => 'right', 'west' => 'left', 'south' => 'u-turn'), 'south' => array('east' => 'left', 'west' => 'right', 'north' => 'u-turn'));
// Initialize the data
if ($cmd == 'init') {
    echo "Initializing data.\n";
    foreach ($inters as $inter => $temp) {
        $node = $client->makeNode()->setProperty('name', $inter)->save();
        $intersections->add($node, 'name', $node->getProperty('name'));
        $inters[$inter] = $node;
    }
    foreach ($streets as $info) {
        $start = $inters[$info[0]];
        $end = $inters[$info[1]];
        $properties = $info[2];
        $street = $start->relateTo($end, 'CONNECTS')->setProperties($properties);
        $street->save();
    }
    // Find a path
} else {
    if ($cmd == 'path' && !empty($argv[2]) && !empty($argv[3])) {
        $from = $argv[2];
        $to = $argv[3];
Ejemplo n.º 7
0
HELP;
    exit(0);
}
$client = new Client();
$partsIndex = new NodeIndex($client, 'parts3');
$parts = array('widget', 'gadget', 'gizmo');
$stores = array("Bob's Old Houseware", "Mainstreet Hardware", "Nutz N' Boltz", "Doodad Emporium");
// Store, part list
$orders = array(array(0, array(0, 1)), array(0, array(1)), array(1, array(1, 2)), array(1, array(0, 2)), array(2, array(0, 1, 2)), array(3, array(2)), array(3, array(0)));
// Initialize the data
if ($cmd == 'init') {
    echo "Initializing data.\n";
    $p = array();
    $s = array();
    foreach ($parts as $part) {
        $node = $client->makeNode()->setProperty('name', $part)->save();
        $partsIndex->add($node, 'name', $node->getProperty('name'));
        $p[] = $node;
    }
    foreach ($stores as $store) {
        $node = $client->makeNode()->setProperty('name', $store)->save();
        $s[] = $node;
    }
    foreach ($orders as $order) {
        $node = $client->makeNode()->save();
        $s[$order[0]]->relateTo($node, 'SOLD')->save();
        foreach ($order[1] as $pi) {
            $node->relateTo($p[$pi], 'CONTAINS')->save();
        }
    }
    // List parts
Ejemplo n.º 8
0
 protected static function importRelations($nodeIds, Client $targetClient, $resultSet, $ignoreProperties = null)
 {
     $result = array();
     $id = null;
     $batch = new Batch($targetClient);
     foreach ($resultSet as $row) {
         $id = $row[0]['metadata']['id'];
         $type = $row[0]['type'];
         $properties = $row[0]['data'];
         if (isset($ignoreProperties)) {
             foreach ($properties as $key => $propertyName) {
                 if (in_array($propertyName, $ignoreProperties)) {
                     unset($properties[$key]);
                 }
             }
         }
         $leftNode = $targetClient->makeNode();
         $leftNodeId = $nodeIds[static::extractIdFromUrl($row[0]['start'])];
         $leftNode->setId($leftNodeId);
         $rightNode = $targetClient->makeNode();
         $rightNodeId = $nodeIds[static::extractIdFromUrl($row[0]['end'])];
         $rightNode->setId($rightNodeId);
         $r = $targetClient->makeRelationship($properties);
         $r->setStartNode($leftNode)->setEndNode($rightNode)->setType($type)->setProperties($properties);
         $batch->save($r);
     }
     $batch->commit();
     return array($result, isset($id) ? $id + 1 : null);
 }