2016-07-04 62 views
2

我想更改一个Jena TriplePath(org.apache.jena.sparql.core.TriplePath)的节点,但我还没有找到任何方式。想象一下,我有这样的代码:如何更改Jena中TriplePath的节点?

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? 

的问题是,我怎么能设置与newNode的TriplePath TP的任一节点(域/谓语/范围),我创建了?有什么方法吗?

回答

1

您需要创建一个新路径并将其分配给tpTriplePath s是不可变的,就像耶拿的SPARQL代数的其余部分一样(不应使用任何方法来打败这个!)。

对于更复杂的设置,有变量和使用模板:

TriplePath Substitute.substitute(TriplePath triplePath, Binding binding)