forked from oxigraph/oxigraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #1 WIP Added oxhdt-sys crate with unit tests.
- Loading branch information
1 parent
2d6fd6f
commit 9c2f831
Showing
6 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
name = "hdt_driver" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Don Pellegrino <[email protected]>"] | ||
description = """ | ||
Rust test driver for Oxigraph HDT calls. | ||
""" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "oxhdt-sys" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Don Pellegrino <[email protected]>"] | ||
description = """ | ||
Rust bindings for HDT for Oxigraph usage. | ||
""" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
oxigraph = { path = "../lib/oxigraph" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#[allow(unused_imports)] | ||
use oxigraph::model::{NamedNode, Literal}; | ||
use oxigraph::sparql::EvaluationError; | ||
use oxigraph::sparql::QueryOptions; | ||
use oxigraph::sparql::QueryResults; | ||
use oxigraph::sparql::dataset::HDTDatasetView; | ||
use oxigraph::sparql::evaluate_hdt_query; | ||
use std::rc::Rc; | ||
|
||
#[allow(dead_code)] | ||
fn hdt_query(hdt_path: &str, sparql_query: &str) -> Result<QueryResults, EvaluationError> { | ||
// Open the HDT file. | ||
let dataset = Rc::new(HDTDatasetView::new(hdt_path)); | ||
let sparql_query = sparql_query; | ||
|
||
// SPARQL query | ||
let (results, _explain) = evaluate_hdt_query( | ||
Rc::clone(&dataset), | ||
sparql_query, | ||
QueryOptions::default(), | ||
false, | ||
) | ||
.expect("failed to evaluate SPARQL query"); | ||
|
||
return results; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn hdt_sparql_select_o_literal_by_s_uri() { | ||
let ex = Literal::new_simple_literal("SPARQL Tutorial"); | ||
|
||
if let QueryResults::Solutions(mut solutions) = hdt_query( | ||
"/home/u133615/projects/oxigraph/hdt_driver/test.hdt", | ||
"SELECT ?o WHERE { <http://example.org/book/book1> ?p ?o }" | ||
).unwrap() { | ||
assert_eq!(solutions.next().unwrap().unwrap().get("o"), Some(&ex.into())); | ||
} | ||
} | ||
|
||
#[test] | ||
fn hdt_sparql_select_s_uri_by_p_uri() { | ||
let ex = NamedNode::new("http://example.org/book/book1").unwrap(); | ||
|
||
if let QueryResults::Solutions(mut solutions) = hdt_query( | ||
"/home/u133615/projects/oxigraph/hdt_driver/test.hdt", | ||
"SELECT ?s WHERE { ?s <http://purl.org/dc/elements/1.1/title> ?o }" | ||
).unwrap() { | ||
assert_eq!(solutions.next().unwrap().unwrap().get("s"), Some(&ex.into())); | ||
} | ||
} | ||
|
||
#[test] | ||
fn hdt_sparql_select_spo_by_s_uri_and_o_literal() { | ||
let ex_s = NamedNode::new("http://example.org/book/book1").unwrap(); | ||
let ex_p = NamedNode::new("http://purl.org/dc/elements/1.1/title").unwrap(); | ||
let ex_o = Literal::new_simple_literal("SPARQL Tutorial"); | ||
|
||
if let QueryResults::Solutions(mut solutions) = hdt_query( | ||
"/home/u133615/projects/oxigraph/hdt_driver/test.hdt", | ||
"SELECT ?s ?p ?o WHERE { <http://example.org/book/book1> ?p ?o . ?s ?p \"SPARQL Tutorial\" }" | ||
).unwrap() { | ||
let row = solutions.next().unwrap().unwrap(); | ||
assert_eq!(row.get("s"), Some(&ex_s.into())); | ||
assert_eq!(row.get("p"), Some(&ex_p.into())); | ||
assert_eq!(row.get("o"), Some(&ex_o.into())); | ||
} | ||
} | ||
} |