【问题标题】:direct answer to sparql select query of equivalent class for graphdb?直接回答 sparql 选择 graphdb 等效类的查询?
【发布时间】:2020-10-31 15:43:50
【问题描述】:

我在类 EquivClass 的 Protege 中有一个“EquivalentTo”定义为 (hasObjProp some ClassA) 和 (has_data_prop 正好 1 rdfs:Literal)

GraphDB 9.4 是否有一种形式的 SPARQL 查询来获得对等价类的选择查询的“直接”答案,而无需显式收集和遍历所有组成的空白节点?基本上,我正在寻找捷径。我不希望一次性获取等效类的实例,而只是获取类定义本身。我试图寻找答案,但我不太清楚可能相关的答案在说什么。

我想要类似的东西

(hasObjProp some ClassA) 和 (has_data_prop 正好 1 rdfs:Literal)

作为对 EquivClass 上 SELECT 查询的回答。如果答案是“不可能”,那就足够了。我可以自己编写带有必要属性的空白节点遍历。

谢谢!!

文件是 -

Ontology imported into GraphDB: tester.owl - https://pastebin.com/92K7dKRZ

SELECT of all triples from GraphDB *excluding* inferred triples: tester-graphdb-sparql-select-all-excl-inferred.tsv - https://pastebin.com/fYdG37v5

SELECT of all triples from GraphDB *including* inferred triples: tester-graphdb-sparql-select-all-incl-inferred.tsv - https://pastebin.com/vvqPH1FZ

添加了响应@UninformedUser 的示例查询。例如,我使用“select *”,但实际上我对“最终结果”感兴趣,即?fp、?fo、?rop、?roo。本质上,我正在寻找比我下面的更简单和简洁的东西。我发布的示例只有一个交集(“and”子句)。在我的现实世界中,有多个具有不同数量的“和”子句的等价类。

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <http://www.semanticweb.org/ontologies/2020/9/tester#>
select * where { 
    :EquivClass owl:equivalentClass ?bneq .
    ?bneq ?p ?bnhead .
    ?bnhead rdf:first ?first .
    ?first ?fp ?fo .
    ?bn3 rdf:rest ?rest .
    ?rest ?rp ?ro .
    ?ro ?rop ?roo .
    filter(?bn3 != owl:Class && ?ro!=rdf:nil)
}

【问题讨论】:

  • 您使用哪种推理配置文件?我的意思是,例如,如果您使用 OWL 2 RL,则将表达式作为 EquivalentClasses 公理的超类部分涵盖,请参阅规范:w3.org/TR/owl2-profiles/… - 类似于 max 以外的基数限制无论如何都不支持,你使用exactly
  • 我也不明白为什么你需要“空白节点遍历”——这是什么意思?对于查询您不需要的实例数据,这仅适用于查询架构。还是我错过了什么?顺便说一下,您还需要 group bycnt 来限制基数
  • 我不是在查询这个类的实例数据——我想要没有中间空白节点的类定义组件。
  • 啊,我明白了。你想要类表达式还是更好地说所有三元组构成类表达式?这将是一个什么样的查询?我的意思是,它必须是一个CONSTRUCT 查询,即使这样我也不明白这在 SPARQL 中应该是什么样子。我的意思是,只做select ?ce where {:A owl:equivalentTo ?ce} 会很奇怪,或者至少我无法想象?ce 的绑定会是什么样子。 CONSTRUCT 查询相同,我猜你想要什么?你想要三元组,对吧?
  • 这让我很疑惑——你是如何进行空白节点遍历的?你能举个例子查询吗?

标签: select sparql graphdb


【解决方案1】:

您可以使用属性路径展开列表:

prefix :      <http://www.semanticweb.org/ontologies/2020/9/tester#> 
prefix owl:   <http://www.w3.org/2002/07/owl#> 
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix xsd:   <http://www.w3.org/2001/XMLSchema#> 
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 

select * {
  :EquivClass owl:equivalentClass/owl:intersectionOf/rdf:rest*/rdf:first ?restr.
  ?restr a owl:Restriction .
  optional {?restr owl:onProperty     ?prop}
  optional {?restr owl:cardinality    ?cardinality}
  optional {?restr owl:someValuesFrom ?class}
}

这会返回:

|   | restr   | prop           | cardinality                  | class   |
| 1 | _:node3 | :hasObjProp    |                              | :ClassA |
| 2 | _:node5 | :has_data_prop | "1" ^^xsd:nonNegativeInteger |         |

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多