0

我对 Sparql 查询有一点问题。我想获取具有“TopologicalNode”类型的所有主题,带有名为“BaseVoltage”的谓词和特定资源(在本例中为“#_2a9”)

我的 .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>

我的查询不起作用(遇到一个终止三重模式的令牌,但令牌太多而无法形成有效的三重模式)

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

我也尝试直接输入完整的 URI ......同样的错误!

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

我的错误是什么?它必须在第三个街区,因为我看到这是有效的

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

非常感谢 !

4

1 回答 1

2

您的查询是无效的 SPARQL,如果您包含一些空格,您可以很容易地看到:

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

?o您立即声明另一个谓词和对象对之后,但没有包含任何额外的标点符号来分隔标记并指示新的三元组模式,因此解析器给您这个错误是完全正确的。当然,错误可能更有帮助,但这是一个单独的问题。

您可以通过插入一个额外的分号字符来修复您的查询,如下所示:

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

顺便说一句,您实际上仍然不会得到任何结果,因为rdf:resource它只是 RDF/XML 的序列化细节,不会出现在您的数据中。您可能的意思只是简单地使用 URI 来代替?o

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

当然,您可能仍需要稍微调整一下以在此处使用正确的 URI,但这应该为您指明正确的方向

于 2014-05-07T15:53:09.313 回答