SPARQL: Fixes parsing of nested anonymous blank nodes

pull/230/head
Tpt 2 years ago committed by Thomas Tanon
parent 2db906350d
commit ba9f6528e7
  1. 10
      lib/spargebra/src/parser.rs
  2. 8
      testsuite/oxigraph-tests/sparql/manifest.ttl
  3. 5
      testsuite/oxigraph-tests/sparql/nested_anonymous.rq
  4. 13
      testsuite/oxigraph-tests/sparql/nested_anonymous.srx
  5. 4
      testsuite/oxigraph-tests/sparql/nested_anonymous.ttl

@ -128,7 +128,7 @@ impl<F> From<FocusedTriplePattern<F>> for FocusedTriplePattern<Vec<F>> {
}
}
#[derive(Clone)]
#[derive(Clone, Debug)]
enum VariableOrPropertyPath {
Variable(Variable),
PropertyPath(PropertyPathExpression),
@ -289,6 +289,7 @@ fn build_bgp(patterns: Vec<TripleOrPathPattern>) -> GraphPattern {
elements.into_iter().reduce(new_join).unwrap_or_default()
}
#[derive(Debug)]
enum TripleOrPathPattern {
Triple(TriplePattern),
Path {
@ -304,6 +305,7 @@ impl From<TriplePattern> for TripleOrPathPattern {
}
}
#[derive(Debug)]
struct AnnotatedTermPath {
term: TermPattern,
annotations: Vec<(VariableOrPropertyPath, Vec<AnnotatedTermPath>)>,
@ -322,7 +324,7 @@ impl From<AnnotatedTerm> for AnnotatedTermPath {
}
}
#[derive(Default)]
#[derive(Debug, Default)]
struct FocusedTripleOrPathPattern<F> {
focus: F,
patterns: Vec<TripleOrPathPattern>,
@ -1596,7 +1598,7 @@ parser! {
} /
s:TriplesNodePath() _ po:PropertyListPath() {?
let mut patterns = s.patterns;
patterns.extend(po.patterns);
patterns.extend(po.patterns);
for (p, os) in po.focus {
for o in os {
add_to_triple_or_path_patterns(s.focus.clone(), p.clone(), o, &mut patterns)?;
@ -1780,7 +1782,7 @@ parser! {
//[101]
rule BlankNodePropertyListPath() -> FocusedTripleOrPathPattern<TermPattern> = "[" _ po:PropertyListPathNotEmpty() _ "]" {?
let mut patterns: Vec<TripleOrPathPattern> = Vec::new();
let mut patterns = po.patterns;
let mut bnode = TermPattern::from(BlankNode::default());
for (p, os) in po.focus {
for o in os {

@ -26,6 +26,7 @@
:nested_path
:nested_expression
:order_terms
:nested_anonymous
) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -114,3 +115,10 @@
mf:name "literals have an order for ORDER BY" ;
mf:action [ qt:query <order_terms.rq> ] ;
mf:result <order_terms.ttl> .
:nested_anonymous rdf:type mf:QueryEvaluationTest ;
mf:name "Nested anonymous" ;
mf:action
[ qt:query <nested_anonymous.rq> ;
qt:data <nested_anonymous.ttl> ] ;
mf:result <nested_anonymous.srx> .

@ -0,0 +1,5 @@
PREFIX : <http://example.com/>
SELECT ?a WHERE {
[ :p1 ?a ; :p2 [ :p3 :foo ] ]
}

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="a"/>
</head>
<results>
<result>
<binding name="a">
<literal>t1</literal>
</binding>
</result>
</results>
</sparql>

@ -0,0 +1,4 @@
PREFIX : <http://example.com/>
[ :p1 "t1" ; :p2 [ :p3 :foo ] ] .
[ :p1 "t2" ; :p2 [ :p3 :bar ] ] .
Loading…
Cancel
Save