Makes SPARQL 1.0 triple pattern tests pass

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

@ -165,6 +165,10 @@ impl<S: EncodedQuadsStore> SparqlEvaluator<S> {
let object = let object =
self.binding_value_lookup_from_term_or_variable(&pattern.object, &mut variables)?; 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 store = self.store.clone();
let variables_len = variables.len(); let variables_len = variables.len();
Ok(EncodedBindingsIterator { Ok(EncodedBindingsIterator {
@ -178,7 +182,26 @@ impl<S: EncodedQuadsStore> SparqlEvaluator<S> {
object.get(&binding), object.get(&binding),
None, //TODO None, //TODO
) { ) {
Ok(iter) => Box::new(iter.map(move |quad| { 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 quad = quad?;
let mut binding = binding.clone(); let mut binding = binding.clone();
binding.resize(variables_len, None); binding.resize(variables_len, None);
@ -186,7 +209,8 @@ impl<S: EncodedQuadsStore> SparqlEvaluator<S> {
predicate.put(quad.predicate, &mut binding); predicate.put(quad.predicate, &mut binding);
object.put(quad.object, &mut binding); object.put(quad.object, &mut binding);
Ok(binding) Ok(binding)
})), }))
}
Err(error) => Box::new(once(Err(error))), 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 { enum BindingValueLookup {
Constant(EncodedTerm), Constant(EncodedTerm),
Variable(usize), Variable(usize),
@ -312,4 +336,11 @@ impl BindingValueLookup {
BindingValueLookup::Variable(v) => binding[*v] = Some(value), 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] #[test]
fn sparql_w3c_query_evaluation_testsuite() { 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") 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 test_blacklist = vec![];
let client = RDFClient::default(); 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(); let test = test_result.unwrap();
if test_blacklist.contains(&test.id) { if test_blacklist.contains(&test.id) {
continue; continue;

Loading…
Cancel
Save