Skip to content

Commit

Permalink
Issue #1 WIP - Added W3C SPARQL 1.0 Query testing for the open-world …
Browse files Browse the repository at this point in the history
…set with two tests excluded per their exclusion in Oxigraph.
  • Loading branch information
donpellegrino committed Nov 6, 2023
1 parent c02b5a0 commit b8af5bd
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 71 deletions.
156 changes: 86 additions & 70 deletions oxhdt-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,23 @@ fn rdf_test_runner(query_path: &str, data_path: &str, result_path: &str) -> bool
let static_results = StaticQueryResults::from_query_results(results.unwrap(), false)
.expect("Failed to transorm the calculated results to a static result");

let results_match = are_query_results_isomorphic(&static_ref_results, &static_results);

// Debug failures by rerunning the query and printing out the
// results.
if !results_match {
let query2 = Query::parse(&rq, None).unwrap();
let (results_dbg, _explain) =
evaluate_hdt_query(Rc::clone(&data), query2, QueryOptions::default(), false)
.expect("Failed to evaluate SPARQL query");
if let QueryResults::Solutions(solutions) = results_dbg.unwrap() {
for row in solutions {
dbg!(&row);
}
}
}

// let query2 = Query::parse(&rq, None).unwrap();
// let (results_dbg, _explain) = evaluate_hdt_query(
// Rc::clone(&data),
// query2,
// QueryOptions::default(),
// false,
// )
// .expect("Failed to evaluate SPARQL query");
// if let QueryResults::Solutions(solutions) = results_dbg.unwrap() {
// for row in solutions {
// dbg!(&row);
// }
// }

return are_query_results_isomorphic(&static_ref_results, &static_results);
return results_match;
}

#[cfg(test)]
Expand Down Expand Up @@ -143,32 +142,16 @@ mod tests {
}
}

