Sparql query for additional data property assertion

1k views Asked by At

I have the following graph for a SKOS term. I have created a SKOS ontology, and a data property assertion "definition" to add definitions to terms, in addition to another data property as a subProperty of skos:altLabel (address), How can I create a SPARQL query which select a prefLabel, address and the definition of terms?

<skos:concept rdf:about="&amp;Ontology129;Zoology"> 
<rdf:type rdf:resource="&amp;owl;NamedIndividual"/> 
<rdf:type rdf:resource="&amp;owl;Thing"/> 
<skos:altlabel xml:lang="en">animal biology</skos:altlabel> 
<definition xml:lang="en">the branch of biology that studies animals</definition>         
 <Address rdf:datatype="&xsd;long">123</Address>
 <skos:altlabel xml:lang="en">zoological science</skos:altlabel> <skos:preflabel 
 xml:lang="en">zoology</skos:preflabel> 
<skos:broader rdf:resource="&amp;Ontology129;Biology"/> 
<skos:inscheme rdf:resource="&amp;Ontology129;ScientificDisciplines"/> 
</skos:concept>
1

There are 1 answers

8
Joshua Taylor On BEST ANSWER

Bad Data

You haven't provided a complete RDF/XML document, so it's hard to tell exactly what's going on, but some of your RDF/XML looks very questionable. For the types in:

<skos:concept rdf:about="&amp;Ontology129;Zoology"> 
  <rdf:type rdf:resource="&amp;owl;NamedIndividual"/> 
  <rdf:type rdf:resource="&amp;owl;Thing"/> 
  …

do not look right. I think you're trying to say that some resource identified by an IRI ending in Zoology is an owl:Thing and an owl:NamedIndividual, but those would be the the IRIs

http://www.w3.org/2002/07/owl#Thing
http://www.w3.org/2002/07/owl#NamedIndividual

but you're using the (not quite) IRIs

&owl;Thing
&owl;NamedIndividual

You've also got some relative IRIs (unless you've specified an xml:base in your document but, again, you didn't post a whole document):

<skos:concept rdf:about="&amp;Ontology129;Zoology"> 
  …
  <definition xml:lang="en">the branch of biology that studies animals</definition>         
  <Address rdf:datatype="&xsd;long">123</Address>

A SPARQL query

I think you wanted data that is something more like:

<rdf:RDF
  xmlns="http://stackoverflow.com/q/20287798/1281433/"
  xmlns:owl="http://www.w3.org/2002/07/owl#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
  xmlns:skos="http://www.w3.org/2004/02/skos/core#">
  <skos:concept rdf:about="http://stackoverflow.com/q/20287798/1281433/Zoology"> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/> 
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/> 
    <skos:altlabel xml:lang="en">animal biology</skos:altlabel> 
    <definition xml:lang="en">the branch of biology that studies animals</definition>         
    <Address rdf:datatype="http://www.w3.org/2001/XMLSchema#long">123</Address>
    <skos:altlabel xml:lang="en">zoological science</skos:altlabel>
    <skos:preflabel xml:lang="en">zoology</skos:preflabel>
    <skos:broader rdf:resource="http://stackoverflow.com/q/20287798/1281433/Biology"/> 
    <skos:inscheme rdf:resource="http://stackoverflow.com/q/20287798/1281433/ScientificDisciplines"/> 
  </skos:concept>
</rdf:RDF>

It's often helpful to look at data in Turtle format when you're writing a SPARQL query, because the SPARQL pattern language and the Turtle syntax are very similar. The data in Turtle is:

@prefix :      <http://stackoverflow.com/q/20287798/1281433/> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix skos:  <http://www.w3.org/2004/02/skos/core#> .

:Zoology  a             owl:NamedIndividual , owl:Thing , skos:concept ;
        :Address        "123"^^xsd:long ;
        :definition     "the branch of biology that studies animals"@en ;
        skos:altlabel   "zoological science"@en , "animal biology"@en ;
        skos:broader    :Biology ;
        skos:inscheme   :ScientificDisciplines ;
        skos:preflabel  "zoology"@en .

The SPARQL query looks a lot like the data:

prefix :      <http://stackoverflow.com/q/20287798/1281433/> 
prefix skos:  <http://www.w3.org/2004/02/skos/core#> 

select ?term ?preflabel ?address ?definition where {
  ?term a skos:concept ;
        skos:preflabel ?preflabel ;
        :Address ?address ;
        :definition ?definition .
}

The results are:

-----------------------------------------------------------------------------------------------
| term     | preflabel    | address         | definition                                      |
===============================================================================================
| :Zoology | "zoology"@en | "123"^^xsd:long | "the branch of biology that studies animals"@en |
-----------------------------------------------------------------------------------------------