Question

I have a file describing people with the help of FOAF. In Jena I am trying to parse all ages from the profiles and noticed that my listStatements and listObjectsOfProperty gives me different results. I could not easily find any help from the javadocs or other documentation.

I have the following code for querying with listStatments:

StmtIterator iter = this.foafmodel.listStatements(
     (Resource) null, 
     this.foafmodel.createProperty("http://xmlns.com/foaf/0.1/age"), 
     (RDFNode) null);

And this is the code for listObjectsOfProperty:

Property foafAge = this.foafmodel.createProperty("http://xmlns.com/foaf/0.1/age");
NodeIterator iter = this.foafmodel.listObjectsOfProperty(foafAge);

In this case listStatements iterator iterates 38 times while the listObjectsOfProperty only 20 times. Can someone explain to me what is the difference between these two implementations?

Was it helpful?

Solution

Let us assume that your data contains multiple triples with your property :p referencing the same object :o, like so:

:s1 :p :o .
:s2 :p :o .

At first glance, it would appear to me that listObjectsOfProperty are giving you all individuals that are referenced by your property without duplication. We can confirm this by digging into the implementation that depends on GraphUtil#listObjects(...). The code uses a Set<Node> to aggregate all of the objects. As a result, you should only get back a single iteration with the element :o.

The other method, listStatements should return to you a statement/triple for every time that property is used. In the example model above, you would/should get two results, one for each statements containing :p.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top