Question

I have a little problem with a Sparql query. I would like to get all subjects having the type "TopologicalNode", with a predicate called "BaseVoltage" and a specific resource (in this example, '#_2a9')

There is a sample of my .xml

<cim:TopologicalNode rdf:ID="_f4d">   
    <cim:IdentifiedObject.name>dj</cim:IdentifiedObject.name>
    <cim:TopologicalNode.BaseVoltage rdf:resource="#_2a9"/>
</cim:TopologicalNode>

<cim:TopologicalNode rdf:ID="_738">    
    <cim:IdentifiedObject.name>iT</cim:IdentifiedObject.name>
    <cim:TopologicalNode.BaseVoltage rdf:resource="#_a5c"/>   
</cim:TopologicalNode>

<cim:TopologicalNode>
    <cim:TopologicalNode rdf:ID="_2a2">
    <cim:IdentifiedObject.name>Hi</cim:IdentifiedObject.name>
    <cim:TopologicalNode.BaseVoltage rdf:resource="#_2a9"/>
    <cim:TopologicalNode.ConnectivityNodeContainer rdf:resource="#_d7a"/>
</cim:TopologicalNode>

My query doesn't work (Encountered a Token which terminates a Triple Pattern but there are too many Tokens to form a valid Triple Pattern)

"SELECT ?s  WHERE {?s rdf:type cim:TopologicalNode; cim:TopologicalNode.BaseVoltage ?o rdf:resource '#_2a9';}"

I also tried to put directly the full URI... Same error!

"SELECT ?s  WHERE {?s rdf:type cim:TopologicalNode; cim:TopologicalNode.BaseVoltage ?o rdf:resource <example.org/EQ#_2a9>;}"

What is my mistake ? It must be in the third block because I saw that this was working

"SELECT ?s  WHERE {?s rdf:type cim:TopologicalNode; cim:TopologicalNode.BaseVoltage ?o }"  

Thank you very much !

Was it helpful?

Solution

Your query is invalid SPARQL, if you include some white space you can easily see this:

SELECT ?s  
WHERE 
{
  ?s rdf:type cim:TopologicalNode ; 
     cim:TopologicalNode.BaseVoltage ?o rdf:resource '#_2a9' ;
}

After the ?o you immediately state another predicate and object pair but fail to include any additional punctuation to separate the tokens and indicate a new triple pattern so the parser is quite right to give you this error. Of course the error could be more helpful but that's a separate issue.

You can fix your query by inserting an additional semicolon character like so:

SELECT ?s  
WHERE 
{
  ?s rdf:type cim:TopologicalNode ; 
     cim:TopologicalNode.BaseVoltage ?o ;
     rdf:resource '#_2a9' ;
}

Btw you still won't actually get any results because rdf:resource is merely a serialisation detail of RDF/XML and will not show up in your data. What you probably meant was simply to use the URI in place of ?o like so:

SELECT ?s  
WHERE 
{
  ?s rdf:type cim:TopologicalNode ; 
     cim:TopologicalNode.BaseVoltage <http://example.org#_2a9> ;
}

Of course you may still need to tweak this slightly to use the correct URI here but this should point you in the right direction

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top