Theasc721
Theasc721

Reputation: 47

Extract attributes values with SPARQL

I want to use SPARQL to get subjects rdf:value which have the following resource : http://purl.org/dc/terms/LCSH

<dcterms:subject>
    <rdf:Description rdf:nodeID="N4192a7fb1dd6438c94649f7afd192f09">
        <rdf:value>United States. Declaration of Independence</rdf:value>
        <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCSH"/>
    </rdf:Description>
</dcterms:subject>
<dcterms:subject>
    <rdf:Description rdf:nodeID="N887b24b564624253b374ee7c95f0ed51">
       <rdf:value>United States -- History -- Revolution, 1775-1783 -- Sources</rdf:value>
       <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCSH"/>
    </rdf:Description>
</dcterms:subject>
<dcterms:subject>
    <rdf:Description rdf:nodeID="N1b3ed5adb91b4b0c8aa1215180fdfa96">
       <rdf:value>JK</rdf:value>
       <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCC"/>
    </rdf:Description>
</dcterms:subject>
<dcterms:subject>
   <rdf:Description rdf:nodeID="Nc5deb6e74cc6462fbeeb8c1871983f09">
      <dcam:memberOf rdf:resource="http://purl.org/dc/terms/LCC"/>
      <rdf:value>KF</rdf:value>
   </rdf:Description>
</dcterms:subject>

Is there a way to extract the rdf:resource and use it to filter the subjects?

Upvotes: 0

Views: 1032

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85913

The rdf/xml snippet isn't complete, so we can't write a perfect query, but you'll want something like this:

select ?value {
  ?x dcterms:subject ?subject .
  ?subject rdf:value ?value .
  ?subject dcam:memberOf  <http://purl.org/dc/terms/LCSH> .
}

If you want to make that a bit shorter, you could do:

select ?value {
  ?x dcterms:subject [
      rdf:value ?value ;
      dcam:memberOf  <http://purl.org/dc/terms/LCSH> ]
}

And if you really only care about things that have rdf:value properties and are members of LCSH you could skip the first triple altogether:

select ?value {
  ?x rdf:value ?value ;
      dcam:memberOf  <http://purl.org/dc/terms/LCSH> 
}

Upvotes: 2

Related Questions