-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathprint_graph.rs
53 lines (47 loc) · 1.55 KB
/
print_graph.rs
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
use std::env;
use std::io;
use tdb_succinct::TdbDataType;
use terminus_store::*;
use tokio;
async fn print_graph(store_path: &str, graph: &str) -> io::Result<()> {
let store = open_directory_store(store_path);
let graph = store
.open(graph)
.await?
.expect(&format!("expected graph {} to exist", graph));
match graph.head().await? {
Some(layer) => {
for id_triple in layer.triples() {
// triples are retrieved in their id form. For printing,
// we need the string form. The conversion happens here.
let triple = layer
.id_triple_to_string(&id_triple)
.expect("expected id triple to be mapable to string");
println!(
"{}, {}, {} {:?}",
triple.subject,
triple.predicate,
match triple.object {
ObjectType::Node(_) => "node",
ObjectType::Value(_) => "value",
},
match triple.object {
ObjectType::Node(n) => String::make_entry(&n),
ObjectType::Value(v) => v,
}
);
}
}
None => {}
}
Ok(())
}
#[tokio::main]
async fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!("usage: {} <path> <graph_name>", args[0]);
} else {
print_graph(&args[1], &args[2]).await.unwrap();
}
}