简体   繁体   中英

Count a specific relationship in OWL File using sparql query

I want to count assertions of a specific relationship in OWL file. if following is my whole 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>

then sparql query should give me something like:-

       SynonymOf = 4 (i.e 4 assertions for <SynonymOf> relation

I intend to run the query on jena fuzeki.

A straightforward way would be:

PREFIX : <http://example.com#>
SELECT (count(?o) as ?count)
WHERE {
  ?s :SynonymOf ?o
} 

However, for the binding to be assigned to specific objects, you might want to consider using Group By :

PREFIX : <http://example.com#>
SELECT ?s (count(?o) as ?count)
WHERE {
  ?s :SynonymOf ?o
}
GROUP BY ?s
SELECT (COUNT(?s) as ?SynonymOf)
WHERE {
    GRAPH ?g {?s SynonymOf ?o }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM