W3C home > Mailing lists > Public > www-rdf-interest@w3.org > January 2005

Re: Object triple Mapping

From: Henry Story <henry.story@bblfish.net>
Date: Fri, 7 Jan 2005 19:15:43 +0100
Message-Id: <24FBA46C-60D8-11D9-8C94-000A95D9FA7A@bblfish.net>
Cc: jena-dev@yahoogroups.com, Max Voelkel <max@xam.de>, bloged <users@bloged.dev.java.net>, kowari-general@lists.sourceforge.net
To: www-rdf-interest@w3.org

I have implemented a little rdfreactor like library[0][1] over the  
vacations for use in BlogEd. This allows me to create very simple  
interfaces using a java beans like pattern that contain all the  
information about the Ontology. A Simple Example will help a little  
here [2]

public interface AtomEntry {
     String BASE = "http://example.com/test/atom.owl#";
     String RDF_TYPE = BASE+"Entry";

     String RDF_author = BASE + "author";
     void setAuthor(AtomPerson person);
     AtomPerson getAuthor();

      * An entry can have any number of contributors
     String RDF_contributor = BASE + "contributor";
     AtomPerson addContributor(AtomPerson person);
     Collection getAllContributor();

      * An entry has a title.
      * This should be a subclass of content that only takes as types  
"text","text/html" and "text/xhtml"
      * I need to figure out how I could specify this from java.
     String RDF_title = BASE + "title";
     AtomContent setTitle(AtomContent title);
     AtomContent getTitle();


It is then really easy to create objects implementing this interfaces:

      AtomPerson hjs = (AtomPerson)  
      hjs.setName("Henry Story");
      AtomEntry header = (AtomEntry)  
      header.setTitle(new AContent("A Unit Test Blog"));
      header.setSummary(new AContent("The best way to develop quickly is  
to develop flexibly with unit tests"));

This makes development of RDF aware programs in Java incredibly easy.  
And it also makes it much easier to explain RDF I think to java  
programmers. With a little more work (or waiting for java 5.0  
annotations) it will be very easy to specify the owl ontology  
completely from an java file, and use those files to generate the  

There are 4 million java programmers out there. I don't think it would  
take them much more than a few hours to understand ( an polished  
version of) the above. That would be w few million programmers who  
would understand RDF in a matter of a few hours.

Henry Story

[0] All published under a BSD license

On 24 Dec 2004, at 21:12, Henry Story wrote:

> Thanks Max. rdfreactor [1] looks very much like what I had in mind.
> To describe my (very initial thoughts) a little more I wrote the  
> following on the Sesame web site [2]
> The problem is essentially the same that JDO and hibernate are  
> attempting to solve. But you are right: those tools attempt to work on  
> persistence where the starting point is the java objects and classes.  
> This is natural when working with Relational databases, as arguably  
> the relational database are a level of abstraction lower than the OO  
> code. In the case of RDF and OWL the database may have the upper hand.  
> OWL is very close to a declarative form of OO programming, but allows  
> multiple inheritance, and lots of other nice features. In my case,  
> writing BlogEd, I did in fact start from an OWL ontology, then wrote  
> some java classes that mapped the OWL classes. So for example I used  
> the Atom Entry class which in OWL I defined as having the following  
> relations
>      author: which maps an entry to a Person
>      id: which maps an entry to a uri (identifying the different  
> versions of an entry)
>      title: which maps an entry to a String
>      content: which maps an entry to a Content object
>      created: which maps an entry to a Date
>      ...
> in java this would of give a class such as
> class Entry {
>      Person author;
>      Node id:
>      String title;
>      Content content;
>      Date created;
>      ...
>      //setter and getter methods
> }
> Now if this Entry class is created directly from the OWL spec, this  
> would be very nice. Perhaps others are in a situation where the  
> inverse would be nice: the creation of an OWL ontology or mapping from  
> some class specifications.
> RDF does make a lot of things very easy though. Every RDF object is a  
> URI. These play a role similar it seems to me to a java pointer,  
> except that they can be universal. So we would like to ask the  
> database questions such as "give me all the Entry objects", and have a  
> java.util.List<Entry> returned. In the case of BlogEd, which uses the  
> Sesame filesystem database, where the calls are cheap, and which does  
> not need to make a lot of database queries, all the Entries in the  
> list could be lazily evaluated: when one makes a call such as
> entry.getTitle()
> the object would get the relevant string from the RDF Database, ie:  
> the code could be implemented as
>     public String getTitle() {
>        if (title == null) {
>            StatementIterator s =graph.getStatements(this.id,  
> atom.title, null);
> 		   if (s != null)
>              title = (String)s.next().getObject();
>         }
>         return title;
>      }
> Perhaps other applications would rather the database do the caching,  
> and fill up the object during the initial factory construction call.  
> In any case a lot of the code here is repetitive, and it seems easily  
> automated. Perhaps this is the kind of job to do using aspects,  
> perhaps dynamic proxies, perhaps using java 5 tags (which comes down  
> to using aspects but in an easier to understand manner) as the next  
> version of hibernate has chosen to do. The question should perhaps be:  
> what remains to be hand coded? Probably the application specific data  
> verification procedures.
> Anyway it seems like there is space here for different solutions that  
> help facilitate the mapping between java objects and an rdf database  
> in the way hibernate helps between java objects and relational  
> databases. I thought I had better check out first to see what is  
> available before rolling my own. Perhaps rdfreactor is the tool I was  
> looking for :-)
> Henry
> On 24 Dec 2004, at 14:08, Max Völkel wrote:
>> Hi Henry,
>> HS> Does anyone here have any thoughts on how best to achieve object
>> HS> tripple mapping in rdf space? There are many tools to map POJO  
>> (Plain
>> HS> old Java Objects) to relational databases now: Hibernate [1], JDO  
>> [2],
>> HS> and others.
>> I am not sure, whether this meets your requirements, but there is a
>> project called RDFReactor [1] that takes an RDF Schema and generates  
>> java
>> interfaces from it. Then you can query and update an rdf model using
>> bean-style java-methods. Not quite what you want, but somehow close, i
>> guess. As i co-developped this project i would like to get your
>> feedback.
>> HS> It should be much easier to do this in RDF as the model is much
>> HS> simpler, especially if one has an OWL ontology to work with.   
>> Perhaps
>> HS> the problem is fundamentally the same as with relational  
>> database. But
>> HS> perhaps triples open up new spaces that just were not clearly  
>> available
>> HS> with relational databases...
>> What would be uses cases for java object persistence as rdf models? I
>> never thought of that.
>>  [1] http://rdfreactor.ontoware.org
>>   Max
> [2] I wish one could also e-mail that wiki!
> http://www.openrdf.org/forum/mvnforum/viewthread? 
> thread=407&lastpage=yes
Received on Friday, 7 January 2005 18:16:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:44:54 UTC