2

我想更改 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?

问题是,如何使用我创建的 newNode 设置 TriplePath tp 的任何节点(域/谓词/范围)?有什么办法吗?

4

1 回答 1

1

您需要创建一个新路径并将其分配给tp. TriplePaths 是不可变的,就像 Jena 中的 SPARQL 代数的其余部分一样(不应该使用任何方法来解决这个问题!)。

对于更复杂的设置,有一个带有变量的模板并使用:

TriplePath Substitute.substitute(TriplePath triplePath, Binding binding)
于 2016-07-04T16:49:45.123 回答