My problem is that I would like to retrieve all subjects containing cim:ACLineSegment, whatever the ID they may have.
<cim:ACLineSegment rdf:ID="_05b8"> <!-- some code... --> </cim:ACLineSegment>
Your subjects don't “contain” cim:ACLineSegment
. Subjects don't contain anything in RDF. Resources (including subjects of triples) are identified by URIs. RDF is based on triples of the form {subject, predicate, object}. The snippet you're showing is RDF/XML, which is a particular serialization of triples. In the snippet you've shown, there are some triples of the form {<.../_05b8>, rdf:type, cim:ACLineSegment}
. That is, your subjects have the value cim:ACLineSegment
as the value of the rdf:type
property.
To explain a little bit more, suppose you had the following data. (By the way, in the future, it will be much more helpful if you provide minimal, but complete, sample data. The data you provided isn't complete, and we can't run queries against it, and we can't be sure what it is in context.)
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://stackoverflow.com/q/23432445/1281433/ex#"
xml:base="http://stackoverflow.com/q/23432445/1281433/ex#">
<ex:Person rdf:ID="Mary">
<ex:hasName>Mary</ex:hasName>
</ex:Person>
<ex:Person rdf:ID="Jim">
<ex:hasName>James</ex:hasName>
<ex:hasAge rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">34</ex:hasAge>
</ex:Person>
<ex:Person rdf:ID="John">
<ex:hasName>John</ex:hasName>
</ex:Person>
</rdf:RDF>
If you take a look at this data in the N-Triples serialization (which has just one triple per line), you'll see these triples:
<http://stackoverflow.com/q/23432445/1281433/ex#Mary> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://stackoverflow.com/q/23432445/1281433/ex#Person> .
<http://stackoverflow.com/q/23432445/1281433/ex#Mary> <http://stackoverflow.com/q/23432445/1281433/ex#hasName> "Mary" .
<http://stackoverflow.com/q/23432445/1281433/ex#John> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://stackoverflow.com/q/23432445/1281433/ex#Person> .
<http://stackoverflow.com/q/23432445/1281433/ex#John> <http://stackoverflow.com/q/23432445/1281433/ex#hasName> "John" .
<http://stackoverflow.com/q/23432445/1281433/ex#Jim> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://stackoverflow.com/q/23432445/1281433/ex#Person> .
<http://stackoverflow.com/q/23432445/1281433/ex#Jim> <http://stackoverflow.com/q/23432445/1281433/ex#hasName> "James" .
<http://stackoverflow.com/q/23432445/1281433/ex#Jim> <http://stackoverflow.com/q/23432445/1281433/ex#hasAge> "34"^^<http://www.w3.org/2001/XMLSchema#integer> .
Notice all those rdf:type
triples? That's because in RDF/XML syntax (§2.13 Typed Node Elements), an element that corresponds to a resource, has the element name as a value for rdf:type
. Thus, the RDF/XML above is actually shorthand for this data:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://stackoverflow.com/q/23432445/1281433/ex#" >
<rdf:Description rdf:about="http://stackoverflow.com/q/23432445/1281433/ex#Mary">
<rdf:type rdf:resource="http://stackoverflow.com/q/23432445/1281433/ex#Person"/>
<ex:hasName>Mary</ex:hasName>
</rdf:Description>
<rdf:Description rdf:about="http://stackoverflow.com/q/23432445/1281433/ex#Jim">
<rdf:type rdf:resource="http://stackoverflow.com/q/23432445/1281433/ex#Person"/>
<ex:hasName>James</ex:hasName>
<ex:hasAge rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">34</ex:hasAge>
</rdf:Description>
<rdf:Description rdf:about="http://stackoverflow.com/q/23432445/1281433/ex#John">
<rdf:type rdf:resource="http://stackoverflow.com/q/23432445/1281433/ex#Person"/>
<ex:hasName>John</ex:hasName>
</rdf:Description>
</rdf:RDF>
It's also helpful to view the data in N3 or Turtle syntax, because it's much closer to the SPARQL query syntax:
@prefix ex: <http://stackoverflow.com/q/23432445/1281433/ex#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:Mary a ex:Person ;
ex:hasName "Mary" .
ex:John a ex:Person ;
ex:hasName "John" .
ex:Jim a ex:Person ;
ex:hasAge 34 ;
ex:hasName "James" .
What all of this means is that you simply want to ask for things with a specified type. Your query would be:
select ?predicate ?object where {
?subject rdf:type cim:ACLineSegment ; # You can use `a` instead of rdf:type.
?predicate ?object
}