use oxirouter::{DataSource, OxiRouterError, Router};
fn main() -> Result<(), OxiRouterError> {
let mut router = Router::new();
router.add_source(
DataSource::new("dbpedia", "https://dbpedia.org/sparql")
.with_vocabulary("http://dbpedia.org/ontology/")
.with_region("EU"),
);
router.add_source(
DataSource::new("wikidata", "https://query.wikidata.org/sparql")
.with_vocabulary("http://www.wikidata.org/prop/direct/")
.with_vocabulary("http://www.wikidata.org/entity/")
.with_region("EU"),
);
router.add_source(
DataSource::new("schema-org", "https://schema.org/sparql")
.with_vocabulary("http://schema.org/")
.with_region("US"),
);
let sparql = r#"
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?person ?label WHERE {
?person a dbo:Person ;
rdfs:label ?label .
FILTER(LANG(?label) = "en")
}
ORDER BY ?label
LIMIT 25
"#;
println!("Routing SPARQL query with `route_sparql`...");
let ranking = router.route_sparql(sparql)?;
println!(
"Processing time: {}μs (ml_used={}, context_used={})",
ranking.processing_time_us, ranking.ml_used, ranking.context_used
);
if ranking.is_empty() {
println!("No sources matched the query.");
return Ok(());
}
println!("Ranked sources ({}):", ranking.len());
for (i, sel) in ranking.sources.iter().enumerate() {
println!(
" {}. {} — confidence={:.3} reason={:?}",
i + 1,
sel.source_id,
sel.confidence,
sel.reason
);
}
let query = oxirouter::Query::from_sparql(sparql)?;
println!("\nQuery details from `from_sparql`:");
println!(" type: {:?}", query.query_type);
println!(" projection_vars: {:?}", query.projection_vars);
println!(" predicates count: {}", query.predicates.len());
println!(" has_filter: {}", query.has_filter);
Ok(())
}