Developer Notes

This is a freeform collection of notes about roadblocks, inconsistencies, discoveries, things to come back to, and interesting resources or ideas.

URIs

One of my main gripes about the Redland SWIG binding is the Redland::URI class. Since Ruby has a URI class in the standard library, I found myself mapping Ruby URIs into Redland::URIs all the time. I know exactly why this was done -- Redland's API has a URI class (librdf_uri) that it uses extensively throughout, so Ruby URIs won't work without some kind of magic going on behind the scenes.

One of my goals for Redleaf is to figure out enough of this magic that one never has to interact directly with anything other than Ruby URI objects. I have a few early (and I'm sure naive) ideas about how this might be accomplished:

  • Monkeypatch the stdlib URI so that any URI that's created has an underlying associated librdf_uri. This is ugly and probably highly impractical.
  • Map all incoming URI objects into librdf_uris on the fly. This is probably better from a cleanliness perspective, but all that memory thrash of creating and freeing so many librdf_uris may have adverse effects on performance.

More on this as I learn more.

Mapping Literals to Ruby Objects

We're going to try to just use native Ruby objects as literals, which will require mapping them back and forth so Redland can understand them.

Typed Literals

These will just be mapped back and forth to a corresponding Ruby datatype, using a stdlib one where possible and falling back to our own where the XML Schema primitive datatypes don't have a direct corresponding class:

XSD Datatype Ruby class
string Map to and from Ruby's String. This is not an exact mapping under 1.8.x, as they aren't encoding-aware. Mapping from a Ruby String to a Literal Node may not be one-to-one, either, depending on how the other types map.
boolean Map to and from Ruby's TrueClass and FalseClass.
decimal Map to and from Ruby's BigDecimal.
float Map to and from Ruby's Float.
double Map to and from Ruby's Float.
duration Map to and from a new Duration class packaged with Redleaf, unless a suitable third-party class can be found. (Duration?)
dateTime Map to and from Ruby's DateTime (stdlib).
time Map to and from a new ClockTime class packaged with Redleaf, unless a suitable third-party class can be found.
date Map to and from a DayOfYear class packaged with Redleaf, unless a suitable third-party class can be found.
gYearMonth Map to and from a GregorianYearMonth class packaged with Redleaf, unless a suitable third-party class can be found.
gYear Map to and from a GregorianYear class packaged with Redleaf, unless a suitable third-party class can be found.
gMonthDay Map to and from a GregorianMonthDay class packaged with Redleaf, unless a suitable third-party class can be found.
gDay Map to and from a GregorianDay class packaged with Redleaf, unless a suitable third-party class can be found.
gMonth Map to and from a GregorianMonth class packaged with Redleaf, unless a suitable third-party class can be found.
hexBinary Map to and from a String containing the canonical representation.
base64Binary Map to and from a String containing the canonical representation. Use this for things which don't fit in the canonical string?
anyURI I'm not sure what the difference between an anyURI-type literal and a URI is, especially in the context of RDF. Would an anyURI literal ever be used instead of a URI?
QName Not sure what to do with this one either, as a QName is an anyURI and an NCName, which "must be associated with a namespace URI".
NOTATION I'm not sure I even understand what this is yet.

Query Testing

The Redland Rasqal RDF Query Demonstration page has a collection of good queries to use to test the Redleaf::Query class.