An embedded and in-memory knowledge graph for static specification analysis.
The Cairn Knowledge Graph implements a directed graph. Each vertex holds a value. A vertex' value can be selected using a unique string, or an index value.
A vertex can hold a value of the following types: - unit, indicating the absence of a value - string, containing Unicode Scalar Values, - boolean, - integer - unsigned integer - floating point, (IEEE 754-2008)
Cairn Knowledge Graph does currently not guarantee ACID database transaction properties.
The graph resides in-memory and does currently not exist in persistent storage.
Applications can include the cairnknowledgegraph crate as a dependency. Building cairnknowledgegraph requires that an ANSI C11 compatible C-compiler and CMake are installed.
```rust use cairnknowledgegraph::error::GraphComputingError; use cairnknowledgegraph::graph::edge::DirectedEdgeDefinedByKeys; use cairnknowledgegraph::graph::graph::Graph; use cairnknowledgegraph::graph::vertex::{Vertex, VertexValue}; use cairnknowledgegraph::operations::addedge::AddEdge; use cairnknowledgegraph::operations::addvertex::AddVertex; use cairnknowledgegraph::operations::selection::operators::and::AndOperator; use cairnknowledgegraph::operations::selectvertex::SelectVertex; use cairnknowledgegraph::operations::selection::vertexselection::VertexSelection;
macrorules! addnewedge { ($fromvertex:ident, $edgetype:ident, $tovertex:ident, $graph:ident) => { let edge = DirectedEdgeDefinedByKeys::new( $fromvertex.clone().into(), $edgetype.clone(), $tovertex.clone().into(), ); $graph.addedgeandedgetypeusing_keys(edge.clone()).unwrap(); }; }
fn main() { let initialvertexcapacity = 10; let initialedgetypecapacity = 10; let mut graph = Graph::new(initialvertexcapacity, initialedgetypecapacity).unwrap();
let zero = Vertex::new(String::from("0"), 0u8.into());
graph.add_or_replace_vertex(zero.clone()).unwrap();
let one = Vertex::new(String::from("1"), 1u8.into());
graph.add_or_replace_vertex(one.clone()).unwrap();
let one_dot_one = Vertex::new(String::from("1.1"), 1.1f32.into());
graph.add_or_replace_vertex(one_dot_one.clone()).unwrap();
let negative_one = Vertex::new(String::from("-1"), (-1i8).into());
graph.add_or_replace_vertex(negative_one.clone()).unwrap();
let negative_one_dot_one = Vertex::new(String::from("-1.1"), (-1.1f32).into());
graph
.add_or_replace_vertex(negative_one_dot_one.clone())
.unwrap();
let integer = Vertex::new(String::from("integer"), String::from("integer").into());
graph.add_or_replace_vertex(integer.clone()).unwrap();
let real_number = Vertex::new(
String::from("real_number"),
String::from("real_number").into(),
);
graph.add_or_replace_vertex(real_number.clone()).unwrap();
let positive = Vertex::new(String::from("positive"), String::from("positive").into());
graph.add_or_replace_vertex(positive.clone()).unwrap();
let negative = Vertex::new(String::from("negative"), String::from("negative").into());
graph.add_or_replace_vertex(negative.clone()).unwrap();
let sign = String::from("sign");
let is_a = String::from("is_a");
add_new_edge!(negative_one_dot_one, is_a, real_number, graph);
add_new_edge!(negative_one_dot_one, sign, negative, graph);
add_new_edge!(negative_one, is_a, real_number, graph);
add_new_edge!(negative_one, is_a, integer, graph);
add_new_edge!(negative_one, sign, negative, graph);
add_new_edge!(zero, is_a, real_number, graph);
add_new_edge!(zero, is_a, integer, graph);
add_new_edge!(one, is_a, real_number, graph);
add_new_edge!(one, is_a, integer, graph);
add_new_edge!(one, sign, positive, graph);
add_new_edge!(one_dot_one, is_a, real_number, graph);
add_new_edge!(one_dot_one, sign, positive, graph);
let negative_selection = graph
.select_vertices_connected_to_vertex_by_key(sign, &"negative")
.unwrap();
let integer_selection = graph
.select_vertices_connected_to_vertex_by_key(is_a, &"integer")
.unwrap();
let negative_integer_selection = negative_selection.and(&integer_selection).unwrap();
let negative_integers = negative_integer_selection.vertex_values_ref().unwrap();
assert_eq!(negative_integers.len(), 1);
assert_eq!(negative_integers, vec!(&VertexValue::Integer8Bit(-1)));
} ```
Cairn Knowledge Graph is inspired by LAGraph and uses the same underlying GraphBLAS implementation from Timothy A. Davis.
cairnknowledgegraph is licensed under Creative Commons Attribution Non Commercial 4.0 International. For other licensing options, please contact Sam Dekker.
Awesome, contributions are welcome. cairnknowledgegraph and your contribution may be relicensed and integrated into commercial software in the future. Therefore, you will be asked to agree to the Contributor License Agreement when you make a pull request.