1

In Model.filter(), I would like to store the objects. But if the object is a blank node, I would like to retrieve the corresponding triple and store the real object.

The problem in Model.filter() is that If the blank node(object) is _:a , the returning "Value" will be something like :xxxxxxxxxxa. this is fine but when I have (:xxxxxxxxxxa,p,o) in the model, trying to use model.filter(_:xxxxxxxxxxa,null,null) fails.

   java.util.NoSuchElementException
        at org.openrdf.model.impl.AbstractModel$ValueSet$ValueSetIterator.
next(AbstractModel.java:493)
        at org.openrdf.model.impl.AbstractModel$ValueSet$ValueSetIterator.next(AbstractModel.java:470)

This is the source code which explain the problem in more detain:

    private Model triples;

    private Value filterBySubjectAndPredicate(Resource subject, IRI Predicate, IRI nextPredicate) {

    Value tempValue = triples.filter(subject, vf.createURI(Predicate.getFullIRI()), null).
objects().iterator().next();
            BNode bnode = null;
            if(tempValue instanceof BNode) {
            bnode = vf.createBNode(tempValue.toString());
            return triples.filter(bnode, vf.createURI(nextPredicategetFullIRI()), null).
objects().iterator().next();
            } else
            return triples.filter(subject, vf.createURI(Predicate.getFullIRI()), null).
objects().iterator().next();
        }

Thank you in advance.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
jd466
  • 547
  • 1
  • 6
  • 20
  • 1
    It's not clear to me what you're trying to do. Can you add a code example that illustrates the problem? – Jeen Broekstra Jan 17 '16 at 18:33
  • Hi, thanks. Yes I will edit the post now. – jd466 Jan 17 '16 at 21:03
  • 1
    It's still not very clear to be honest, as this is not a complete and minimal example (it would also be good if you could fix indentation to make it easier to read). However: why are you creating a new BNode object, instead of just reusing the existing one? – Jeen Broekstra Jan 18 '16 at 02:18
  • Hi, thanks. I changed the code as you suggested and now it works. Casting directly. – jd466 Jan 18 '16 at 08:52

0 Answers0