Graph Definition Language (GDL)
Inspired by the Neo4j Cypher query language, GDL allows the simple definition of property graphs. GDL contains a parser and simple structs that represent the property graph and its elements. The Rust implementation is inspired by my Java implementation.
Property graph data model
A property graph consists of nodes and relationships. Nodes have zero or more labels, relationships have zero or one relationship type. Both, nodes and relationships have properties, organized as key-value-pairs. Relationships are directed, starting at a source node and pointing at a target node.
Quickstart example
use ;
use Rc;
let gdl_string = "(alice:Person { name: 'Alice', age: 23 }),
(bob:Person { name: 'Bob', age: 42 }),
(alice)-[r:KNOWS { since: 1984 }]->(bob)";
let graph = gdl_string..unwrap;
assert_eq!;
assert_eq!;
let alice = graph.get_node.unwrap;
assert_eq!;
assert_eq!;
let relationship = graph.get_relationship.unwrap;
assert_eq!;
More GDL language examples
Define a node:
let g = "()"..unwrap;
assert_eq!;
Define a node and assign it to variable alice
:
let g = "(alice)"..unwrap;
assert!;
Define a node with label User
and multiple properties:
let g = "(alice:User { name: 'Alice', age : 23 })"..unwrap;
assert_eq!;
assert!;
assert!;
Define an outgoing relationship:
let g = "(alice)-->()"..unwrap;
assert_eq!;
Define an incoming relationship:
let g = "(alice)<--()"..unwrap;
assert_eq!;
Define a relationship with type KNOWS
, assign it to variable r1
and add a property:
use Rc;
let g = "(alice)-[r1:KNOWS { since : 2014 }]->(bob)"..unwrap;
assert!;
assert_eq!;
Define multiple outgoing relationships from the same source node (i.e. alice
):
let g = "
(alice)-[r1:KNOWS { since : 2014 }]->(bob)
(alice)-[r2:KNOWS { since : 2013 }]->(eve)
"..unwrap;
assert_eq!;
assert_eq!;
Define paths (four nodes and three relationships are created):
let g = "()-->()<--()-->()"..unwrap;
assert_eq!;
assert_eq!;
Paths can be comma separated to express arbitrary complex patterns:
let g = "
()-->()<--()-->(),
()<--()-->()-->(),
()-->()<--()-->()
"..unwrap;
assert_eq!;
assert_eq!;
License
Apache 2.0 or MIT