【问题标题】:RDFLib (Python) to Sesame (JAVA)RDFLib (Python) 到芝麻 (JAVA)
【发布时间】:2015-12-05 16:38:16
【问题描述】:

我在 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 APIs 中是否有与 Collection 相同的概念,或者我应该使用 first 和 rest 手动创建列表?

【问题讨论】:

    标签: java python assertion sesame rdflib


    【解决方案1】:

    Sesame 的核心库目前没有为 Collections 提供便利的函数——不过这个问题正在修复中;计划在下一个版本中将基本的收集处理实用程序添加到核心库中。

    有几个第三方 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);
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-30
      • 2012-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多