Re: Questions about value expansion

Hi Sean,

You may get a more accurate, detailed answer if you file an issue over here:

https://github.com/ruby-rdf/json-ld/

But -- I've got one quick response inline below:

On 11/07/2014 08:08 AM, Sean Johnson wrote:
>
> Hello,
>
> I'm curious about the value expansion implementation in the Ruby 
> library, jsonld.
>
> In particular, the expanding of native types. Here's some tests from 
> the library:
>
> |   "native boolean" => ["foo", true,                           {"@value" => true}],
>    "native integer" => ["foo", 1,                              {"@value" => 1}],
>    "native double" =>  ["foo", 1.1e1,                          {"@value" => 1.1E1}],
>    "native date" =>    ["foo", Date.parse("2011-12-27"),       {"@value" => "2011-12-27", "@type" => RDF::XSD.date.to_s}],
>    "native time" =>    ["foo", Time.parse("10:11:12Z"),        {"@value" => "10:11:12Z", "@type" => RDF::XSD.time.to_s}],
>    "native dateTime" =>["foo", DateTime.parse("2011-12-27T10:11:12Z"), {"@value" => "2011-12-27T10:11:12Z", "@type" => RDF::XSD.dateTime.to_s}],
> |
>
> Why does a native date, time and dateTime get expanded to include an 
> @type, but a native integer does not? That seems inconsistent. And why 
> does the @type get added in this case when the spec doesn't mention 
> adding @type unless the active context includes a type mapping?
>

Since JSON-LD is a subset of JSON, the JSON-LD API spec only covers 
native support for built-in JSON types. There is such a thing as a JSON 
number and a JSON boolean -- so native conversion for integers, doubles, 
and booleans are covered in the spec. However, JSON doesn't natively 
support dates or times, so that's why @type must be present there. It 
looks like the Ruby library has a proprietary feature to auto-convert 
native Ruby dates/times to literals using an assumed appropriate XSD @type.

> http://www.w3.org/TR/json-ld-api/#value-expansion
>
> Similarly, I don't understand this value expansion behavior:
>
> |%w(boolean integer string dateTime date time).each do |dt|
>    it "expands datatype xsd:#{dt}" do
>      expect(subject.expand_value("foo", RDF::XSD[dt])).to produce({"@id" => "http://www.w3.org/2001/XMLSchema##{dt}"}, @debug)
>    end
> end
> |
>
> If I'm translating the Ruby correctly, it's if the value is literally 
> a Ruby type, then expand it to an IRI pointing to the W3C XML Schema 
> IRI for the type. Again… I don't see any mention of that in the value 
> expansion portion of the spec:
>
> http://www.w3.org/TR/json-ld-api/#value-expansion
>
> Thanks for the help! I'm just trying to ensure I do the right thing 
> with value expansion and I'm confused by these differences in the spec 
> and the Ruby implementation.
>
> Cheers,
> Sean
>


-- 
Dave Longley
CTO
Digital Bazaar, Inc.
http://digitalbazaar.com

Received on Wednesday, 12 November 2014 22:26:16 UTC