0

I have the following code in python using RDFLib and I want to translate it into JAVA using Sesame libraries.

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)

In the above code, g is a graph.

the above code creates the following assertion:

is_extent_of only ({arc_1,arc_2,arc_4})

I was able to create the same code but the last line. Does anyone know if there is the same notion as Collection in Sesame APIs or I should manually create the list using first and rest?

msc87
  • 943
  • 3
  • 17
  • 39

1 Answers1

1

Sesame's core library currently has no convenience functions for Collections - this is being remedied though; there are plans to add basic collection handling utilities to the core libraries in the next release.

There are several third-party Sesame extension libraries that offer this kind of thing though (for example, the SesameTools library has the RdfListUtil class for this purpose). And of course you can construct an RDF List by hand. The basic procedure is fairly simple, something like this ought to do the trick:

    // 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);
        }
    }
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73