Skip to content
jadell edited this page Oct 7, 2013 · 3 revisions

GEOFF (Graph Export Object File Format) is a text representation of a graph (a set of nodes and relationships between nodes). GEOFF can also handle importing indexed key/value pairs on nodes and relationships. The format is heavily based on Neo4j's Cypher syntax.

Plenty of great information on GEOFF is available at the py2neo site.

GEOFF and neo4jphp

neo4jphp provides functionality for both importing from and exporting to GEOFF files. Each import/export operation is considered independent of any others. If a node or relationship entity with the same identifier is present in more than one import/export, the entity will be created more than once (on import) or written more than once (on export.)

Importing from GEOFF

Importing a GEOFF file (or string) results in a Batch object representing all the create node, create relationship and index operations in the file. The batch can be committed, or it can be used to import another GEOFF file. In the latter case, operations from each additional file will be appended to the original batch.

$geoff = new Everyman\Neo4j\Geoff($client);

// Import from a file
$handle = fopen('/path/to/file.geoff', 'r');
$singleBatch = $geoff->load($handle);
$singleBatch->commit();

// Import from a string
$geoffString = '(Liz)	{"name": "Elizabeth", "title": "Queen of the Commonwealth Realms"}'.PHP_EOL;
$multiBatch = $geoff->load($handle);

// Append to an existing batch
$multiBatch = $geoff->load(fopen('/path/to/another.geoff', 'r'), $multiBatch);
$multiBatch->commit();

Exporting to GEOFF

A path or an array of paths can be exported to a GEOFF file. If no file handle is provided, a GEOFF string will be returned. In the following code, assume $pathA and $pathB are Path objects.

$geoff = new Everyman\Neo4j\Geoff($client);

// Export to a file
$handle = fopen('/path/to/file.geoff', 'w+');
$geoff->dump(array($pathA, $pathB), $handle);

// Export to a string
$geoffString = $geoff->dump($pathA);
Clone this wiki locally