views:

2319

answers:

5

I'm looking for a light weight java library for dealing with RDF data. It needs to be able to parse and write RDF xml data. Also I would like it to support simple querying of an RDF model. SPARQL would be nice but not required and I don't need an inferencing capabilities.

I've used Jena, but it's not very light weight.

+2  A: 

Jena is the de-facto standard framework for building Semantic Web applications in Java, "It provides a programmatic environment for RDF, RDFS and OWL, SPARQL and includes a rule-based inference engine". What is exactly your problem with Jena ?

I think the second most widely used alternative is Sesame (http://www.openrdf.org/). Take a look at it.

If you Google for RDF and Java, you'll find other alternatives like JRDF (http://jrdf.sourceforge.net/) ... but I've not tried them.

Regards.

Guido
I have no major problems with Jena.. I was just looking for some alternatives to try out. Thanks!
delux247
+8  A: 

Jena (http://jena.sourceforge.net/) is the most widely-used at the moment, and relies heavily on community standards (OWL, SPARQL, etc). Other options are:

  • KOAN (http://kaon.semanticweb.org/), which perhaps can be used in a more scaled-down fashion, but strays from pure standards with some proprietary language and extensions.

  • Sesame (http://www.openrdf.org/), which you will find comparable to Jena unless you are interested in comparing large-scale triple retrieval efficiencies, or you need to support OWL.

  • JRDF (http://jrdf.sourceforge.net/), supposedly blending several of the RDF frameworks, but I can't say I know anything about it.

If you do not really need SPARQL or inferencing, what is the primary purpose of the RDF store? Simply pulling and transforming to different output?

.msb

msbmsb
Yes... to your question... Simply for pulling and manipulating rdf data from an RDF service. So.. I would query this service.. it would return rdf xml then I want to be able to parse it, maybe cache it for a short time and be able to perform simple queries on this smaller model.
delux247
+2  A: 

I think you need to unpack a bit what you mean by lightweight. If you mean the size of the .jar files in a Jena deployment, you may be able to leave some of them out: icu4j.jar, for example, is only used if your app handles internationalized data. However, if you are running a web-service, the deployment size probably doesn't matter.

Alternatively, if your focus is on performance, it would help if you could post some numbers and/or code snippets. There are some common pitfalls to avoid (such as not using the default OntModel if you have no need of inferencing). Some of the newer persistent store adapters, such as TDB and SDB, may give significant speed-ups with larger volumes of data. Be aware though, that some of Jena's performance penalty comes from following W3C specs quite closely. Being lightweight at the expense of full compliance may impact your app in unexpected ways in the future, especially if you plan interoperation with other data services.

I guess the other interpretation of lightweight would be the programming model. I think it's fair to say that Jena pays a tax in following closely the RDF-triples view of the world. It's a bit like programming in assembler if what you really want is a high-level language. Jena's ontology API may help you, or you may prefer an OWL-centric API like http://owlapi.sourceforge.net/. Again, if you can post some specific examples of what you're trying to achieve we can give more tailored advice. The next version of Jena will support Java generics, which will definitely help smooth the API, but there's no scheduled release date for that yet.

Ian

Ian Dickinson
Thanks for this answer. To get more specific.. I am really just looking for an RDF parser that can give me a set of triples (tuples). Then I just need to be able to do simple triple match style queries on the triple set (model). That is really all the functionality that I need.
delux247
My suggestion, I think, would be to stick with Jena or Sesame. Either of those toolkits will easily do what you ask in a few lines of code, and you may appreciate the extended functionality later in the lifetime of your project.
Ian Dickinson
+1  A: 

If we strip your needs to the bare minimum, what I read is that you would like to parse some XML (which just happens to contain RDF). If your RDF are really simple, You could build a datastructure such as a Map using StAX to handle the statements. This would ofcourse be very implementation specific and not very generic, but one the other side it would be really simple and light weight (depending on the size of the target RDF data, that is).

But I would really - like the rest of the guys here - recommend using Jena. Parsing RDF is as simple as using a Model.read

Steen
+1  A: 

I just used JRDF to read some RDF xml so I could pull out the distinct named individuals in it. it was a breeze - just one library to put on the path. The working part of the code was:

 in = new FileInputStream("MYRDF.rdf");
 final Graph jrdfMem = JRDF_FACTORY.getGraph();
 Parser parser = new GraphRdfXmlParser(jrdfMem, new MemMapFactory());
 parser.parse(in, toEscapedString(new URL("http://foo.bar.org/foo#")));
 ClosableIterable<Triple> triples = jrdfMem.find(
   ANY_SUBJECT_NODE, ANY_PREDICATE_NODE, ANY_OBJECT_NODE);
 for(Triple t: triples) {
   .....
 }
 triples.close();
paulmurray