简体   繁体   English

DotNetRDF sparql查询以获取具有特定资源的主题

[英]DotNetRDF sparql query to get subjects with a specific resource

I have a little problem with a Sparql query. 我对Sparql查询有一点问题。 I would like to get all subjects having the type "TopologicalNode", with a predicate called "BaseVoltage" and a specific resource (in this example, '#_2a9') 我想让所有主题都具有“TopologicalNode”类型,带有一个名为“BaseVoltage”的谓词和一个特定的资源(在这个例子中,'#_aa9')

There is a sample of my .xml 有一个我的.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! 我也试图直接把完整的URI ...同样的错误!

"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 ! 非常感谢你 !

Your query is invalid SPARQL, if you include some white space you can easily see this: 您的查询是无效的SPARQL,如果您包含一些空格,您可以很容易地看到:

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. 经过?o ,你立即宣布另一个谓语和宾语对,但不包括任何其他标点令牌分离,表明一个新的三重图案所以解析器是完全正确的,给你这个错误。 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. 顺便说一句,你仍然不会得到任何结果,因为rdf:resource只是RDF / XML的序列化细节,不会显示在你的数据中。 What you probably meant was simply to use the URI in place of ?o like so: 您可能想要的只是使用URI代替?o如此:

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 当然,您可能仍需要稍微调整一下以使用正确的URI,但这应该指向正确的方向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM