Skip to content

Commit

Permalink
Group all BGPs together in one pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Aug 20, 2014
1 parent 0a068da commit 2e28b0c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 104 deletions.
17 changes: 16 additions & 1 deletion lib/sparql.jison
Expand Up @@ -502,7 +502,22 @@ TriplesTemplate
: (TriplesSameSubject '.')* TriplesSameSubject '.'? -> unionAll($1, [$2])
;
GroupGraphPattern
: '{' ( SubSelect | GroupGraphPatternSub ) '}' -> { type: 'group', patterns: $2 }
: '{' ( SubSelect | GroupGraphPatternSub ) '}'
{
// Simplify the pattern by grouping all BGPs together
if ($2.length > 1) {
var bgpTriples = [], otherPatterns = [];
for (var i = 0, pattern; pattern=$2[i]; i++) {
if (pattern.type === 'bgp')
appendAllTo(bgpTriples, pattern.triples);
else if (!pattern.patterns || pattern.patterns.length > 0)
otherPatterns.push(pattern);
}
$2 = !bgpTriples.length ? otherPatterns
: appendAllTo([{ type: 'bgp', triples: bgpTriples }], otherPatterns);
}
$$ = { type: 'group', patterns: $2 }
}
;
GroupGraphPatternSub
: TriplesBlock? GroupGraphPatternSubTail* -> $1 ? unionAll([$1], $2) : $2
Expand Down
25 changes: 10 additions & 15 deletions test/parsedQueries/bsbm10.json
Expand Up @@ -39,6 +39,16 @@
"subject": "?offer",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/deliveryDays",
"object": "?deliveryDays"
},
{
"subject": "?offer",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/price",
"object": "?price"
},
{
"subject": "?offer",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/validTo",
"object": "?date"
}
]
},
Expand All @@ -53,21 +63,6 @@
]
}
},
{
"type": "bgp",
"triples": [
{
"subject": "?offer",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/price",
"object": "?price"
},
{
"subject": "?offer",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/validTo",
"object": "?date"
}
]
},
{
"type": "filter",
"expression": {
Expand Down
54 changes: 22 additions & 32 deletions test/parsedQueries/bsbm5.json
Expand Up @@ -19,23 +19,7 @@
"subject": "?product",
"predicate": "http://www.w3.org/2000/01/rdf-schema#label",
"object": "?productLabel"
}
]
},
{
"type": "filter",
"expression": {
"type": "operation",
"operator": "!=",
"args": [
"http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer1/Product28",
"?product"
]
}
},
{
"type": "bgp",
"triples": [
},
{
"subject": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer1/Product28",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/productFeature",
Expand All @@ -55,9 +39,30 @@
"subject": "?product",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/productPropertyNumeric1",
"object": "?simProperty1"
},
{
"subject": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer1/Product28",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/productPropertyNumeric2",
"object": "?origProperty2"
},
{
"subject": "?product",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/productPropertyNumeric2",
"object": "?simProperty2"
}
]
},
{
"type": "filter",
"expression": {
"type": "operation",
"operator": "!=",
"args": [
"http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer1/Product28",
"?product"
]
}
},
{
"type": "filter",
"expression": {
Expand Down Expand Up @@ -97,21 +102,6 @@
]
}
},
{
"type": "bgp",
"triples": [
{
"subject": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer1/Product28",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/productPropertyNumeric2",
"object": "?origProperty2"
},
{
"subject": "?product",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/productPropertyNumeric2",
"object": "?simProperty2"
}
]
},
{
"type": "filter",
"expression": {
Expand Down
35 changes: 15 additions & 20 deletions test/parsedQueries/bsbm8.json
Expand Up @@ -36,6 +36,21 @@
"subject": "?review",
"predicate": "http://purl.org/stuff/rev#text",
"object": "?text"
},
{
"subject": "?review",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/reviewDate",
"object": "?reviewDate"
},
{
"subject": "?review",
"predicate": "http://purl.org/stuff/rev#reviewer",
"object": "?reviewer"
},
{
"subject": "?reviewer",
"predicate": "http://xmlns.com/foaf/0.1/name",
"object": "?reviewerName"
}
]
},
Expand All @@ -56,26 +71,6 @@
]
}
},
{
"type": "bgp",
"triples": [
{
"subject": "?review",
"predicate": "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/reviewDate",
"object": "?reviewDate"
},
{
"subject": "?review",
"predicate": "http://purl.org/stuff/rev#reviewer",
"object": "?reviewer"
},
{
"subject": "?reviewer",
"predicate": "http://xmlns.com/foaf/0.1/name",
"object": "?reviewerName"
}
]
},
{
"type": "optional",
"patterns": [
Expand Down
15 changes: 5 additions & 10 deletions test/parsedQueries/sparql-5-2-2c.json
Expand Up @@ -16,6 +16,11 @@
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/name",
"object": "?name"
},
{
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/mbox",
"object": "?mbox"
}
]
},
Expand All @@ -29,16 +34,6 @@
"\"Smith\""
]
}
},
{
"type": "bgp",
"triples": [
{
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/mbox",
"object": "?mbox"
}
]
}
]
}
15 changes: 5 additions & 10 deletions test/parsedQueries/sparql-5-2-3b.json
Expand Up @@ -16,6 +16,11 @@
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/name",
"object": "?name"
},
{
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/mbox",
"object": "?mbox"
}
]
},
Expand All @@ -29,16 +34,6 @@
"\"Smith\""
]
}
},
{
"type": "bgp",
"triples": [
{
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/mbox",
"object": "?mbox"
}
]
}
]
}
11 changes: 1 addition & 10 deletions test/parsedQueries/sparql-5-2-3c.json
Expand Up @@ -16,16 +16,7 @@
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/name",
"object": "?name"
}
]
},
{
"type": "group",
"patterns": []
},
{
"type": "bgp",
"triples": [
},
{
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/mbox",
Expand Down
7 changes: 1 addition & 6 deletions test/parsedQueries/sparql-5-2b.json
Expand Up @@ -16,12 +16,7 @@
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/name",
"object": "?name"
}
]
},
{
"type": "bgp",
"triples": [
},
{
"subject": "?x",
"predicate": "http://xmlns.com/foaf/0.1/mbox",
Expand Down

0 comments on commit 2e28b0c

Please sign in to comment.