Пример #1
0
{$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();
    $kevin->relateTo($mysticRiver, 'IN')->save();
    // Find all actors in a movie
} else {
    if ($cmd == 'actors') {
Пример #2
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";
 public function insert_with_index($modelName, $property, $value)
 {
     try {
         /* creating node index */
         $nodeIndex = new NodeIndex($this->client, $modelName);
         /* creating label*/
         $label = $this->client->makeLabel($modelName);
         /* creating node */
         $node = $this->client->makeNode()->setProperty($property, $value)->save();
         /* labeling node */
         $node->addLabels(array($label));
         /* adding node to index */
         $nodeIndex->add($node, $property, $node->getProperty($property));
         return $node->getId();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Пример #4
0

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];
        $algorithm = null;
Пример #5
0
    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
} else {