SPARQL Querying Transitive different versions of arq

286 views Asked by At

Basically I got a SPARQL query below which works with the arq 2.8.8 but doesn't work with arq2.8.4 as it doesnt recognise the + symbol. I really want a query which can work on the arq 2.8.4 version which is similar to the one I posted. The query I posted basically finds all items which are the sameas each other. For eg if a is the sameas b and b is the sameas c, the query returns both b and c for a.

PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE { ?x owl:sameas+ ?y }
1

There are 1 answers

0
RobV On BEST ANSWER

The feature you are using is SPARQL 1.1 and so was not supported by earlier versions of ARQ. The only way you can write a query that gets close to what you do is to do one of the following.

Union paths of different lengths

PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT *
WHERE
{
  { ?x owl:sameAs ?y }
  UNION
  { ?s owl:sameAs [ owl:sameAs ?y ] . }
  UNION
  { ?s owl:sameAs [ owl:sameAs [ owl:sameAs ?y ] ] . }
  # Repeat the above pattern up to whatever limit you want
}

Use client side code

Issue an initial query as follows:

PREFIX owl: <http://www.w3.org/2002/07/owl#> 
SELECT * WHERE { ?x owl:sameAs ?y }

Make a list of ?y values, then for each value issue a query of the form:

PREFIX owl: <http://www.w3.org/2002/07/owl#> 
SELECT * WHERE { <constant> owl:sameAs ?y }

Where you substitute <constant> for one of the values from the list each time and then add the new values of ?y to the list.

Only thing you need to be careful of with this approach is that you keep track of values for which you've already issued the second query to save you repeating queries.