|
|
@ -8,13 +8,12 @@ extern crate url; |
|
|
|
|
|
|
|
|
|
|
|
use reqwest::Client; |
|
|
|
use reqwest::Client; |
|
|
|
use reqwest::Response; |
|
|
|
use reqwest::Response; |
|
|
|
|
|
|
|
use rudf::errors::*; |
|
|
|
use rudf::model::vocab::rdf; |
|
|
|
use rudf::model::vocab::rdf; |
|
|
|
use rudf::model::vocab::rdfs; |
|
|
|
use rudf::model::vocab::rdfs; |
|
|
|
use rudf::model::*; |
|
|
|
use rudf::model::*; |
|
|
|
use rudf::rio::ntriples::read_ntriples; |
|
|
|
use rudf::rio::ntriples::read_ntriples; |
|
|
|
use rudf::rio::turtle::read_turtle; |
|
|
|
use rudf::rio::turtle::read_turtle; |
|
|
|
use rudf::rio::RioError; |
|
|
|
|
|
|
|
use rudf::rio::RioResult; |
|
|
|
|
|
|
|
use rudf::sparql::algebra::Query; |
|
|
|
use rudf::sparql::algebra::Query; |
|
|
|
use rudf::sparql::parser::read_sparql_query; |
|
|
|
use rudf::sparql::parser::read_sparql_query; |
|
|
|
use rudf::store::isomorphism::GraphIsomorphism; |
|
|
|
use rudf::store::isomorphism::GraphIsomorphism; |
|
|
@ -178,25 +177,25 @@ impl Default for RDFClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl RDFClient { |
|
|
|
impl RDFClient { |
|
|
|
pub fn load_turtle(&self, url: Url) -> RioResult<MemoryGraph> { |
|
|
|
pub fn load_turtle(&self, url: Url) -> Result<MemoryGraph> { |
|
|
|
Ok(read_turtle(self.get(&url)?, Some(url))?.collect()) |
|
|
|
Ok(read_turtle(self.get(&url)?, Some(url))?.collect()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn load_ntriples(&self, url: Url) -> RioResult<MemoryGraph> { |
|
|
|
pub fn load_ntriples(&self, url: Url) -> Result<MemoryGraph> { |
|
|
|
read_ntriples(self.get(&url)?).collect() |
|
|
|
read_ntriples(self.get(&url)?).collect() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn load_sparql_query(&self, url: Url) -> RioResult<Query> { |
|
|
|
pub fn load_sparql_query(&self, url: Url) -> Result<Query> { |
|
|
|
read_sparql_query(self.get(&url)?, Some(url)) |
|
|
|
read_sparql_query(self.get(&url)?, Some(url)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get(&self, url: &Url) -> RioResult<Response> { |
|
|
|
fn get(&self, url: &Url) -> Result<Response> { |
|
|
|
match self.client.get(url.clone()).send() { |
|
|
|
match self.client.get(url.clone()).send() { |
|
|
|
Ok(response) => Ok(response), |
|
|
|
Ok(response) => Ok(response), |
|
|
|
Err(error) => if error.description() == "message is incomplete" { |
|
|
|
Err(error) => if error.description() == "message is incomplete" { |
|
|
|
self.get(url) |
|
|
|
self.get(url) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Err(RioError::new(error)) |
|
|
|
Err("HTTP request error".into()) //TODO: improve
|
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -267,9 +266,9 @@ pub mod mf { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<'a> Iterator for TestManifest<'a> { |
|
|
|
impl<'a> Iterator for TestManifest<'a> { |
|
|
|
type Item = Result<Test, ManifestError>; |
|
|
|
type Item = Result<Test>; |
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<Test, ManifestError>> { |
|
|
|
fn next(&mut self) -> Option<Result<Test>> { |
|
|
|
match self.tests_to_do.pop() { |
|
|
|
match self.tests_to_do.pop() { |
|
|
|
Some(Term::NamedNode(test_node)) => { |
|
|
|
Some(Term::NamedNode(test_node)) => { |
|
|
|
let test_subject = NamedOrBlankNode::from(test_node.clone()); |
|
|
|
let test_subject = NamedOrBlankNode::from(test_node.clone()); |
|
|
@ -278,9 +277,9 @@ impl<'a> Iterator for TestManifest<'a> { |
|
|
|
{ |
|
|
|
{ |
|
|
|
Some(Term::NamedNode(c)) => match c.value().split("#").last() { |
|
|
|
Some(Term::NamedNode(c)) => match c.value().split("#").last() { |
|
|
|
Some(k) => k.to_string(), |
|
|
|
Some(k) => k.to_string(), |
|
|
|
None => return Some(Err(ManifestError::NoType)), |
|
|
|
None => return Some(Err("no type".into())), |
|
|
|
}, |
|
|
|
}, |
|
|
|
_ => return Some(Err(ManifestError::NoType)), |
|
|
|
_ => return Some(Err("no type".into())), |
|
|
|
}; |
|
|
|
}; |
|
|
|
let name = match self.graph |
|
|
|
let name = match self.graph |
|
|
|
.object_for_subject_predicate(&test_subject, &mf::NAME) |
|
|
|
.object_for_subject_predicate(&test_subject, &mf::NAME) |
|
|
@ -298,14 +297,14 @@ impl<'a> Iterator for TestManifest<'a> { |
|
|
|
.object_for_subject_predicate(&test_subject, &*mf::ACTION) |
|
|
|
.object_for_subject_predicate(&test_subject, &*mf::ACTION) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Some(Term::NamedNode(n)) => n.url().clone(), |
|
|
|
Some(Term::NamedNode(n)) => n.url().clone(), |
|
|
|
Some(_) => return Some(Err(ManifestError::InvalidAction)), |
|
|
|
Some(_) => return Some(Err("invalid action".into())), |
|
|
|
None => return Some(Err(ManifestError::ActionNotFound)), |
|
|
|
None => return Some(Err("action not found".into())), |
|
|
|
}; |
|
|
|
}; |
|
|
|
let result = match self.graph |
|
|
|
let result = match self.graph |
|
|
|
.object_for_subject_predicate(&test_subject, &*mf::RESULT) |
|
|
|
.object_for_subject_predicate(&test_subject, &*mf::RESULT) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Some(Term::NamedNode(n)) => Some(n.url().clone()), |
|
|
|
Some(Term::NamedNode(n)) => Some(n.url().clone()), |
|
|
|
Some(_) => return Some(Err(ManifestError::InvalidResult)), |
|
|
|
Some(_) => return Some(Err("invalid result".into())), |
|
|
|
None => None, |
|
|
|
None => None, |
|
|
|
}; |
|
|
|
}; |
|
|
|
Some(Ok(Test { |
|
|
|
Some(Ok(Test { |
|
|
@ -317,7 +316,7 @@ impl<'a> Iterator for TestManifest<'a> { |
|
|
|
result, |
|
|
|
result, |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
Some(_) => Some(Err(ManifestError::InvalidTestsList)), |
|
|
|
Some(_) => Some(Err("invalid test list".into())), |
|
|
|
None => { |
|
|
|
None => { |
|
|
|
match self.manifests_to_do.pop() { |
|
|
|
match self.manifests_to_do.pop() { |
|
|
|
Some(url) => { |
|
|
|
Some(url) => { |
|
|
@ -341,7 +340,7 @@ impl<'a> Iterator for TestManifest<'a> { |
|
|
|
}), |
|
|
|
}), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
Some(_) => return Some(Err(ManifestError::InvalidTestsList)), |
|
|
|
Some(_) => return Some(Err("invalid tests list".into())), |
|
|
|
None => (), |
|
|
|
None => (), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -353,7 +352,7 @@ impl<'a> Iterator for TestManifest<'a> { |
|
|
|
self.tests_to_do |
|
|
|
self.tests_to_do |
|
|
|
.extend(self.graph.values_for_list(list.clone().into())); |
|
|
|
.extend(self.graph.values_for_list(list.clone().into())); |
|
|
|
} |
|
|
|
} |
|
|
|
Some(_) => return Some(Err(ManifestError::InvalidTestsList)), |
|
|
|
Some(_) => return Some(Err("invalid tests list".into())), |
|
|
|
None => (), |
|
|
|
None => (), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -364,45 +363,3 @@ impl<'a> Iterator for TestManifest<'a> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
|
|
|
|
pub enum ManifestError { |
|
|
|
|
|
|
|
NoType, |
|
|
|
|
|
|
|
ActionNotFound, |
|
|
|
|
|
|
|
InvalidAction, |
|
|
|
|
|
|
|
InvalidResult, |
|
|
|
|
|
|
|
InvalidTestsList, |
|
|
|
|
|
|
|
RioError(RioError), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Error for ManifestError { |
|
|
|
|
|
|
|
fn description(&self) -> &str { |
|
|
|
|
|
|
|
match self { |
|
|
|
|
|
|
|
ManifestError::NoType => "no type found on the test case", |
|
|
|
|
|
|
|
ManifestError::ActionNotFound => "action not found", |
|
|
|
|
|
|
|
ManifestError::InvalidAction => "invalid action", |
|
|
|
|
|
|
|
ManifestError::InvalidResult => "invalid result", |
|
|
|
|
|
|
|
ManifestError::InvalidTestsList => "invalid tests list", |
|
|
|
|
|
|
|
ManifestError::RioError(e) => e.description(), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn cause(&self) -> Option<&Error> { |
|
|
|
|
|
|
|
match self { |
|
|
|
|
|
|
|
ManifestError::RioError(e) => Some(e), |
|
|
|
|
|
|
|
_ => None, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for ManifestError { |
|
|
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
|
|
|
|
write!(f, "{}", self.description()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<RioError> for ManifestError { |
|
|
|
|
|
|
|
fn from(e: RioError) -> Self { |
|
|
|
|
|
|
|
ManifestError::RioError(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|