我的问题是关于使用 SPARQL 查询一些 owl 本体,其中owl:Restrictions
被大量使用(在我的例子中,这是“细胞本体论 http://obofoundry.org/ontology/cl.html").
以下是一些典型条目的示例(以 Turtle 格式,从上述本体中提取):
### http://purl.obolibrary.org/obo/CL_0000792
obo:CL_0000792 rdf:type owl:Class ;
owl:equivalentClass [ owl:intersectionOf ( obo:CL_0000624
[ rdf:type owl:Restriction ;
owl:onProperty obo:RO_0002104 ;
owl:someValuesFrom obo:PR_000001380
]
[ rdf:type owl:Restriction ;
owl:onProperty obo:RO_0002215 ;
owl:someValuesFrom obo:GO_0050777
]
[ rdf:type owl:Restriction ;
owl:onProperty <http://purl.obolibrary.org/obo/cl#has_low_plasma_membrane_amount> ;
owl:someValuesFrom obo:PR_000001869
]
) ;
rdf:type owl:Class
] ;
rdfs:subClassOf obo:CL_0000624 ,
obo:CL_0000815 ,
[ rdf:type owl:Restriction ;
owl:onProperty obo:RO_0002104 ;
owl:someValuesFrom obo:PR_000001380
] ,
[ rdf:type owl:Restriction ;
owl:onProperty obo:RO_0002215 ;
owl:someValuesFrom obo:GO_0050777
] ,
[ rdf:type owl:Restriction ;
owl:onProperty <http://purl.obolibrary.org/obo/cl#has_low_plasma_membrane_amount> ;
owl:someValuesFrom obo:PR_000001869
] .
这里我的最终目标是将猫头鹰的等效属性转移到subClassOf
特性:
CL_0000792 rdfs:subClassOf [
rdf:type owl:Restriction ;
owl:onProperty obo:RO_0002104 ;
owl:someValueFrom obo:PR_000001380
] ;
rdfs:subClassOf [
rdf:type owl:Restriction ;
owl:onProperty obo:cl#has_low_plasma_membrane_amount ;
owl:someValueFrom obo:PR_000001869
] .
我没有实现的是从rdfs:subclass
部分,然后将它们正确地绑定到subClassOf
各种属性(然后过滤掉obo:RO_0002215
会很容易)。
编辑:当我在这里取得一些进展时,一个新的 SPARQL 查询
EDIT2:按照 Damyan Ognyanov 的回答更新了 SPARQL 查询部分,该部分忽略了 owl:intersectionOf 部分中的集合,并且也更紧凑/优雅
这是我当前的 SPARQL 查询:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX tpo: <http://www.definiens.com/ontologies/TissuePhenomicsOntology>
PREFIX cl: <http://purl.obolibrary.org/obo/cl.owl>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX efo: <http://www.ebi.ac.uk/efo/efo.owl>
CONSTRUCT {
?cell rdfs:subClassOf [ rdf:type owl:Restriction ;
owl:onProperty ?cellProp ;
owl:someValuesFrom ?cellPropValue
] .
?cellProp ?cellPropProp ?cellPropObj .
?cellPropValue ?cellPropValueProp ?cellPropValuePropValue .
?cell ?cellProp2 ?cellProp2Obj .
}
FROM named cl:
FROM named tpo:
WHERE {
# query cl to get our information
graph cl:
{
?cell (rdfs:subClassOf|(owl:equivalentClass/owl:intersectionOf/rdf:rest*/rdf:first)) ?x .
?x owl:onProperty ?cellProp ;
owl:someValuesFrom ?cellPropValue .
?cellProp ?cellPropProp ?cellPropObj .
?cellPropValue ?cellPropValueProp ?cellPropValuePropValue .
?cell ?cellProp2 ?cellProp2Obj .
}
# limit ?cell to the entries already present in TPO
graph tpo:
{
?cell rdfs:subClassOf* obo:CL_0000000 .
}
}
如果您更换CONSTRUCT
部分与SELECT *
那么看来所有变量都已正确分配,信息就在那里。
我仍然缺少的是一个适当的CONSTRUCT
部分重建“有些复杂”owl:Property
限制。因此,此查询主要返回一长串空白节点,例如 Protege 无法正确解析这些节点。
@AKSW 还正确地指出,SPARQL 可能不是查询和构建 OWL 图的首选工具。这里确实清楚地表明,人们需要知道精确的数据结构才能构建有效的查询,至少以这种方式。
?cell (rdfs:subClassOf|(owl:equivalentClass/owl:intersectionOf/rdf:rest*/rdf:first)) ?x 。
?x owl:onProperty ?cellProp ;
owl:someValuesFrom ?cellPropValue 。
?cellProp ?cellPropProp ?cellPropObj 。
?cellPropValue ?cellPropValueProp ?cellPropValuePropValue 。
?cell ?cellProp2 ?cellProp2Obj 。