Processing SIOC feeds with Jenabean

February 26th, 2009 § 1

This is a simple example of using jenabean’s “Thing” class to process SIOC data. The full example is available here.
SIOC is an OWL ontology for integrating and exchanging online community information.  It’s one of the few but growing public ontologies that have some adoption where you can find examples in the wild.  Jenabean makes it very easy to extract information using the SIOC vocabulary.   Assuming your Jena project is setup, all that’s required is for you to download the jenabean jar file to get started.  The latest snapshot build (0.9) contains a ready made interface for working with SIOC feeds or data.  First create a simple class with a static main…

public class SiocExample {
public static void main(String[] args) {...}
}

SIOC has some inverse properties and other interesting relationships that an inferencer can make use of, so we’ll begin with a Jena OntModel with inferencing:

OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
m.setNsPrefix("sioc", "http://rdfs.org/sioc/ns#");
m.read("http://demo.openlinksw.com/tutorial/sioc.vsp");

On line 2 I’m setting a prefix so that if and when you print out your model it will use the standard “sioc” prefix before all the properties and classes as you’d see in their documentation and examples.  Line 3  reads in some SIOC RDF off the internet.  It’s a set of openlink tutorial documents encoded as SIOC.  You’ll need to have a connection to the internet for that to work of course.

Sioc space =
new Thing("http://demo.openlinksw.com/tutorial/", m).
as(Sioc.class);

Lines 4-6 create a “thing” which is connected to the model, giving us a handle to speak “SIOC” in a way that’s natural to Java developers, and their IDE’s. The URI points to the root “space” for the SIOC document.  From their we can get to the rest of the graph without mentioning specific URI’s.  Now we can ask the space for it’s name:

System.out.println("found space " + space.name());

There are many other accessor methods you can try, but it’s important to know what your “thing” is pointing at as the SIOC interface supports the entire vocabulary.  Now that you’ve read the space name, you can then look at all the SIOC Container children:

for (Thing thing : space.space_of()) {
Sioc container = thing.as(Sioc.class);
System.out.println(container.description());
System.out.println("\tcontains " + container.container_of().size() + " items.");
Individual i = (Individual)thing.getResource().as(Individual.class);
System.out.println("\tAKA..." + i.getURI());
}

Line 7 loops for each container that has this space. Again, we need to go ahead and “polymorph” the thing into a an Sioc thing. Next, Line 9 gets it’s sioc:description literal. You could then dig down deeper into the data, the example just stops by printing out the size of the documents list within the container. Finally line 11 shows how you can get back to the Jena api if necessary. “Things” are just wrappers on Jena Resources.

Reblog this post [with Zemanta]

Tagged:

§ One Response to “Processing SIOC feeds with Jenabean”

What's this?

You are currently reading Processing SIOC feeds with Jenabean at The Web Semantic.

meta