1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
//! # Graph Definition Language (GDL)
//!
//! Inspired by the [Neo4j Cypher](http://neo4j.com/docs/stable/cypher-query-lang.html) 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](https://github.com/s1ck/gdl).
//!
//! ## 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 gdl::{CypherValue, Graph};
//! use std::rc::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.parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(graph.node_count(), 2);
//! assert_eq!(graph.relationship_count(), 1);
//!
//! let alice = graph.get_node("alice").unwrap();
//! assert_eq!(alice.property_value("age"), Some(&CypherValue::from(23)));
//! assert_eq!(alice.property_value("name"), Some(&CypherValue::from("Alice")));
//!
//! let relationship = graph.get_relationship("r").unwrap();
//! assert_eq!(relationship.rel_type(), Some("KNOWS"));
//! ```
//!
//! ## More GDL language examples
//!
//! Define a node:
//!
//! ```
//! let g = "()".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.node_count(), 1);
//! ```
//!
//! Define a node and assign it to variable `alice`:
//!
//! ```
//! let g = "(alice)".parse::<gdl::Graph>().unwrap();
//!
//! assert!(g.get_node("alice").is_some());
//! ```
//!
//! Define a node with label `User` and multiple properties:
//!
//! ```
//! let g = "(alice:User { name: 'Alice', age : 23 })".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.get_node("alice").unwrap().labels().collect::<Vec<_>>(), vec!["User"]);
//! assert!(g.get_node("alice").unwrap().property_value("name").is_some());
//! assert!(g.get_node("alice").unwrap().property_value("age").is_some());
//! ```
//!
//! Define an outgoing relationship:
//!
//! ```
//! let g = "(alice)-->()".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.relationship_count(), 1);
//! ```
//!
//! Define an incoming relationship:
//!
//! ```
//! let g = "(alice)<--()".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.relationship_count(), 1);
//! ```
//!
//! Define a relationship with type `KNOWS`, assign it to variable `r1` and add a property:
//!
//! ```
//! use std::rc::Rc;
//!
//! let g = "(alice)-[r1:KNOWS { since : 2014 }]->(bob)".parse::<gdl::Graph>().unwrap();
//!
//! assert!(g.get_relationship("r1").is_some());
//! assert_eq!(g.get_relationship("r1").unwrap().rel_type(), Some("KNOWS"));
//! ```
//!
//! 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)
//! ".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.node_count(), 3);
//! assert_eq!(g.relationship_count(), 2);
//! ```
//!
//! Define paths (four nodes and three relationships are created):
//!
//! ```
//! let g = "()-->()<--()-->()".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.node_count(), 4);
//! assert_eq!(g.relationship_count(), 3);
//! ```
//!
//! Paths can be comma separated to express arbitrary complex patterns:
//!
//! ```
//! let g = "
//! ()-->()<--()-->(),
//! ()<--()-->()-->(),
//! ()-->()<--()-->()
//! ".parse::<gdl::Graph>().unwrap();
//!
//! assert_eq!(g.node_count(), 12);
//! assert_eq!(g.relationship_count(), 9);
//! ```
//!
//! ## License
//!
//! Apache 2.0 or MIT
//!
#![allow(dead_code)]
pub mod graph;
pub mod parser;
pub use graph::Graph;
pub use graph::Node;
pub use graph::Relationship;
pub use parser::CypherValue;
#[cfg(doctest)]
mod tests {
doc_comment::doctest!("../README.md");
}