SPARQL query for skos:related field?

558 views Asked by At

Trying to query for the most referenced SKOS concept in an RDF/XML file.

So if a concept looks like this in the file:

<rdf:Description   rdf:about="http://foo.bar.biz/Processes/151">
    <rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
    <skos:prefLabel xml:lang="en">Part</skos:prefLabel>
    <skos:related rdf:resource="http://foo.bar.biz/Processes/150"/>
</rdf:Description>

How can I construct a SPARQL query that targets the skos:related tag ? I'm looking into RDFLib in Python right now, which has SPARQL compatibility. Seems like a query would be more appropriate than parsing the entire file - just not familiar enough with SPARQL syntax I suppose.

1

There are 1 answers

0
scotthenninger On

As Jeen suggests, finding out more about SPARQL is a good idea. As an initial reference, this is pretty easy:

SELECT ?related
WHERE {
    ?s skos:related ?related
}

A more useful suggestion may be to view the data in any RDF text serialization other than RDF/XML, which is difficult for humans to parse out the triples, and hence understand how to query it. For example, the equivalent snippet in the Turtle text serialization is:

<http://foo.bar.biz/Processes/151> 
    rdf:type skos:Concept ;
    skos:prefLabel "Part"@en ;
    skos:related <http://foo.bar.biz/Processes/150>
.

...and you may find that more compatible with understanding how RDF is structured and how SPARQL can be used to query it.