使用 sparql 查询计算 OWL 文件中的特定关系
Count a specific relationship in OWL File using sparql query
我想计算 OWL 文件中特定关系的断言。如果以下是我的全部 Ontology:-
<owl:NamedIndividual rdf:about="file:/C:/myOnt.owl#comfort">
<SynonymOf rdf:resource="file:/C:/myOnt.owl#impunity"/>
<SynonymOf rdf:resource="file:/C:/myOnt.owl#sooth"/>
<SynonymOf rdf:resource="file:/C:/myOnt.owl#ease"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="file:/C:/myOnt.owl#population">
<SynonymOf rdf:resource="file:/C:/myOnt.owl#habitation"/>
</owl:NamedIndividual>
然后 sparql 查询应该给我这样的东西:-
SynonymOf = 4 (i.e 4 assertions for <SynonymOf> relation
我打算 运行 关于 jena fuzeki 的查询。
SELECT (COUNT(?s) as ?SynonymOf)
WHERE {
GRAPH ?g {?s SynonymOf ?o }
}
一个简单的方法是:
PREFIX : <http://example.com#>
SELECT (count(?o) as ?count)
WHERE {
?s :SynonymOf ?o
}
但是,对于要分配给特定对象的绑定,您可能需要考虑使用 Group By
:
PREFIX : <http://example.com#>
SELECT ?s (count(?o) as ?count)
WHERE {
?s :SynonymOf ?o
}
GROUP BY ?s
我想计算 OWL 文件中特定关系的断言。如果以下是我的全部 Ontology:-
<owl:NamedIndividual rdf:about="file:/C:/myOnt.owl#comfort">
<SynonymOf rdf:resource="file:/C:/myOnt.owl#impunity"/>
<SynonymOf rdf:resource="file:/C:/myOnt.owl#sooth"/>
<SynonymOf rdf:resource="file:/C:/myOnt.owl#ease"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="file:/C:/myOnt.owl#population">
<SynonymOf rdf:resource="file:/C:/myOnt.owl#habitation"/>
</owl:NamedIndividual>
然后 sparql 查询应该给我这样的东西:-
SynonymOf = 4 (i.e 4 assertions for <SynonymOf> relation
我打算 运行 关于 jena fuzeki 的查询。
SELECT (COUNT(?s) as ?SynonymOf)
WHERE {
GRAPH ?g {?s SynonymOf ?o }
}
一个简单的方法是:
PREFIX : <http://example.com#>
SELECT (count(?o) as ?count)
WHERE {
?s :SynonymOf ?o
}
但是,对于要分配给特定对象的绑定,您可能需要考虑使用 Group By
:
PREFIX : <http://example.com#>
SELECT ?s (count(?o) as ?count)
WHERE {
?s :SynonymOf ?o
}
GROUP BY ?s