jaykio77
jaykio77

Reputation: 391

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.

Upvotes: 1

Views: 487

Answers (2)

Artemis
Artemis

Reputation: 3301

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

Upvotes: 3

ffa
ffa

Reputation: 797

SELECT (COUNT(?s) as ?SynonymOf)
WHERE {
    GRAPH ?g {?s SynonymOf ?o }
    }

Upvotes: 0

Related Questions