First of all I must apologize since I am very new when it comes to XML, RDF and SPARQL queries. All my knowledge is based on 3 days of much reading so it has not fully sunk in. Nevertheless, a problem I encountered when trying to query a large RDF file using Jena was how to get all instances that are part of a superclass?
Sorry if this is badly worded so here is an example. In my RDF file, there is always a main node:
The Main Node
and then there are objects that have this node as a resource like:
<cim:Connection rdf:ID="connection_1">
<cim:Object.name>Connection Point 1</cim:Object.name>
<cim:Connection.node rdf:resource="#main_node_1"/>
</cim:Connection>
or
<cim:Potential rdf:ID="potential_1">
<cim:Object.name>Equal Potential 1</cim:Object.name>
<cim:Potential.node rdf:resource="#main_node_1"/>
</cim:Connection>
Now I know how to query for any rdf:type
and (a bit) how to graph query using SPARQL. What I want to do is 1st find the MainNode (which I already can) and then find all elements/objetcs/classes/instances that reference to this MainNode.
With my current attempts I can query for a Connection
or Potential
directly, but not for both. So the query returning all Connection
s would be:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX cim: <http://iec.ch/TC57/2010/CIM-schema-cim15#>
SELECT ?object
WHERE {
?object cim:Connection.node ?mainNode .
?mainNode cim:Object.name "The Main Node" .
}
and for all Potential
s the query would be:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX cim: <http://iec.ch/TC57/2010/CIM-schema-cim15#>
SELECT ?object
WHERE {
?object cim:potential.node ?mainNode .
?mainNode cim:Object.name "The Main Node" .
}
Yet I need to extract both and do not want to use UNION
since there may be more classes that I have not included. My attempt was to change the ?object
line to:
?mainNode cim:*.name "The Main Node" .
yet the asterisk *
does not allow me to make any class available here. In fact, both Connection
and Potential
could be seen as children of a superclass that contains the variable node
.