Makes RDF testsuites parsing more robust

pull/171/head
Tpt 4 years ago
parent b4080a7ce1
commit 80676b5149
  1. 5
      lib/src/model/graph.rs
  2. 63
      testsuite/src/manifest.rs
  3. 3
      testsuite/src/vocab.rs

@ -174,6 +174,11 @@ impl Graph {
self.graph_mut().remove(triple) self.graph_mut().remove(triple)
} }
/// Clears the graph
pub fn clear(&mut self) {
self.dataset.clear()
}
/// Loads a file into the graph. /// Loads a file into the graph.
/// ///
/// Usage example: /// Usage example:

@ -246,43 +246,50 @@ impl Iterator for TestManifest {
None => { None => {
match self.manifests_to_do.pop() { match self.manifests_to_do.pop() {
Some(url) => { Some(url) => {
let manifest = SubjectRef::from(NamedNodeRef::new(url.as_str()).unwrap()); self.graph.clear();
if let Err(error) = load_to_graph(&url, &mut self.graph) { if let Err(error) = load_to_graph(&url, &mut self.graph) {
return Some(Err(error)); return Some(Err(error));
} }
// New manifests for manifest in self
match self
.graph .graph
.object_for_subject_predicate(manifest, mf::INCLUDE) .subjects_for_predicate_object(rdf::TYPE, mf::MANIFEST)
{ {
Some(TermRef::BlankNode(list)) => { match self
self.manifests_to_do.extend( .graph
RdfListIterator::iter(&self.graph, list.into()).filter_map( .object_for_subject_predicate(manifest, mf::INCLUDE)
|m| match m { {
Term::NamedNode(nm) => Some(nm.into_string()), Some(TermRef::BlankNode(list)) => {
_ => None, self.manifests_to_do.extend(
}, RdfListIterator::iter(&self.graph, list.into()).filter_map(
), |m| match m {
); Term::NamedNode(nm) => Some(nm.into_string()),
_ => None,
},
),
);
}
Some(_) => return Some(Err(anyhow!("invalid tests list"))),
None => (),
} }
Some(_) => return Some(Err(anyhow!("invalid tests list"))),
None => (),
}
// New tests // New tests
match self match self
.graph .graph
.object_for_subject_predicate(manifest, mf::ENTRIES) .object_for_subject_predicate(manifest, mf::ENTRIES)
{ {
Some(TermRef::BlankNode(list)) => { Some(TermRef::BlankNode(list)) => {
self.tests_to_do self.tests_to_do
.extend(RdfListIterator::iter(&self.graph, list.into())); .extend(RdfListIterator::iter(&self.graph, list.into()));
} }
Some(term) => { Some(term) => {
return Some(Err(anyhow!("Invalid tests list. Got term {}", term))); return Some(Err(anyhow!(
"Invalid tests list. Got term {}",
term
)));
}
None => (),
} }
None => (),
} }
} }
None => return None, None => return None,

@ -34,6 +34,9 @@ pub mod mf {
pub const ENTRIES: NamedNodeRef<'_> = NamedNodeRef::new_unchecked( pub const ENTRIES: NamedNodeRef<'_> = NamedNodeRef::new_unchecked(
"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries", "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#entries",
); );
pub const MANIFEST: NamedNodeRef<'_> = NamedNodeRef::new_unchecked(
"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#Manifest",
);
pub const NAME: NamedNodeRef<'_> = NamedNodeRef::new_unchecked( pub const NAME: NamedNodeRef<'_> = NamedNodeRef::new_unchecked(
"http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name", "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#name",
); );

Loading…
Cancel
Save