Back in January 2005, being annoyed with the verboseness of a certain RDF API for Java, I tried to come up with a friendlier way of manipulating generic RDF from Java. My experiments never went anywhere and I forgot about it after a few days. I just found the files on my hard disk and think this snippet is worth sharing:
public void testCreatePPD() {
Document profile = RDF.newDocument();
Resource richard = RDF.resource();
Resource homepage = RDF.URI("http://richard.cyganiak.de/");
profile.assert(profile, "rdf:type",
"foaf:personalProfileDocument");
profile.assert(profile, "foaf:primaryTopic",
richard);
profile.assert(richard, "foaf:name",
RDF.literal("Richard Cyganiak"));
profile.assert(richard, "foaf:mbox",
RDF.URI("mailto:richard@cyganiak.de"));
profile.assert(richard, "foaf:homepage",
homepage);
profile.assert(homepage, "dc:title",
RDF.literal("Richard Cyganiak's Homepage"));
profile.assert(homepage, "dc:description",
RDF.literal("Meine Homepage (deutschsprachig)", "de"));
ResourceSet people = profile.getAll("foaf:Person");
Iterator it = people.iterator();
while (it.hasNext()) {
Resource person = (Resource) it.next();
String name = profile.get(person, "foaf:name").asString();
System.out.println(name);
}
}
That looks pretty nice, I think. Wrapping Jena’s Graph interface into such a developer-friendly API wouldn’t be all that hard.
Of course, compared to ActiveRDF that code still looks as unfun as having your teeth pulled.