Monalizza
Monalizza

Reputation: 43

number of RDF resources with specific property

How to get the number of RDF resources (subjects) associated with a specific property?

I don't want to use the list statements iterator to count the number of unique resources because this will also count the number of statements with the same subjects but different objects. Isn't there just a method that just returns the number of unique subjects of a particular property?

StmtIterator iter = model1.listStatements();
// print out the predicate, subject and object of each statement

int u=0;
while (iter.hasNext()) {
    Statement stmt      = iter.nextStatement();  // get next statement
    Resource  subject   = stmt.getSubject();     // get the subject
    Property  predicate = stmt.getPredicate();   // get the predicate
    RDFNode   object    = stmt.getObject();    
    u++;
}

Upvotes: 0

Views: 66

Answers (1)

AndyS
AndyS

Reputation: 16630

One of Model.listResourcesWithProperty operations.

Model javadoc

Upvotes: 1

Related Questions