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)
}
/// Clears the graph
pub fn clear(&mut self) {
self.dataset.clear()
}
/// Loads a file into the graph.
///
/// Usage example:

@ -246,43 +246,50 @@ impl Iterator for TestManifest {
None => {
match self.manifests_to_do.pop() {
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) {
return Some(Err(error));
}
// New manifests
match self
for manifest in self
.graph
.object_for_subject_predicate(manifest, mf::INCLUDE)
.subjects_for_predicate_object(rdf::TYPE, mf::MANIFEST)
{
Some(TermRef::BlankNode(list)) => {
self.manifests_to_do.extend(
RdfListIterator::iter(&self.graph, list.into()).filter_map(
|m| match m {
Term::NamedNode(nm) => Some(nm.into_string()),
_ => None,
},
),
);
match self
.graph
.object_for_subject_predicate(manifest, mf::INCLUDE)
{
Some(TermRef::BlankNode(list)) => {
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
match self
.graph
.object_for_subject_predicate(manifest, mf::ENTRIES)
{
Some(TermRef::BlankNode(list)) => {
self.tests_to_do
.extend(RdfListIterator::iter(&self.graph, list.into()));
}
Some(term) => {
return Some(Err(anyhow!("Invalid tests list. Got term {}", term)));
// New tests
match self
.graph
.object_for_subject_predicate(manifest, mf::ENTRIES)
{
Some(TermRef::BlankNode(list)) => {
self.tests_to_do
.extend(RdfListIterator::iter(&self.graph, list.into()));
}
Some(term) => {
return Some(Err(anyhow!(
"Invalid tests list. Got term {}",
term
)));
}
None => (),
}
None => (),
}
}
None => return None,

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

Loading…
Cancel
Save