// Create W3C SPARQL 1.0 Basic test functions.
macro_rules! rdf_sparql10_basic_test {
($(($name:ident, $query:literal, $data:literal, $result:literal)),*) => {
// Create W3C SPARQL 1.0 test functions.
macro_rules! rdf_sparql10_test {
($(($group:literal, $name:ident, $query:literal, $data:literal, $result:literal)),*) => {
$(
#[test]
fn $name() {
assert!(rdf_test_runner(
concat!("../testsuite/rdf-tests/sparql/sparql10/basic/", $query),
concat!("tests/resources/rdf-tests/sparql/sparql10/basic/", $data),
concat!("https://w3c.github.io/rdf-tests/sparql/sparql10/basic/", $result)
));
}
)*
}
}

// Create W3C SPARQL 1.0 DAWG Triple Pattern test functions.
macro_rules! rdf_sparql10_triple_match_test {
($(($name:ident, $query:literal, $data:literal, $result:literal)),*) => {
$(
#[test]
fn $name() {
assert!(rdf_test_runner(
concat!("../testsuite/rdf-tests/sparql/sparql10/triple-match/", $query),
concat!("tests/resources/rdf-tests/sparql/sparql10/triple-match/", $data),
concat!("https://w3c.github.io/rdf-tests/sparql/sparql10/triple-match/", $result)
concat!("../testsuite/rdf-tests/sparql/sparql10/", $group, "/", $query),
concat!("tests/resources/rdf-tests/sparql/sparql10/", $group, "/", $data),
concat!("https://w3c.github.io/rdf-tests/sparql/sparql10/", $group, "/", $result)
));
}
)*
Expand All @@ -181,51 +164,84 @@ mod tests {
// changes in the upstream W3C SPARQL test suite since the list is
// hard-coded. Processing the manifest.ttl would enable
// synchronization with the upsteam suite.
rdf_sparql10_basic_test! {
(base_prefix_1, "base-prefix-1.rq", "data-1.hdt", "base-prefix-1.srx"),
(base_prefix_2, "base-prefix-2.rq", "data-1.hdt", "base-prefix-2.srx"),
(base_prefix_3, "base-prefix-3.rq", "data-1.hdt", "base-prefix-3.srx"),
(base_prefix_4, "base-prefix-4.rq", "data-1.hdt", "base-prefix-4.srx"),
(base_prefix_5, "base-prefix-5.rq", "data-1.hdt", "base-prefix-5.srx"),
rdf_sparql10_test! {
("basic", base_prefix_1, "base-prefix-1.rq", "data-1.hdt", "base-prefix-1.srx"),
("basic", base_prefix_2, "base-prefix-2.rq", "data-1.hdt", "base-prefix-2.srx"),
("basic", base_prefix_3, "base-prefix-3.rq", "data-1.hdt", "base-prefix-3.srx"),
("basic", base_prefix_4, "base-prefix-4.rq", "data-1.hdt", "base-prefix-4.srx"),
("basic", base_prefix_5, "base-prefix-5.rq", "data-1.hdt", "base-prefix-5.srx"),

(list_1, "list-1.rq", "data-2.hdt", "list-1.srx"),
(list_2, "list-2.rq", "data-2.hdt", "list-2.srx"),
(list_3, "list-3.rq", "data-2.hdt", "list-3.srx"),
(list_4, "list-4.rq", "data-2.hdt", "list-4.srx"),
("basic", list_1, "list-1.rq", "data-2.hdt", "list-1.srx"),
("basic", list_2, "list-2.rq", "data-2.hdt", "list-2.srx"),
("basic", list_3, "list-3.rq", "data-2.hdt", "list-3.srx"),
("basic", list_4, "list-4.rq", "data-2.hdt", "list-4.srx"),

(quotes_1, "quotes-1.rq", "data-3.hdt", "quotes-1.srx"),
(quotes_2, "quotes-2.rq", "data-3.hdt", "quotes-2.srx"),
("basic", quotes_1, "quotes-1.rq", "data-3.hdt", "quotes-1.srx"),
("basic", quotes_2, "quotes-2.rq", "data-3.hdt", "quotes-2.srx"),

// HDT Java (https://github.com/rdfhdt/hdt-java) creates the
// data-3.hdt from the data-3.ttl correctly. HDT C++ does not
// per https://github.com/rdfhdt/hdt-cpp/issues/219.
(quotes_3, "quotes-3.rq", "data-3.hdt", "quotes-3.srx"),
("basic", quotes_3, "quotes-3.rq", "data-3.hdt", "quotes-3.srx"),

("basic", quotes_4, "quotes-4.rq", "data-3.hdt", "quotes-4.srx"),

(quotes_4, "quotes-4.rq", "data-3.hdt", "quotes-4.srx"),
("basic", term_1, "term-1.rq", "data-4.hdt", "term-1.srx"),
("basic", term_2, "term-2.rq", "data-4.hdt", "term-2.srx"),
("basic", term_3, "term-3.rq", "data-4.hdt", "term-3.srx"),
("basic", term_4, "term-4.rq", "data-4.hdt", "term-4.srx"),
("basic", term_5, "term-5.rq", "data-4.hdt", "term-5.srx"),
("basic", term_6, "term-6.rq", "data-4.hdt", "term-6.srx"),
("basic", term_7, "term-7.rq", "data-4.hdt", "term-7.srx"),
("basic", term_8, "term-8.rq", "data-4.hdt", "term-8.srx"),
("basic", term_9, "term-9.rq", "data-4.hdt", "term-9.srx"),

(term_1, "term-1.rq", "data-4.hdt", "term-1.srx"),
(term_2, "term-2.rq", "data-4.hdt", "term-2.srx"),
(term_3, "term-3.rq", "data-4.hdt", "term-3.srx"),
(term_4, "term-4.rq", "data-4.hdt", "term-4.srx"),
(term_5, "term-5.rq", "data-4.hdt", "term-5.srx"),
(term_6, "term-6.rq", "data-4.hdt", "term-6.srx"),
(term_7, "term-7.rq", "data-4.hdt", "term-7.srx"),
(term_8, "term-8.rq", "data-4.hdt", "term-8.srx"),
(term_9, "term-9.rq", "data-4.hdt", "term-9.srx"),
("basic", var_1, "var-1.rq", "data-5.hdt", "var-1.srx"),
("basic", var_2, "var-2.rq", "data-5.hdt", "var-2.srx"),

(var_1, "var-1.rq", "data-5.hdt", "var-1.srx"),
(var_2, "var-2.rq", "data-5.hdt", "var-2.srx"),
("basic", bgp_no_match, "bgp-no-match.rq", "data-7.hdt", "bgp-no-match.srx"),
("basic", spoo_1, "spoo-1.rq", "data-6.hdt", "spoo-1.srx"),

(bgp_no_match, "bgp-no-match.rq", "data-7.hdt", "bgp-no-match.srx"),
(spoo_1, "spoo-1.rq", "data-6.hdt", "spoo-1.srx"),
("basic", prefix_name_1, "prefix-name-1.rq", "data-6.hdt", "prefix-name-1.srx")
}

(prefix_name_1, "prefix-name-1.rq", "data-6.hdt", "prefix-name-1.srx")
rdf_sparql10_test! {
("triple-match", dawg_triple_pattern_001, "dawg-tp-01.rq", "data-01.hdt", "result-tp-01.ttl"),
("triple-match", dawg_triple_pattern_002, "dawg-tp-02.rq", "data-01.hdt", "result-tp-02.ttl"),
("triple-match", dawg_triple_pattern_003, "dawg-tp-03.rq", "data-02.hdt", "result-tp-03.ttl"),
("triple-match", dawg_triple_pattern_004, "dawg-tp-04.rq", "dawg-data-01.hdt", "result-tp-04.ttl")
}

rdf_sparql10_triple_match_test! {
(dawg_triple_pattern_001, "dawg-tp-01.rq", "data-01.hdt", "result-tp-01.ttl"),
(dawg_triple_pattern_002, "dawg-tp-02.rq", "data-01.hdt", "result-tp-02.ttl"),
(dawg_triple_pattern_003, "dawg-tp-03.rq", "data-02.hdt", "result-tp-03.ttl"),
(dawg_triple_pattern_004, "dawg-tp-04.rq", "dawg-data-01.hdt", "result-tp-04.ttl")
rdf_sparql10_test! {
// Excluded with "Multiple writing of the same
// xsd:integer. Our system does strong normalization." per
// oxigraph/testsuite/tests/sparql.rs
// sparql10_w3c_query_evaluation_testsuite
// ("open-world", open_eq_01, "open-eq-01.rq", "data-1.hdt", "open-eq-01-result.srx"),

("open-world", open_eq_02, "open-eq-02.rq", "data-1.hdt", "open-eq-02-result.srx"),
("open-world", open_eq_03, "open-eq-03.rq", "data-1.hdt", "open-eq-03-result.srx"),
("open-world", open_eq_04, "open-eq-04.rq", "data-1.hdt", "open-eq-04-result.srx"),
("open-world", open_eq_05, "open-eq-05.rq", "data-1.hdt", "open-eq-05-result.srx"),
("open-world", open_eq_06, "open-eq-06.rq", "data-1.hdt", "open-eq-06-result.srx"),
("open-world", open_eq_07, "open-eq-07.rq", "data-2.hdt", "open-eq-07-result.srx"),
("open-world", open_eq_08, "open-eq-08.rq", "data-2.hdt", "open-eq-08-result.srx"),
("open-world", open_eq_09, "open-eq-09.rq", "data-2.hdt", "open-eq-09-result.srx"),
("open-world", open_eq_10, "open-eq-10.rq", "data-2.hdt", "open-eq-10-result.srx"),
("open-world", open_eq_11, "open-eq-11.rq", "data-2.hdt", "open-eq-11-result.srx"),
("open-world", open_eq_12, "open-eq-12.rq", "data-2.hdt", "open-eq-12-result.srx"),

("open-world", date_1, "date-1.rq", "data-3.hdt", "date-1-result.srx"),

// Excluded with "We use XSD 1.1 equality on dates." per
// oxigraph/testsuite/tests/sparql.rs
// sparql10_w3c_query_evaluation_testsuite
// (date_2, "date-2.rq", "data-3.hdt", "date-2-result.srx"),

("open-world", date_3, "date-3.rq", "data-3.hdt", "date-3-result.srx"),
("open-world", date_4, "date-4.rq", "data-3.hdt", "date-4-result.srx"),

("open-world", open_cmp_01, "open-cmp-01.rq", "data-4.hdt", "open-cmp-01-result.srx"),
("open-world", open_cmp_02, "open-cmp-02.rq", "data-4.hdt", "open-cmp-02-result.srx")
}
}
19 changes: 18 additions & 1 deletion oxhdt-sys/tests/resources/generate-hdt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,22 @@ function triple_match_hdt () {
done
}

function open_world_hdt () {
data=("data-1"
"data-2"
"data-3"
"data-4")

for data_file in "${data[@]}"
do
# Use the rdf2hdt.sh from the HDT Java implementation, presumed to be
# in the PATH.

rdf2hdt.sh ../../../testsuite/rdf-tests/sparql/sparql10/open-world/"$data_file".ttl \
rdf-tests/sparql/sparql10/open-world/"$data_file".hdt
done
}

# basic_data_hdt
triple_match_hdt
# triple_match_hdt
open_world_hdt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b8af5bd

Please sign in to comment.