SPARQL queries
Run SPARQL queries on the loaded data or on an endpoint.
Run queries
#![allow(unused)]
fn main() {
use rudof_lib::{Rudof, RudofConfig};
use rudof_lib::formats::{
InputSpec, DataFormat, ResultQueryFormat, QueryType
};
use std::str::FromStr;
let mut rudof = Rudof::new(RudofConfig::default());
let data_input = InputSpec::from_str(r#"
prefix : <http://example.org/>
prefix schema: <http://schema.org/>
:a schema:name "Alice" ;
:status :Active ;
schema:knows :a, :b .
:b schema:name "Bob" ;
:status :Waiting ;
schema:knows :c .
:c schema:name "Carol" .
:d schema:name 23 . # Should fail
:e schema:name "Emily" ; # Should fail
schema:knows :d .
"#).unwrap();
// Load RDF data
rudof.load_data()
.with_data(&[data_input])
.with_data_format(&DataFormat::Turtle)
.execute()
.unwrap();
let query_input = InputSpec::from_str(
r#"
prefix : <http://example.org/>
prefix schema: <http://schema.org/>
select ?person ?name ?status where {
?person schema:name ?name ;
:status ?status .
}
"#,
)
.unwrap();
// Load query into Rudof's state (this is what the `sparql` command uses)
rudof.load_sparql_query(&query_input)
.with_query_type(&QueryType::Select)
.execute()
.unwrap();
// Serialize the query to standard output (this is what the `sparql` command uses)
rudof.serialize_sparql_query(&mut std::io::stdout()).execute().unwrap();
// Run the query (this is what the `query` command uses)
rudof.run_query().execute();
// Serialize the query results to standard output
rudof.serialize_query_results(&mut std::io::stdout())
.with_result_query_format(&ResultQueryFormat::Csv)
.execute()
.unwrap();
// Reset query state (just the loaded query)
rudof.reset_sparql_query().execute();
// Reset query execution state (query and query results)
rudof.reset_query_results().execute();
}