我的问题是使用SPARQL查询一些猫头鹰本体,其中owl:Restrictions
被大量使用(在我的情况下,这是“Cell Ontology”)。
以下是一些典型条目的示例(以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。
owl:intersectionOf
的值是RDF列表,上面的Turtle片段使用RDF列表语法来枚举owl:intersectionOf
集合的成员(例如,条目包含在(
和)
之间)。
因此,您还应该在属性路径中包含rdf:rest*/rdf:first
属性,因为这些属性用于构造集合。
对于查询,我将引入一个额外的变量来绑定感兴趣的限制并使用它来获取owl:onProperty
和owl:someValuesFrom
的值,例如,你的WHERE
子句可能类似于:
?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 .