Example #1
0
    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());
    }
 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>');
     }
 }