On 27/07/16 09:25, Jindřich Mynarz wrote:
Hi,
I'm wondering why Jena thinks the optimized SPARQL algebras of the
following queries are different:
# Query 1
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
?concept skos:broader [ skos:prefLabel ?broaderLabel ] .
}
# Query 1 algebra
(bgp
(triple ?concept <http://www.w3.org/2004/02/skos/core#broader> ??0)
(triple ??0 <http://www.w3.org/2004/02/skos/core#prefLabel> ?broaderLabel)
)
# Query 2
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
?concept skos:broader/skos:prefLabel ?broaderLabel .
}
# Query 2 algebra
(bgp
(triple ?concept <http://www.w3.org/2004/02/skos/core#broader> ??P4)
(triple ??P4 <http://www.w3.org/2004/02/skos/core#prefLabel>
?broaderLabel)
)
When I compare if the query 1 algebra is equal to the query 2 algebra,
false is returned. However, the only difference I can spot between the
algebras is in the names of the non-distinguished variables ??0 and ??P4.
Why are the query algebras treated as different?
Two algebra expressions are equal if they are the same structures,
including variable names.
ARQ does have some isomorphism support:
Op.isEqualTo(Op other, NodeIsomorphismMap labelMap)
but those bnodes are concrete ones, not query generated ones.
See Iso.nodeIso which has some provision but
NodeIsomorphismMap.makeIsomorphic only covers concrete (data) bnodes.
A subclass of NodeIsomorphismMap and isEqualTo could so generate
variable isomorphism (I checked on your example).
There are cases where subqueries have different scope variables (they
don't make the final results so changing their name does not change the
outcome). But that does not fit the structural isomorphism code in ARQ
so it would need a new algorithm.
Names matter: the two are different:
(bgp (?X ?Y ?O))
(bgp (?s ?p ?o))
BTW The queries are different are higher levels of entailment. Paths
don't play a part of entailment matching.
Andy
- Jindřich