Fixes SPARQL-star tests evaluation

pull/171/head
Tpt 3 years ago
parent f9e8bb7c4e
commit 4b3cdc6831
  1. 4
      lib/src/sparql/eval.rs
  2. 30
      spargebra/src/algebra.rs

@ -2703,8 +2703,8 @@ fn get_triple_template_value<'a>(
TripleTemplateValue::Triple(triple) => Some( TripleTemplateValue::Triple(triple) => Some(
EncodedTriple { EncodedTriple {
subject: get_triple_template_value(&triple.subject, tuple, bnodes)?, subject: get_triple_template_value(&triple.subject, tuple, bnodes)?,
predicate: get_triple_template_value(&triple.subject, tuple, bnodes)?, predicate: get_triple_template_value(&triple.predicate, tuple, bnodes)?,
object: get_triple_template_value(&triple.subject, tuple, bnodes)?, object: get_triple_template_value(&triple.object, tuple, bnodes)?,
} }
.into(), .into(),
), ),

@ -648,15 +648,7 @@ impl GraphPattern {
match self { match self {
GraphPattern::Bgp(p) => { GraphPattern::Bgp(p) => {
for pattern in p { for pattern in p {
if let TermPattern::Variable(s) = &pattern.subject { add_triple_pattern_variables(pattern, vars)
vars.insert(s);
}
if let NamedNodePattern::Variable(p) = &pattern.predicate {
vars.insert(p);
}
if let TermPattern::Variable(o) = &pattern.object {
vars.insert(o);
}
} }
} }
GraphPattern::Path { GraphPattern::Path {
@ -664,9 +656,13 @@ impl GraphPattern {
} => { } => {
if let TermPattern::Variable(s) = subject { if let TermPattern::Variable(s) = subject {
vars.insert(s); vars.insert(s);
} else if let TermPattern::Triple(s) = subject {
add_triple_pattern_variables(s, vars)
} }
if let TermPattern::Variable(o) = object { if let TermPattern::Variable(o) = object {
vars.insert(o); vars.insert(o);
} else if let TermPattern::Triple(o) = object {
add_triple_pattern_variables(o, vars)
} }
} }
GraphPattern::Join { left, right } GraphPattern::Join { left, right }
@ -704,6 +700,22 @@ impl GraphPattern {
} }
} }
fn add_triple_pattern_variables<'a>(pattern: &'a TriplePattern, vars: &mut BTreeSet<&'a Variable>) {
if let TermPattern::Variable(s) = &pattern.subject {
vars.insert(s);
} else if let TermPattern::Triple(s) = &pattern.subject {
add_triple_pattern_variables(s, vars)
}
if let NamedNodePattern::Variable(p) = &pattern.predicate {
vars.insert(p);
}
if let TermPattern::Variable(o) = &pattern.object {
vars.insert(o);
} else if let TermPattern::Triple(o) = &pattern.object {
add_triple_pattern_variables(o, vars)
}
}
struct SparqlGraphPattern<'a>(&'a GraphPattern); struct SparqlGraphPattern<'a>(&'a GraphPattern);
impl<'a> fmt::Display for SparqlGraphPattern<'a> { impl<'a> fmt::Display for SparqlGraphPattern<'a> {

Loading…
Cancel
Save