SPARQL:如何将 owl:equivalentClass 转移到 rdfs:subClassOf (owl:Restriction) 属性?
SPARQL: how to transfer owl:equivalentClass to rdfs:subClassOf (owl:Restriction) properties?
我的问题是关于使用 SPARQL 查询一些 owl ontology,其中 owl:Restrictions
被大量使用(在我的例子中是“Cell Ontology”)。
这是一些典型条目的示例(以 Turtle 格式,从上面提到的 ontology 中提取):
### 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
] .
这里我的最终目标是将 owl 等效属性转移到 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 部分中的集合,并且还 compact/elegant
这是我当前的 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 .
}
}
如果您用 SELECT *
替换 CONSTRUCT
部分,那么看起来所有变量都已正确分配,信息就在那里。
我仍然缺少的是重建 "somewhat convoluted" owl:Property
限制的适当 CONSTRUCT
部分。因此,此查询主要是 returns 一长串空白节点,例如,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 .
我的问题是关于使用 SPARQL 查询一些 owl ontology,其中 owl:Restrictions
被大量使用(在我的例子中是“Cell Ontology”)。
这是一些典型条目的示例(以 Turtle 格式,从上面提到的 ontology 中提取):
### 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
] .
这里我的最终目标是将 owl 等效属性转移到 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 部分中的集合,并且还 compact/elegant
这是我当前的 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 .
}
}
如果您用 SELECT *
替换 CONSTRUCT
部分,那么看起来所有变量都已正确分配,信息就在那里。
我仍然缺少的是重建 "somewhat convoluted" owl:Property
限制的适当 CONSTRUCT
部分。因此,此查询主要是 returns 一长串空白节点,例如,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 .