我想更改 Jena TriplePath (org.apache.jena.sparql.core.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?
问题是,如何使用我创建的新节点设置 TriplePath tp 的任何节点(域/谓词/范围)?有什么办法吗?
最佳答案
您需要创建一个新路径并将其分配给tp
。 TriplePath
是不可变的,Jena 中的 SPARQL 代数的其余部分也是如此(不应该使用任何方法来打败它!)。
对于更复杂的设置,有一个带有变量的模板并使用:
TriplePath Substitute.substitute(TriplePath triplePath, Binding binding)
关于java - 如何更改 Jena 中 TriplePath 的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38186703/