Export result as Geoff from Neo4jPHP?

124 views
Skip to first unread message

Robert Crowe

unread,
Dec 19, 2012, 7:12:54 PM12/19/12
to ne...@googlegroups.com
I'd like to snapshot my graph using Neo4jPHP by exporting it as Geoff, but the export only seems to accept paths.  I had hoped to do a simple Cypher query like:

$queryString = "START n=node(*) return n";
$query
= new Everyman\Neo4j\Cypher\Query($client, $queryString);
$result
= $query->getResultSet();

and export the results to Geoff.  So I either need to find a way to convert the result object to a path object, or figure out how to get an array of paths with having a specific endpoint.

Any ideas?  Thanks in advance!

Robert

Josh Adell

unread,
Dec 19, 2012, 10:03:37 PM12/19/12
to ne...@googlegroups.com
That query won't actually return a copy of the graph, just the nodes.  Change up your query a bit, then loop through the Cypher resultset object to turn it into an array of paths:

$queryString = "START n=node(*) MATCH p = n --> () RETURN p";

$query 
= new Everyman\Neo4j\Cypher\Query($client, $queryString);
$result 
= $query->getResultSet();
$paths = array();
foreach ($result as $row) {
    $paths[] = $row['p'];
}

-- Josh

Michael Hunger

unread,
Dec 20, 2012, 2:06:11 AM12/20/12
to ne...@googlegroups.com
That won't return nodes that have no relationships.

Probably use:

START n=node(*) MATCH n -[r?]->m RETURN n,r,id(m)

use the m and n's id's to generate geoff identifiers, and the properties of n,r as well

--
 
 

Nigel Small

unread,
Dec 20, 2012, 2:42:20 AM12/20/12
to ne...@googlegroups.com
The cypher command line tool that comes with py2neo can export to Geoff as well:

cypher -f geoff "START...."

Nige


--
 
 

Robert Crowe

unread,
Dec 20, 2012, 6:57:37 PM12/20/12
to ne...@googlegroups.com
Thanks Josh, that works!

Michael Hunger

unread,
Feb 2, 2013, 10:05:28 AM2/2/13
to ne...@googlegroups.com
You can use the export code from the neo4j console


Michael

Sent from mobile device

Am 02.02.2013 um 14:08 schrieb Dmitry Serebrennikov <dser...@gmail.com>:

This seems to be something that should be easy. Geoff import is tantalizingly simple with the plugin, but there seems to be no easy export...

I guess my problem is that I'm still a newbie in cypher. Was just hoping for an easy mysqldump equivalent :) but so far no luck...

I'm trying to find a way to export a subgraph that starts from a particular node and includes any nodes reachable via any of 3 or 4 different relationship types. The maximum depth will be under 5. However, I also need to include connections between these nodes such that the subgraph can be fully restored on another instance of neo.

For example:
(start)-[:r1]->(a1)
(a1)-[:r2]->(b1_1)
(a1)-[:r2]->(b1_2)
(a1)-[:r3]->(c1_1)
(c1_1)-[:r4]->(b1_1)
etc

One challenge is how to cleanly walk this subgraph and not "escape" into the larger graph.
Second challenge is how to include (c1_1)-[:r4]->(b1_1) types of connections.

Any help is greatly appreciated!
Thanks!
Dmitry
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dmitry Serebrennikov

unread,
Feb 3, 2013, 4:53:47 AM2/3/13
to ne...@googlegroups.com
Thanks for the quick reply!
This helps.
But, it still exports the entire graph. What's the best way to target this to a subgraph? Would cypher be the way to go or something low level is more appropriate?
Is there a well-defined standard way of defining and extracting a subgraph or is this so application-specific that there is just no way to write a nice easy tool like mysqldump (I suspect the latter)?

Thanks!
-Dmitry

Michael Hunger

unread,
Feb 3, 2013, 6:19:13 AM2/3/13
to ne...@googlegroups.com
Hoe to you specify a subset of the db in mysqldump?

There is also code to export the graph to cypher based on data from a previous cypher execution

Sent from mobile device

Dmitry Serebrennikov

unread,
Feb 3, 2013, 8:27:35 PM2/3/13
to ne...@googlegroups.com
Well, in mysql you have luxury of databases and tables. So you can dump all tables from one db, a list of named tables, or a list of named tables with a where expression applied.
But in neo there is just one "space" for data that is all connected and no much regarding types of nodes (unless some thing like Spring Data gives you that via _type_ field).

Here's a half-baked proposal for automatic subgraph extraction – just to keep conversation going.
Please take this with a grain of salt – I'm very new to the graph land still.

Half-Baked Proposal
I think the way to do this in graphs would be to specify some starting nodes and allowed traversal rules, and then export everything reachable from these starting points. All relationships affecting the selected nodes would also be included. Relationships between the nodes in the exported set are part of the subgraph, so they should be exported. Relationships that connect exported nodes with the rest of the graph should also be exported because they necessary to "reconnect" the subgraph to the destination graph upon import. This of course assumes some kind of unique key-based lookup of the nodes in the destination graph to reconnect with. And what if they are not found? Perhaps these relationships are then to be dropped or placeholder nodes created automatically?

In mysql land, equivalent of these relationships are foreign keys, which are defined at the table-to-table level (i.e. Node-type to node-type) and so they are already "present" in the destination db. All that's needed is to insert the rows and "relationships" are automatically re-established.
Reply all
Reply to author
Forward
0 new messages