SPARQL聚合查询无效

问题描述 投票:1回答:1

我正在尝试编写SPARQL查询以从RDF中的本体中提取某些属性和标签。我在python 2.7(操作系统:Ubuntu 16.04,64位)中使用rdflib 4.2.2,它允许我在SPARQL 1.1中运行查询。本体论是人体的解剖学,所有的器官都有自己的阶级。它的组织使得这些器官具有超级类别,以及具有标签的其他属性,例如hasRelatedSynonymsomeValuesFrom。以下是本体的示例,具有类限制和属性的单个类:

<owl:Class rdf:about="http://human.owl#NCI_C12832">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Conus_Medullaris</rdfs:label>
<rdfs:subClassOf rdf:resource="http://human.owl#NCI_C33969"/>
<rdfs:subClassOf>
   <owl:Restriction>
      <owl:onProperty rdf:resource="http://human.owl#UNDEFINED_part_of"/>
      <owl:someValuesFrom rdf:resource="http://human.owl#NCI_C12464"/>
   </owl:Restriction>
</rdfs:subClassOf>
<oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid5111"/>

有些类对单个属性有多个值的限制,这就是我尝试使用group_concat将所有这些值放在一行中的原因,以便在一行中获得有关类的所有相关信息。

这是我正在尝试运行的查询:

querytrial4=graph.query("""SELECT ?node ?nodeLabel ?superclass ?superclassLabel (group_concat(DISTINCT ?node2) as ?node2s) (group_concat(DISTINCT ?node2Label) as ?node2Labels) where {
?node rdf:type owl:Class .
?node rdfs:subClassOf ?superclass .
OPTIONAL { 
    ?node rdfs:subClassOf ?restriction .
    ?restriction a owl:Restriction .
    ?restriction owl:someValuesFrom ?node2 .
    ?node2 rdfs:label ?node2Label } 
?node rdfs:label ?nodeLabel .
?superclass rdfs:label ?superclassLabel .
}
group by ?node ?nodeLabel ?superclass ?superclassLabel ?node2 ?
node2Label
LIMIT 10""")

正如rdf4j论坛上的几个贡献者所建议的那样,我已将限制及其属性放在OPTIONAL块中,因为并非所有类都具有这些属性。但是,当我尝试运行查询时,我得到一个错误,说变量?node2Label是未绑定的。为什么即使变量在可选块内部也会抛出此错误,我该如何解决此查询?任何建议将不胜感激。我已经附加了本体,以防有人想尝试自己运行查询。

可以从此链接下载本体。它在商店/解剖/ human.owl

https://github.com/AgreementMakerLight/AML-Jar

sparql
1个回答
0
投票

我认为你的查询中的问题可能是?node2Label之间的空白,因为你在? node2Label语句之前写了LIMIT

我从链接下载了人类本体,删除了那个空白区域,在GraphDB上运行了查询,运行正常。

© www.soinside.com 2019 - 2024. All rights reserved.