user641687
user641687

Reputation:

SPARQL query on rdf:resource

Suppose I want to retrieve the names of all elements in the periodic table with a standard state of 'gas'. Here are what I believe are the relevant portions of the .owl file…

<owl:Class rdf:ID='StandardState'>
    <owl:oneOf rdf:parseType='Collection'>
        <StandardState rdf:ID='state_unknown'/>
        <StandardState rdf:ID='gas'/>
        <StandardState rdf:ID='solid'/>
        <StandardState rdf:ID='liquid'/>
    </owl:oneOf>
</owl:Class>

…example of an Element listing with StandardState 'gas', of course there are many more, but of the same format…

<Element rdf:ID="He">
    <name rdf:datatype="&xsd;string">helium</name>
    <symbol rdf:datatype="&xsd;string">He</symbol>
    <atomicNumber rdf:datatype="&xsd;integer">2</atomicNumber>
    <atomicWeight rdf:datatype="&xsd;float">4.002602</atomicWeight>
    <group rdf:resource="#group_18"/>
    <period rdf:resource="#period_1"/>
    <block rdf:resource="#p-block"/>
    <standardState rdf:resource="#gas"/>
    <color rdf:datatype="&xsd;string">colourless</color>
    <classification rdf:resource="#Non-metallic"/>
    <casRegistryID rdf:datatype="&xsd;string">7440-59-7</casRegistryID>
</Element>

I know how to query when what I ultimately want is linked to a XSD primitive, like ^^xsd:string, but when what I'm querying against is an rdf:resource I'm confused as to how to proceed.

Upvotes: 2

Views: 1451

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85813

You query for non-literals the same way that you query for literals: by writing graph patterns to match against them. In this case you can do something like:

PREFIX ex: <http://www.example.org/periodic-table#>
SELECT ?element 
WHERE { 
  ?element ex:standardState ex:gas .
}

Upvotes: 3

Related Questions