Re: Questions about value expansion

> On Nov 12, 2014, at 2:34 PM, Markus Lanthaler <markus.lanthaler@gmx.net> wrote:
> 
> Hi Sean,
> 
> Now to your second mail :-)
> 
> On Friday, November 07, 2014 2:08 PM, Sean Johnson wrote:
>> I'm curious about the value expansion implementation in the Ruby 
>> library, jsonld.
> 
> Gregg is implementer of that library, but I'll do my best to answer your questions.

Thats me!

>> In particular, the expanding of native types. Here's some tests from the 
>> library:
> 
> In general, you should have a look at our test suite [1-2] which expresses all of this in a language-indented manner.. if you submit an implementation report, we'll include your conformance level in the official conformance report [3].
> 
> 
>>       "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?
> 
> Honestly, I have no clue... and it's difficult to figure out what's going on here since you cite this without any context.

Integers, floats, doubles, booleans and nil can be represented natively in JSON-LD, dates, times, and dateTimes can't. The @type is necessary to not loose information, but this is not core code, and only there to facilitate usage within the Ruby RDF.rb eco-system, and honestly, some of it is probably not needed any longer.

>> 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?
> 
> When converting from or to RDF, types sometimes get added. See
> 
>   http://www.w3.org/TR/json-ld-api/#data-round-tripping
> 
> for all details (this is obviously also expressed in the algorithms handling this).
> 
>> http://www.w3.org/TR/json-ld-api/#value-expansion
> 
> Value expansion is not one of those though :-)
> 
> 
>> 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
> 
> Again, I don't know what's going on here and I don't have the time to dig into that. I would suggest to not try to reverse-engineer one of the existing implementations (that might do more than what's required) but really implement the algorithms as specified and run the official test suite.

Yes, probably not too useful for anything other than the Ruby/RDF.rb implementation.

>> 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.
> 
> Then simply ignore the Ruby implementation :-) The spec is hopefully clear enough.. if not, let us know. Many more people will be able to help you with that than figuring out what a snippet of a specific implementation is doing (especially without context or links to the code).

I understand the value in working code, and as I said in another response, you're free to crib. It may send you down some paths that aren't useful for passing tests, though. That said, most of the Ruby implementation follows the spec quite closely.

Gregg

> Cheers,
> Markus
> 
> 
> [1] https://github.com/json-ld/json-ld.org/tree/master/test-suite
> [2] http://json-ld.org/test-suite/
> [3] http://json-ld.org/test-suite/reports/
> 
> 
> --
> Markus Lanthaler
> @markuslanthaler
> 
> 

Received on Thursday, 13 November 2014 01:29:36 UTC