2

So I have this turtle file:

@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ex: <http://example.org/> .
@prefix ex-sample: <http://example.org/sample/> .

ex:a rdf:type skos:Concept .
ex:a rdf:prefLabel "a" .
ex:b rdf:type skos:Concept .
ex:b rdf:prefLabel "b" .
ex:c rdf:type skos:Concept .
ex:c rdf:prefLabel "c" .
ex:d rdf:type skos:Concept .
ex:d rdf:prefLabel "d" .

ex:e rdf:type ex-sample:sample .
ex:e dct:subject ex:d .
ex:e dct:subject ex:c .

I want to make a SPARQL query that returns a column that lists all the possible paths to reach the ex:a from ex:e. I expect the table to have two rows, that look like this:

row1: d,c,b,a
row2: c,b,a

I have tried this SPARQL query:

    ?target rdf:type ex:sample .
    ?target skos:prefLabel ?targetTitle .
    ?target dct:subject ?dctsubject .
    ?dctsubject skos:broader* ?furtherPath .
    ?furtherPath skos:prefLabel ?furtherPathLabel .
}

It can identify all the paths but they are printed in many rows, like this:

row 1: d
row 2: c
row 3: b
row 4: a
row 5: c
row 6: b
row 7: a

Thanks!

rose
  • 61
  • 4
  • 1
    1) your sample data doesn't match the query, the data is missing the SKOS taxonomy triples 2) SPARQL isn't the appropriate language to get paths, there are only some limited workarounds 3) your output is more or less by accident in the correct order, depending on the implementation the order might be different and still a valid SPARQL result – UninformedUser Mar 16 '23 at 08:01
  • 1
    the best answer is still this one: https://stackoverflow.com/questions/18024413/finding-all-steps-in-property-path - and you can see there are limitations, but at least it will ensure the position of a node in the path. In addition, you would need to use `group_concat` as an aggregate function on each start/end group. The problem, there is no guarantee of the ordering in this aggregate function, even if you do a sort in a subselect because its datastructure is just a collection. So it depends on the implementation of the underlying triple store if the odering of the path would be preserved. – UninformedUser Mar 16 '23 at 08:01

0 Answers0