[redland-dev] ruby bindings and typed literals

Dave Beckett dave at dajobe.org
Tue Feb 6 05:13:04 UTC 2007


Benno Blumenthal wrote:
> 
> Hello All,
> 
> I am interested in modifying ActiveRDF so that typed literals are
> handled properly.
> In the Redland Ruby bindings, there is a literal subclass of node which
> has a lang and value properties.
> And it is possible to define a literal node with the datatype property
> set correctly.
> 
> But I cannot see how to get the datatype property back out with the ruby
> bindings.
> 
> So what happens to numeric/date/XML literals in the ruby bindings?   Are
> they already converted to Ruby datatypes, or am I missing something?

As far as I can tell, this method of the Node class does return the
datatype URI  since it's put into hash_uri and used

    # create a literal from another Node
    def Literal.from_node(node)
      lang = Redland.librdf_node_get_literal_value_language(node) if
Redland.librdf_node_get_literal_value_language(node)
      str = Redland.librdf_node_get_literal_value(node)
      hash_uri = Redland.librdf_node_get_literal_value_datatype_uri(node)
      hash_uri = Uri.new(Redland.librdf_uri_to_string(hash_uri)) if hash_uri
      return Literal.new(str,lang,hash_uri)
    end

Or if this isn't what you are talking about, the above code gives you
the fragment you need to make such a method of the base Node class:
(hand edited, not tested)
    def datatype(node)
      uri = Redland.librdf_node_get_literal_value_datatype_uri(self.node)
      uri = Uri.new(Redland.librdf_uri_to_string(uri)) if uri
      return uri
    end

Dave


More information about the redland-dev mailing list