首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RDFLib (Python)到Sesame (JAVA)

RDFLib (Python)到Sesame (JAVA)
EN

Stack Overflow用户
提问于 2015-12-05 16:38:16
回答 1查看 354关注 0票数 0

在python中,我使用RDFLib编写了以下代码,并希望使用Sesame库将其转换为JAVA。

Python

代码语言:javascript
复制
 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是一个图。

上面的代码创建了以下断言:

代码语言:javascript
复制
is_extent_of only ({arc_1,arc_2,arc_4})

我能够创建相同的代码,但最后一行。有没有人知道在Sesame中是否存在与Collection相同的概念,或者我应该使用first和rest手动创建列表?

EN

回答 1

Stack Overflow用户

发布于 2015-12-05 19:26:03

Sesame的核心库目前没有方便的集合功能--这一点正在纠正;计划在下一个版本中将基本的集合处理实用程序添加到核心库中。

不过,有几个第三方芝麻扩展库提供了这种功能(例如,SesameTools库有用于此目的的RdfListUtil类)。当然,您可以手工构建一个RDF列表。基本程序相当简单,类似这样的操作应该可以做到:

代码语言:javascript
复制
    // 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);
        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34107967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档