检索用作类型的空白节点(retrieving a blank node used as a type)

编程入门 行业动态 更新时间:2024-10-21 06:06:10
检索用作类型的空白节点(retrieving a blank node used as a type)

我有一个本体的东西:

:indi_1 a :Segment; a [ :builds only {:indi_2}]; :hasID 1.

现在我想找到indi_1构建的个体。 我做了以下查询:

SELECT distinct ?a WHERE {:indi_1 a ?b. ?b a _:blankNode}

但我仍然得到我的结果中的细分。 另外,我无法进入空白节点内来重新检索indi_2 。

我该如何构建查询?

I have an ontology something like:

:indi_1 a :Segment; a [ :builds only {:indi_2}]; :hasID 1.

Now I want to find the individual(s) which indi_1 builds. I made the following query:

SELECT distinct ?a WHERE {:indi_1 a ?b. ?b a _:blankNode}

but I still get the segment in my results. Plus I can't reach inside the blank node to retrive the indi_2.

How should I build my query?

最满意答案

我不知道为什么你会期望?ba :blankNode要求?b是一个空白节点。 :blankNode是一个空白节点,在这样的SPARQL查询中充当变量,所以它只需要?b有一些类型。 您的书面查询甚至不合法。 它看起来像你想要的:indi_1 a ?b . ?ba _:blankNode :indi_1 a ?b . ?ba _:blankNode (注意. ,而不是; )。

无论如何,要检查是否有空白节点,请查看SPARQL 1.1规范 ,并注意到有一个isBlank函数。 这就是您用来过滤结果的方法。 你有这样的事情:

select * {
  ?a a ?b 
  filter isBlank(?b)
}
 

但是,如果您实际需要的是个人列表,那么您实际上需要更仔细地查看数据的RDF序列化。 你实际上并不在意吗?b是空白的,而是具有正确属性的限制。 从公理如下:

:a仅构建{:b,:c}

你最终得到这样的RDF:

:a a owl:NamedIndividual , owl:Thing ; a [ a owl:Restriction ; owl:allValuesFrom [ a owl:Class ; owl:oneOf ( :c :b ) ] ; owl:onProperty :builds ] .

所以你的查询将是:

prefix :      <http://www.example.org/>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

select ?x ?y {
  ?x a [ owl:allValuesFrom [ owl:oneOf/rdf:rest*/rdf:first ?y ] ] .
}
 
-----------
| x  | y  |
===========
| :a | :c |
| :a | :b |
-----------
 

您可以使用更多属性路径清理一下:

select ?x ?y {
  ?x rdf:type/owl:allValuesFrom/owl:oneOf/rdf:rest*/rdf:first ?y .
}
 

OWL与RDF不同。 SPARQL是一种RDF查询语言。 OWL可以序列化为RDF,但序列化并不总是那么漂亮,因此SPARQL不一定是查询OWL的最佳方式,即使OWL可以序列化为RDF。 这有点像通过搜索文件中的特定字节或位来搜索文档中的文本。 它可能会工作,但如果有人要更改字符编码,您可能会有相同的文本 ,但不同的字节或位,因此查询可能不再起作用。

I don't know why you'd expect ?b a :blankNode to require that ?b is a blank node. :blankNode is a blank node, which in a SPARQL query like this acts as a variable, so it's just requiring that ?b has some type. Your query as written isn't even legal. It looks like you want :indi_1 a ?b . ?b a _:blankNode instead (note the ., not a ;).

At any rate, to check whether something a blank node, look at the SPARQL 1.1 spec, and notice that there's an isBlank function. That's what you'd use to filter your results. You'd have something like this:

select * {
  ?a a ?b 
  filter isBlank(?b)
}
 

But if what you're actually looking for is the list of individuals, you actually need to look a bit more closely at the RDF serialization of your data. You don't actually care that ?b is blank, but rather that it's a restriction with the right properties. From an axiom like:

    :a builds only {:b, :c}

you end up with RDF like this:

:a a owl:NamedIndividual , owl:Thing ; a [ a owl:Restriction ; owl:allValuesFrom [ a owl:Class ; owl:oneOf ( :c :b ) ] ; owl:onProperty :builds ] .

So your query would be:

prefix :      <http://www.example.org/>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

select ?x ?y {
  ?x a [ owl:allValuesFrom [ owl:oneOf/rdf:rest*/rdf:first ?y ] ] .
}
 
-----------
| x  | y  |
===========
| :a | :c |
| :a | :b |
-----------
 

You can clean that up a little bit with more property paths:

select ?x ?y {
  ?x rdf:type/owl:allValuesFrom/owl:oneOf/rdf:rest*/rdf:first ?y .
}
 

OWL isn't the same as RDF. SPARQL is an RDF query language. OWL can be serialized as RDF, but the serialization isn't always all that pretty, so SPARQL isn't necessarily the best way to query OWL, even though OWL can be serialized to RDF. It's kind of like searching for text in a document by searching for specific bytes or bits in the file. It might work, but if someone were to change the character encoding, you could have the same text, but different bytes or bits, so the query might not work anymore.

更多推荐

本文发布于:2023-04-27 22:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329693.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   空白   类型   retrieving   node

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!