You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Dick Murray <di...@unit4.com> on 2011/08/22 18:05:25 UTC

model.listStatements() not behaving as expected.

Hello all.

I have the following statements;

<http://www.example.org/ooo/id/operator/example>
                rdfs:label "No language tag" ;
                rdfs:label "@en language tag"@en ;
                rdfs:label "Another @en language tag"@en ;
                rdfs:label "@fr language tag"@fr ;
                rdfs:label "test"@x ;
                rdfs:label "test"@y .

I'm using the following code to create a new model containing a filtered set of statements based on the language tag;

                public String getLabel(String language) {
                                Model m = ModelFactory.createDefaultModel().add(this.model.listStatements(this.resource, RDFS.label, (String)null, language));
                                System.out.println(m.size());
                                StmtIterator i = m.listStatements();
                                Statement s;
                                while (i.hasNext()) {
                                                s = i.nextStatement();
                                                System.out.println(s.toString());
                                }
                }

However if I pass in "en" I get a model with 6 statements..?

[http://www.example.org/ooo/id/operator/example, http://www.w3.org/2000/01/rdf-schema#label, "@en language tag"@en]
[http://www.example.org/ooo/id/operator/example, http://www.w3.org/2000/01/rdf-schema#label, "Another @en language tag"@en]
[http://www.example.org/ooo/id/operator/example, http://www.w3.org/2000/01/rdf-schema#label, "@fr language tag"@fr]
[http://www.example.org/ooo/id/operator/example, http://www.w3.org/2000/01/rdf-schema#label, "No language tag"]
[http://www.example.org/ooo/id/operator/example, http://www.w3.org/2000/01/rdf-schema#label, "test"@x]
[http://www.example.org/ooo/id/operator/example, http://www.w3.org/2000/01/rdf-schema#label, "test"@y]

If execute the following I get 0 statements;

this.model.listStatements(this.resource, RDFS.label, "test", (String)null)

If I execute the following I get 1 statement;

this.model.listStatements(this.resource, RDFS.label, "test", "x")

The javadoc states that the subject/predicate/object will match all if null. But it doesn't mention the language.

Can I get an iterator over the statements which match a subject/predicate and language tag or do I need to do my own filtering..?