pub use super::framework::*;
pub const EX: &str = "http://example.org/";
pub const FOAF: &str = "http://xmlns.com/foaf/0.1/";
pub const RDF: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
pub const RDFS: &str = "http://www.w3.org/2000/01/rdf-schema#";
pub const OWL: &str = "http://www.w3.org/2002/07/owl#";
pub const XSD: &str = "http://www.w3.org/2001/XMLSchema#";
pub fn ex(local: &str) -> Term {
iri(&format!("{EX}{local}"))
}
pub fn foaf(local: &str) -> Term {
iri(&format!("{FOAF}{local}"))
}
pub fn rdf_type() -> Term {
iri(&format!("{RDF}type"))
}
pub fn rdfs(local: &str) -> Term {
iri(&format!("{RDFS}{local}"))
}
pub fn dataset_from_triples(triples: Vec<(Term, Term, Term)>) -> InMemoryDataset {
let mut ds = InMemoryDataset::new();
for (s, p, o) in triples {
ds.add_triple(s, p, o);
}
ds
}
pub fn person_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("alice"), foaf("name"), str_lit("Alice")),
(ex("alice"), iri(&format!("{FOAF}age")), int_lit(30)),
(ex("alice"), rdf_type(), iri(&format!("{FOAF}Person"))),
(ex("bob"), foaf("name"), str_lit("Bob")),
(ex("bob"), iri(&format!("{FOAF}age")), int_lit(25)),
(ex("bob"), rdf_type(), iri(&format!("{FOAF}Person"))),
(ex("charlie"), foaf("name"), str_lit("Charlie")),
(ex("charlie"), iri(&format!("{FOAF}age")), int_lit(35)),
(ex("charlie"), rdf_type(), iri(&format!("{FOAF}Person"))),
])
}
pub fn numeric_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("s1"), ex("value"), int_lit(10)),
(ex("s2"), ex("value"), int_lit(20)),
(ex("s3"), ex("value"), int_lit(30)),
(ex("s4"), ex("value"), int_lit(15)),
(ex("s5"), ex("value"), int_lit(25)),
])
}
pub fn hierarchy_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("a"), ex("child"), ex("b")),
(ex("b"), ex("child"), ex("c")),
(ex("c"), ex("child"), ex("d")),
(ex("d"), ex("child"), ex("e")),
(ex("a"), ex("knows"), ex("b")),
(ex("b"), ex("knows"), ex("c")),
])
}
pub fn optional_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("alice"), foaf("name"), str_lit("Alice")),
(ex("alice"), foaf("mbox"), str_lit("alice@example.org")),
(ex("bob"), foaf("name"), str_lit("Bob")),
(ex("charlie"), foaf("name"), str_lit("Charlie")),
(ex("charlie"), foaf("mbox"), str_lit("charlie@example.org")),
])
}
pub fn union_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("alice"), rdf_type(), iri(&format!("{FOAF}Person"))),
(ex("alice"), foaf("name"), str_lit("Alice")),
(ex("acme"), rdf_type(), ex("Organization")),
(ex("acme"), ex("orgName"), str_lit("ACME Corp")),
(ex("bob"), rdf_type(), iri(&format!("{FOAF}Person"))),
(ex("bob"), foaf("name"), str_lit("Bob")),
])
}
pub fn negation_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("alice"), foaf("name"), str_lit("Alice")),
(ex("alice"), foaf("mbox"), str_lit("alice@example")),
(ex("bob"), foaf("name"), str_lit("Bob")),
(ex("charlie"), foaf("name"), str_lit("Charlie")),
(ex("charlie"), foaf("mbox"), str_lit("charlie@example")),
(ex("dave"), foaf("name"), str_lit("Dave")),
])
}
pub fn group_by_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("item1"), ex("category"), ex("A")),
(ex("item1"), ex("price"), int_lit(10)),
(ex("item2"), ex("category"), ex("A")),
(ex("item2"), ex("price"), int_lit(20)),
(ex("item3"), ex("category"), ex("B")),
(ex("item3"), ex("price"), int_lit(15)),
(ex("item4"), ex("category"), ex("B")),
(ex("item4"), ex("price"), int_lit(25)),
(ex("item5"), ex("category"), ex("A")),
(ex("item5"), ex("price"), int_lit(30)),
])
}
pub fn string_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("r1"), ex("label"), str_lit("Hello World")),
(ex("r2"), ex("label"), str_lit("SPARQL Query")),
(ex("r3"), ex("label"), str_lit("Semantic Web")),
(ex("r4"), ex("label"), str_lit("RDF Graph")),
(ex("r1"), ex("code"), str_lit("ABC123")),
(ex("r2"), ex("code"), str_lit("XYZ789")),
])
}
pub fn subquery_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("alice"), ex("score"), int_lit(85)),
(ex("bob"), ex("score"), int_lit(92)),
(ex("charlie"), ex("score"), int_lit(78)),
(ex("dave"), ex("score"), int_lit(92)),
(ex("alice"), foaf("name"), str_lit("Alice")),
(ex("bob"), foaf("name"), str_lit("Bob")),
(ex("charlie"), foaf("name"), str_lit("Charlie")),
(ex("dave"), foaf("name"), str_lit("Dave")),
])
}
pub fn values_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("a"), ex("value"), int_lit(1)),
(ex("b"), ex("value"), int_lit(2)),
(ex("c"), ex("value"), int_lit(3)),
(ex("d"), ex("value"), int_lit(4)),
(ex("e"), ex("value"), int_lit(5)),
(ex("a"), foaf("name"), str_lit("Resource A")),
(ex("b"), foaf("name"), str_lit("Resource B")),
(ex("c"), foaf("name"), str_lit("Resource C")),
])
}
pub fn typed_dataset() -> InMemoryDataset {
dataset_from_triples(vec![
(ex("r1"), ex("intVal"), int_lit(42)),
(ex("r1"), ex("strVal"), str_lit("hello")),
(
ex("r1"),
ex("boolVal"),
Term::Literal(Literal {
value: "true".to_string(),
language: None,
datatype: Some(NamedNode::new_unchecked(
"http://www.w3.org/2001/XMLSchema#boolean",
)),
}),
),
(
ex("r1"),
ex("decVal"),
Term::Literal(Literal {
value: "3.14".to_string(),
language: None,
datatype: Some(NamedNode::new_unchecked(
"http://www.w3.org/2001/XMLSchema#decimal",
)),
}),
),
(
ex("r2"),
ex("intVal"),
Term::Literal(Literal {
value: "-7".to_string(),
language: None,
datatype: Some(NamedNode::new_unchecked(
"http://www.w3.org/2001/XMLSchema#integer",
)),
}),
),
])
}