コード例 #1
0
 private function exportToDB($graph, OutputInterface $output, Client $client)
 {
     $converter = new CypherStatementsConverter();
     $converter->convert($graph);
     try {
         $constraints = 0;
         foreach ($converter->getConstraintStatements() as $statement) {
             $client->sendCypherQuery($statement['statement']);
             $constraints++;
         }
         $output->writeln('<info>Created ' . $constraints . ' constraint(s)</info>');
         $nodes = 0;
         foreach ($converter->getNodeStatements() as $ns) {
             $client->sendCypherQuery($ns['statement'], $ns['parameters']);
             $nodes += count($ns['parameters']['props']);
         }
         $output->writeln('<info>Created ' . $nodes . ' node(s)</info>');
         $edges = 0;
         foreach ($converter->getEdgeStatements() as $es) {
             $params = isset($es['parameters']) ? $es['parameters'] : ['pairs' => []];
             $client->sendCypherQuery($es['statement'], $params);
             $edges += count($params['pairs']);
         }
         $output->writeln('<info>Created ' . $edges . ' relationship(s)</info>');
     } catch (HttpException $e) {
         $output->writeln('<error>Unable to connect to the database' . PHP_EOL . $e->getMessage() . PHP_EOL . '</error>');
     }
 }
コード例 #2
0
 public function testConversion()
 {
     $gen = new Neogen();
     $p = '(person:Person {firstname:firstName, lastname:lastName} *5)-[:WORKS_AT *n..1]->(company:Company {name:company} *10)
     (actor:Person:Actor {name:fullName, birthdate:{dateTimeBetween:["-50 years","-18 years"]}} *10)-[:WORKS_AT {since:{dateTimeBetween:["-5 years","-1 years"]}} *n..1]->(company)';
     $graph = $gen->generateGraphFromCypher($p);
     $converter = new CypherStatementsConverter();
     $converter->convert($graph);
     $client = ClientBuilder::create()->addDefaultLocalConnection()->build();
     $client->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
     $statements = $converter->getStatements();
     foreach ($statements['constraints'] as $st) {
         $client->sendCypherQuery($st['statement']);
     }
     foreach ($statements['nodes'] as $st) {
         $client->sendCypherQuery($st['statement'], $st['parameters']);
     }
     foreach ($statements['edges'] as $st) {
         if (!isset($st['parameters'])) {
             $parameters = array();
         } else {
             $parameters = $st['parameters'];
         }
         $client->sendCypherQuery($st['statement'], $parameters);
     }
 }
コード例 #3
0
ファイル: ProcessorTest.php プロジェクト: neoxygen/neogen
    public function testPatternProcessing1()
    {
        $p = '(p:Product *1)
(cc:ComponentCategory *20)-[:PART_OF {quantity: {randomNumber: [3]}} *n..1]->(p)
(csc:ComponentSubCategory *20)-[:PART_OF {quantity: {randomNumber: [3]}} *n..1]->(cc)
(c:Component {price: {randomNumber: [2]}} *20)-[:PART_OF {quantity: {randomNumber: [3]}} *n..1]->(csc)';
        $gen = new Neogen();
        $schema = $gen->generateGraphFromCypher($p);
        $converter = new CypherStatementsConverter();
        $converter->convert($schema);
        $edgesStatements = $converter->getEdgeStatements();
        $this->assertCount(7, $edgesStatements);
        $this->assertCount(4, $converter->getNodeStatements());
    }
コード例 #4
0
ファイル: IntegrationTest.php プロジェクト: neoxygen/neogen
 public function loadGraphInDB($pattern)
 {
     $this->clearDB();
     $gen = new Neogen();
     $schema = $gen->generateGraphFromCypher($pattern);
     $converter = new CypherStatementsConverter();
     $converter->convert($schema);
     $statements = $converter->getStatements();
     foreach ($statements as $statement) {
         if (is_array($statement)) {
             foreach ($statement as $st) {
                 $props = isset($st['parameters']) ? $st['parameters'] : array();
                 $this->sendQuery($st['statement'], $props);
             }
         } else {
             $props = isset($statement['parameters']) ? $statement['parameters'] : array();
             $this->sendQuery($statement['statement'], $props);
         }
     }
 }