forked from chrishayuk/larql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_cmd.rs
More file actions
35 lines (27 loc) · 787 Bytes
/
Copy pathquery_cmd.rs
File metadata and controls
35 lines (27 loc) · 787 Bytes
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
use std::path::PathBuf;
use clap::Args;
#[derive(Args)]
pub struct QueryArgs {
/// Path to graph file (.larql.json or .larql.bin).
#[arg(short, long)]
graph: PathBuf,
/// Entity to query.
subject: String,
/// Relation to filter (optional).
relation: Option<String>,
}
pub fn run(args: QueryArgs) -> Result<(), Box<dyn std::error::Error>> {
let graph = larql_core::load(&args.graph)?;
let edges = graph.select(&args.subject, args.relation.as_deref());
if edges.is_empty() {
println!("No results for '{}'", args.subject);
return Ok(());
}
for edge in edges {
println!(
" {} --{}--> {} ({:.2})",
edge.subject, edge.relation, edge.object, edge.confidence
);
}
Ok(())
}