2

I want to change a node of a Jena TriplePath (org.apache.jena.sparql.core.TriplePath), but I haven't found any manner. Imagine I have this code:

TriplePath tp = null;
....
//tp has been defined and not null

Node domain = tp.getSubject();
Node predicate = tp.getPredicate();
Node range = tp.getObject();
Node newNode = NodeFactory.createURI("http://www.example.com/example/example");

//And now? How can I set a Node (domain/predicate/range) of tp?

The question is, how can I set any Node (domain/predicate/range) of the TriplePath tp with the newNode I've created? Is there any manner?

tremendows
  • 4,262
  • 3
  • 34
  • 51

1 Answers1

1

You need to create a new path and assign it to tp. TriplePaths are immutable, as is the rest of the SPARQL algebra in Jena (any ways to defeat this should not be used!).

For more complex setups, have a template with variables and use:

TriplePath Substitute.substitute(TriplePath triplePath, Binding binding)
tremendows
  • 4,262
  • 3
  • 34
  • 51
AndyS
  • 16,345
  • 17
  • 21