Makes SPARQL 1.0 triple pattern tests pass

pull/10/head
Tpt 6 years ago
parent 7ed4252ad8
commit d69d9c526e
  1. 51
      src/store/sparql.rs
  2. 13
      tests/sparql_test_cases.rs

@ -165,6 +165,10 @@ impl<S: EncodedQuadsStore> SparqlEvaluator<S> {
let object =
self.binding_value_lookup_from_term_or_variable(&pattern.object, &mut variables)?;
let filter_sp = subject.is_var() && subject == predicate;
let filter_so = subject.is_var() && subject == object;
let filter_po = predicate.is_var() && predicate == object;
let store = self.store.clone();
let variables_len = variables.len();
Ok(EncodedBindingsIterator {
@ -178,15 +182,35 @@ impl<S: EncodedQuadsStore> SparqlEvaluator<S> {
object.get(&binding),
None, //TODO
) {
Ok(iter) => Box::new(iter.map(move |quad| {
let quad = quad?;
let mut binding = binding.clone();
binding.resize(variables_len, None);
subject.put(quad.subject, &mut binding);
predicate.put(quad.predicate, &mut binding);
object.put(quad.object, &mut binding);
Ok(binding)
})),
Ok(mut iter) => {
if filter_sp {
iter = Box::new(iter.filter(|quad| match quad {
Err(_) => true,
Ok(quad) => quad.subject == quad.predicate,
}))
}
if filter_so {
iter = Box::new(iter.filter(|quad| match quad {
Err(_) => true,
Ok(quad) => quad.subject == quad.object,
}))
}
if filter_po {
iter = Box::new(iter.filter(|quad| match quad {
Err(_) => true,
Ok(quad) => quad.predicate == quad.object,
}))
}
Box::new(iter.map(move |quad| {
let quad = quad?;
let mut binding = binding.clone();
binding.resize(variables_len, None);
subject.put(quad.subject, &mut binding);
predicate.put(quad.predicate, &mut binding);
object.put(quad.object, &mut binding);
Ok(binding)
}))
}
Err(error) => Box::new(once(Err(error))),
}
}
@ -288,7 +312,7 @@ impl<S: EncodedQuadsStore> SparqlEvaluator<S> {
}
}
#[derive(Clone, Copy)]
#[derive(PartialEq, Eq, Clone, Copy)]
enum BindingValueLookup {
Constant(EncodedTerm),
Variable(usize),
@ -312,4 +336,11 @@ impl BindingValueLookup {
BindingValueLookup::Variable(v) => binding[*v] = Some(value),
}
}
fn is_var(&self) -> bool {
match self {
BindingValueLookup::Constant(_) => false,
BindingValueLookup::Variable(_) => true,
}
}
}

@ -78,14 +78,19 @@ fn sparql_w3c_syntax_testsuite() {
#[test]
fn sparql_w3c_query_evaluation_testsuite() {
let manifest_10_url =
let manifest_10_urls = vec![
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/basic/manifest.ttl")
.unwrap();
.unwrap(),
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/triple-match/manifest.ttl")
.unwrap(),
];
let test_blacklist = vec![];
let client = RDFClient::default();
for test_result in TestManifest::new(&client, manifest_10_url) {
for test_result in manifest_10_urls
.into_iter()
.flat_map(|manifest| TestManifest::new(&client, manifest))
{
let test = test_result.unwrap();
if test_blacklist.contains(&test.id) {
continue;

Loading…
Cancel
Save