我有一个org.openrdf.model.impl.GraphImpl类的图形对象,我可以退出它,也可以在它上调用.iterator()。我试图利用org.openrdf.repository.RepositoryConnection中的这个add方法:
add(info.aduna.iteration.Iteration, org.openrdf.model.Resource)到目前为止,我还没有成功地将图形的迭代器或PatternIterator转换为info.aduna.iteration.Iteration,尽管它看起来应该是一件直接的事情。任何帮助都是非常感谢的。
发布于 2015-06-30 21:38:53
首先,由于SesameVersion2.7.0,org.openrdf.model.Graph (以及默认的GraphImpl实现)被废弃,而倾向于org.openrdf.model.Model接口(以及伴随的LinkedHashModel和TreeModel实现)。如果您使用的是Sesame2.7.0或更高版本,您可能需要考虑切换到使用Model,因为它具有更丰富的特性,并且通常更容易使用(有关详细信息,请参阅userdocs中的相关部分 )。
但是,由于Model和Graph都扩展了java.util.Collection,因此都是java.lang.Iterable实例,所以您可以通过使用RepositoryConnection.add(Iterable<? extends Statement> statements, Resource... contexts)轻松地将它们添加到存储中。
换句话说,您可以这样做,而不是试图以某种方式转换为Iteration:
Model model = new LinkedHashModel();
Graph graph = new GraphImpl();
...
RepositoryConnection conn = repo.getConnection();
conn.add(model); // a Model is an Iterable, so this works
conn.add(graph); // a Graph is an Iterable, so this workshttps://stackoverflow.com/questions/31148657
复制相似问题