在python中,我使用RDFLib编写了以下代码,并希望使用Sesame库将其转换为JAVA。
Python
restrictionNode= BNode()
g.add((nodeIndividualName,rdftype,restrictionNode))
g.add((restrictionNode, rdftype, OWL.Restriction))
g.add((restrictionNode, OWL.onProperty, rno.is_extent_of))
listClassNode = BNode()
g.add((restrictionNode, OWL.allValuesFrom, listClassNode))
g.add((listClassNode, rdftype, OWL.Class))
arcListNode = BNode()
g.add((listClassNode, OWL.oneOf,arcListNode ))
Collection(g, arcListNode,arcIndividualList)在上面的代码中,g是一个图。
上面的代码创建了以下断言:
is_extent_of only ({arc_1,arc_2,arc_4})我能够创建相同的代码,但最后一行。有没有人知道在Sesame中是否存在与Collection相同的概念,或者我应该使用first和rest手动创建列表?
发布于 2015-12-05 19:26:03
Sesame的核心库目前没有方便的集合功能--这一点正在纠正;计划在下一个版本中将基本的集合处理实用程序添加到核心库中。
不过,有几个第三方芝麻扩展库提供了这种功能(例如,SesameTools库有用于此目的的RdfListUtil类)。当然,您可以手工构建一个RDF列表。基本程序相当简单,类似这样的操作应该可以做到:
// use a Model to collect the triples making up the RDF list
Model m = new TreeModel();
final ValueFactory vf = SimpleValueFactory.getInstance();
Resource current = vf.createBNode(); // start node of your list
m.add(current, RDF.TYPE, RDF.LIST);
// iterate over the collection you want to convert to an RDF List
Iterator<? extends Value> iter = collection.iterator();
while (iter.hasNext()) {
Value v = iter.next();
m.add(current, RDF.FIRST, v);
if (iter.hasNext()) {
Resource next = vf.createBNode();
m.add(current, RDF.REST, next);
current = next;
}
else {
m.add(current, RDF.REST, RDF.NIL);
}
}https://stackoverflow.com/questions/34107967
复制相似问题