One of the things I wanted to try was a RdfBuilder, this is similar to Groovy's NodeBuilder.
There are a couple of things that make it a bit tricky. When parsing or debugging builders I haven't yet found a way to find the methods/properties available even using MetaClass. And of course, when the magic goes wrong it's a bit harder to debug Groovy versus java.
It certainly smartens up the creation of triples, for example (bits from the NTriples test case):
def rdf = new RdfBuilder(graph)
rdf.with {
  namespace("eg", "http://example.org/")
  namespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
  "eg:resource1" "eg:property":"eg:resource2"
  "_:anon" "eg:property":"eg:resource2"
  "eg:resource1" "eg:property":"_:anon"
  (3..6).each {
    "eg:resource$it" "eg:property":"eg:resource2"
  }
  "eg:resource7" "eg:property":'"simple literal"'
  "eg:resource17" ("eg:property":['"\\u20AC"', 
    '"\\uD800\\uDC00"', '"\\uD84C\\uDFB4"', '"\\uDBFF\\uDFFF"'])
  "eg:resource24" "eg:property":'"<a></a>"^^rdfs:XMLLiteral'
  "eg:resource31" "eg:property": '"chat"@en'
}
Using the builder results in a file that's smaller than the test case file. You could remove some duplication by creating a method that takes in a number and the object and generates "eg:resource$number" "eg:property" "$object" but doing that may actually make it harder to read.
If you stick to only using URIs you can do things like:
rdf.with {
  urn.foo6 {
    urn.bar {
      urn.baz1
      urn.baz2
    }
  }
}
I expect that JRDF will only be more Groovy friendly in the future.
 
2 comments:
I see in RDF the hint of seamlessly inter-operable applications and knowledge bases.
Adding RDF support to groovy would be hugely valuable. Of course, writing RDF triples in groovy would make it much easier to integrate existing (legacy) systems.
Reading RDF in native groovy would allow sophisticated reasoning and the rich visualisations required to propel knowledge management into the business world.
What help do you need?
Lee, get in contact with me and I'm sure we can do some stuff with JRDF and Groovy (above what I've already done). I've spoken about integrating SPARQL builder - like the SQL builder. That would be a good start.
Post a Comment