[
https://issues.apache.org/jira/browse/JENA-362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13526951#comment-13526951
]
François-Paul Servant commented on JENA-362:
--------------------------------------------
Here's a modification to com.hp.hpl.jena.rdf.model.impl.ModelCom that seems to
patch the problem:
@Override
public StmtIterator listStatements( Resource S, Property P, String O,
String L ) {
// these 2 lines are the code of jena 2.7.4
// return O == null ? listStatements(S, P, Node.ANY)
// : listStatements( S, P, Node.createLiteral( O, L, false ) );
if (O != null) {
// this is not OK when L is null: returns only the statements
whose lang is ""
// return listStatements( S, P, Node.createLiteral( O, L, false
) );
if (L != null) return listStatements( S, P, Node.createLiteral(
O, L, false ) );
// there's maybe a better way!
return new StringFilteredStmtIterator(O, listStatements(S, P,
Node.ANY));
} else {
return new LangFilteredStmtIterator(L, listStatements(S, P,
Node.ANY));
}
}
private class StringFilteredStmtIterator extends
FilterKeepIterator<Statement> implements StmtIterator {
public StringFilteredStmtIterator(final String str,
Iterator<Statement> it ) {
super(
new Filter<Statement>() {
@Override public boolean
accept(Statement s) {
RDFNode o = s.getObject();
if (o instanceof Literal) {
if (str == null) return
true; // should not happen
return
(str.equals(((Literal) o).getString()));
}
return false;
}
},
it );
}
public Statement nextStatement() { return next(); }
}
private class LangFilteredStmtIterator extends
FilterKeepIterator<Statement> implements StmtIterator {
public LangFilteredStmtIterator(final String l, Iterator<Statement>
it ) {
super(
new Filter<Statement>() {
@Override public boolean
accept(Statement s) {
RDFNode o = s.getObject();
if (o instanceof Literal) {
if (l == null) return
true;
return
(l.equals(((Literal) o).getLanguage()));
}
return false;
}
},
it );
}
public Statement nextStatement() { return next(); }
}
> model.listStatements(s,p,o,lang) has problems with null values in the third
> and forth argument
> ----------------------------------------------------------------------------------------------
>
> Key: JENA-362
> URL: https://issues.apache.org/jira/browse/JENA-362
> Project: Apache Jena
> Issue Type: Bug
> Components: Jena
> Affects Versions: Jena 2.7.4
> Reporter: François-Paul Servant
> Priority: Minor
>
> 1) model.listStatements(s,p,null,lang) doesn't filter on lang param
> 2) model.listStatements(s,p,o,null) only returns statements whose object has
> lang "" (when o != null)
> TEST 1
> import org.junit.Test;
> import com.hp.hpl.jena.rdf.model.*;
> public class LstStmt1 {
> @Test
> public final void test() {
> Model m = ModelFactory.createDefaultModel();
> Resource s = m.createResource("http://www.a.com/s");
> Property p = m.createProperty("http://www.a.com/p");
> m.add(s,p,m.createResource("http://www.a.com/o"));
> m.add(s,p,"texte","fr");
> m.add(s,p,"text","en");
>
> StmtIterator it = m.listStatements(s, p, null,"en");
> // list all the statements - not what one can expect
> for (;it.hasNext();) {
> System.out.println(it.next());
> }
> }
> }
> TEST2
> public class LstStmt2 {
> @Test
> public final void test() {
> Model m = ModelFactory.createDefaultModel();
> Resource s = m.createResource("http://www.a.com/s");
> Property p = m.createProperty("http://www.a.com/p");
> m.add(s,p,"text","en");
> m.add(s,p,"text");
>
> StmtIterator it = m.listStatements(s, p,"text",null);
> // should list the 2 statements, but doesn't: only the one
> without lang
> for (;it.hasNext();) {
> System.out.println(it.next());
> }
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira