0

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>
jojo
  • 333
  • 2
  • 13

1 Answers1

2

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 |
-----------------------------------------------------------------------------------------------
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thank you, I will try your suggestion then I will tell you if it work with me, however I did not manually create my data, I used Protege and SkosEd to create my ontology, and this is an automatically generated data. – jojo Nov 29 '13 at 16:40
  • it seems that it does not work, there is an error which say: "Unresolved prefixed name: :definition" and if I put PREFIX res: then I write: ....res:Address ?address; res:Definition ?definition it gives me an empty results – jojo Nov 29 '13 at 16:52
  • @jojo Yes, like I said, I had to modify your data a lot to get to something that was _similar_. I don't have access to your _actual_ data. In your comment you wrote `res:Address` and `res:`Definition`. Even if your `res:` prefix is defined correctly, in the _data_ that you showed us `Address` was capitalized, but `definition` was not. – Joshua Taylor Nov 29 '13 at 16:57
  • @jojo Also, please wrap any code-like stuff in your comments with backticks ```; I can't tell whether your code in your last comment was `PREFIX res:` or `PREFIX res:` (notice the leading `http://`). – Joshua Taylor Nov 29 '13 at 16:59
  • thank you for your responses,and I'm so sorry, but it stills give me no results – jojo Nov 29 '13 at 17:08
  • @jojo The data that I provided, when used with the query that I provided, produces the results that I've shown. That's the _only_ data that we have available to us at the moment, because you haven't provided enough of your data for us to use. If you want a query that will work the on the exact that you have, you'll need to show us that data. – Joshua Taylor Nov 29 '13 at 17:19
  • Thank you, it works now: the problem was in my prefix, I have changed the prefix of res to [PREFIX res:] – jojo Nov 29 '13 at 17:33
  • @jojo As I requested before, please surround any code in comments with backticks (`\``). It doesn't matter all that much, but I don't know whether your fixed version is `PREFIX res:` (as it appears in your comment) or `PREFIX res:`. – Joshua Taylor Nov 29 '13 at 17:56