Skip to content
Snippets Groups Projects
Commit d383cc79 authored by Fabien Givors's avatar Fabien Givors
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
/target
[package]
name = "oxibug"
version = "0.1.0"
edition = "2024"
[dependencies]
oxigraph = "0.4.8"
reqwest = { version="0.12.12", features=["blocking"] }
use oxigraph::store::Store;
fn download_shacl() -> Vec<u8> {
use reqwest::blocking::Client;
let client = Client::new();
let shacl_url = "https://www.w3.org/ns/shacl.ttl";
client.get(shacl_url).send().expect("failed to download file").bytes().expect("failed to build bytes").to_vec()
}
fn load_turtle(store: &mut Store, bytes: &[u8]) {
use oxigraph::io::{RdfFormat, RdfParser};
use oxigraph::model::{GraphNameRef, NamedNodeRef};
let shacl_ns = "http://www.w3.org/ns/shacl";
let graph_iri = GraphNameRef::NamedNode(NamedNodeRef::new_unchecked(shacl_ns));
store
.bulk_loader()
.load_from_reader(
RdfParser::from_format(RdfFormat::Turtle)
.without_named_graphs()
.with_default_graph(graph_iri),
bytes,
)
.expect("unable to load data")
}
fn perform_query_1(store: &Store) {
use oxigraph::sparql::QueryResults;
let query_str = "
SELECT DISTINCT
?node
?label
?inverse_label
?type
WHERE {
GRAPH <http://www.w3.org/ns/shacl> {
?node ?p ?o .
}
GRAPH <http://www.w3.org/ns/shacl> {
#OPTIONAL { ?node <http://www.w3.org/2000/01/rdf-schema#label> ?label . } .
OPTIONAL { ?node <http://example.com/ns#inverseLabel> ?inverse_label . } .
} .
GRAPH <http://www.w3.org/ns/shacl> {
OPTIONAL { ?node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type . } .
}
FILTER(?node = <http://www.w3.org/ns/shacl#ClosedConstraintComponent-closed>)
}
";
if let QueryResults::Solutions(solutions) = store.query(query_str).expect("invalid query") {
println!("Query 1: {}", solutions.count());
}
}
fn perform_query_2(store: &Store) {
use oxigraph::sparql::QueryResults;
let query_str = "
SELECT DISTINCT
?node
?label
?inverse_label
?type
WHERE {
GRAPH <http://www.w3.org/ns/shacl> {
?node ?p ?o .
}
GRAPH <http://www.w3.org/ns/shacl> {
OPTIONAL { ?node <http://www.w3.org/2000/01/rdf-schema#label> ?label . } .
OPTIONAL { ?node <http://example.com/ns#inverseLabel> ?inverse_label . } .
} .
GRAPH <http://www.w3.org/ns/shacl> {
OPTIONAL { ?node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type . } .
}
FILTER(?node = <http://www.w3.org/ns/shacl#ClosedConstraintComponent-closed>)
}
";
if let QueryResults::Solutions(solutions) = store.query(query_str).expect("invalid query") {
println!("Query 2: {}", solutions.count());
}
}
fn main() {
let mut store = Store::new().expect("failed to create new store");
let shacl_bytes = download_shacl();
load_turtle(&mut store, &shacl_bytes);
perform_query_1(&store);
perform_query_2(&store);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment