Adds comparison to SPARQL-star evaluation

pull/171/head
Tpt 4 years ago
parent 7e0738b624
commit a2dcbc715a
  1. 45
      lib/src/sparql/eval.rs
  2. 2
      testsuite/rdf-star
  3. 35
      testsuite/src/sparql_evaluator.rs

@ -822,14 +822,14 @@ impl SimpleEvaluator {
self.equals(&a, &b).map(|v| v.into())
}
PlanExpression::Greater(a, b) => Some(
(self.partial_cmp_literals(
(self.partial_cmp(
&self.eval_expression(a, tuple)?,
&self.eval_expression(b, tuple)?,
)? == Ordering::Greater)
.into(),
),
PlanExpression::GreaterOrEqual(a, b) => Some(
match self.partial_cmp_literals(
match self.partial_cmp(
&self.eval_expression(a, tuple)?,
&self.eval_expression(b, tuple)?,
)? {
@ -839,14 +839,14 @@ impl SimpleEvaluator {
.into(),
),
PlanExpression::Less(a, b) => Some(
(self.partial_cmp_literals(
(self.partial_cmp(
&self.eval_expression(a, tuple)?,
&self.eval_expression(b, tuple)?,
)? == Ordering::Less)
.into(),
),
PlanExpression::LessOrEqual(a, b) => Some(
match self.partial_cmp_literals(
match self.partial_cmp(
&self.eval_expression(a, tuple)?,
&self.eval_expression(b, tuple)?,
)? {
@ -2049,8 +2049,25 @@ impl SimpleEvaluator {
_ if b.is_blank_node() => Ordering::Greater,
_ => Ordering::Less,
},
EncodedTerm::Triple(a) => match b {
EncodedTerm::Triple(b) => {
match self.cmp_terms(Some(&a.subject), Some(&b.subject)) {
Ordering::Equal => {
match self.cmp_terms(Some(&a.predicate), Some(&b.predicate)) {
Ordering::Equal => {
self.cmp_terms(Some(&a.object), Some(&b.object))
}
o => o,
}
}
o => o,
}
}
_ => Ordering::Greater,
},
a => match b {
_ if b.is_named_node() || b.is_blank_node() => Ordering::Greater,
_ if b.is_triple() => Ordering::Less,
b => self.partial_cmp_literals(a, b).unwrap_or(Ordering::Equal),
},
},
@ -2060,6 +2077,26 @@ impl SimpleEvaluator {
}
}
fn partial_cmp(&self, a: &EncodedTerm, b: &EncodedTerm) -> Option<Ordering> {
if a == b {
return Some(Ordering::Equal);
} else if let EncodedTerm::Triple(a) = a {
if let EncodedTerm::Triple(b) = b {
match self.partial_cmp(&a.subject, &b.subject) {
Some(Ordering::Equal) => match self.partial_cmp(&a.predicate, &b.predicate) {
Some(Ordering::Equal) => self.partial_cmp(&a.object, &b.object),
o => o,
},
o => o,
}
} else {
None
}
} else {
self.partial_cmp_literals(a, b)
}
}
#[allow(clippy::cast_precision_loss)]
fn partial_cmp_literals(&self, a: &EncodedTerm, b: &EncodedTerm) -> Option<Ordering> {
match a {

@ -1 +1 @@
Subproject commit be7932662fde2a8af3b92b28a9d91489ae143d16
Subproject commit 561ce517d21f9f17f324ac58ac50be9231804255

@ -416,16 +416,39 @@ fn compare_solutions(expected: &[(Variable, Term)], actual: &[(Variable, Term)])
expected.iter().zip(actual).all(
move |((expected_variable, expected_value), (actual_variable, actual_value))| {
expected_variable == actual_variable
&& expected_value
== if let Term::BlankNode(actual_value) = actual_value {
bnode_map.entry(actual_value).or_insert(expected_value)
} else {
actual_value
}
&& compare_terms(
expected_value.as_ref(),
actual_value.as_ref(),
&mut bnode_map,
)
},
)
}
fn compare_terms<'a>(
expected: TermRef<'a>,
actual: TermRef<'a>,
bnode_map: &mut HashMap<BlankNodeRef<'a>, BlankNodeRef<'a>>,
) -> bool {
match (expected, actual) {
(TermRef::BlankNode(expected), TermRef::BlankNode(actual)) => {
expected == *bnode_map.entry(actual).or_insert(expected)
}
(TermRef::Triple(expected), TermRef::Triple(actual)) => {
compare_terms(
expected.subject.as_ref().into(),
actual.subject.as_ref().into(),
bnode_map,
) && compare_terms(
expected.predicate.as_ref().into(),
actual.predicate.as_ref().into(),
bnode_map,
) && compare_terms(expected.object.as_ref(), actual.object.as_ref(), bnode_map)
}
(expected, actual) => expected == actual,
}
}
enum StaticQueryResults {
Graph(Graph),
Solutions {

Loading…
Cancel
Save