sweetrdf / rdfInterface

MIT License
6 stars 2 forks source link

Literal->getDatatype() always returns string? Why is it different from getLang? #12

Closed k00ni closed 3 years ago

k00ni commented 3 years ago

Literal interface says

https://github.com/sweetrdf/rdfInterface/blob/48d8a66bb7952e30e7382dd2a57cb3ce8cccebeb/src/rdfInterface/Literal.php#L45-L47

Does it mean that there is a default value for getDatatype? Like an empty string?

IMHO regarding the PHP side there is no difference between getDatatype and getLang(), both might be null at the beginning. But their definition differs for some reason. Can you please explain why?

zozlak commented 3 years ago

On the RDF side the difference is a literal without a lang tag is always different from one having a lang tag while lack of datatype means the datatype is assumed to be xsd:string (so "foo" and "foo"^^http://www.w3.org/2001/XMLSchema#string are equal; see https://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal for a reference).

This creates an ambiguity because xsd:string datatype has two valid representations - lack of a datatype (in PHP context we would say null) and explicit xsd:string. To deal with this ambiguity I decided to explicitly forbid the null representation (but I also admit it should be precisely described in the method comment).

I must also admit this convention is not followed by Literal class constructor and DataFactory::literal() method. What is worse, DataFactory::literal() has different default (null) than the Literal class constructor (xsd:string). It's clear it must be synced.

I see three options to make it in sync:

Personally I'm the most in favor of the last one and I dislike the first one the most. And what do you think?

zozlak commented 3 years ago

By the way to make such assumptions clear and easy to verify (and to save copy-pasting of tests code in implementations) I started to build a tests suite for the rdfInterface compatibility in the tests directory. The simpleRdf already makes use of them.

k00ni commented 3 years ago

I am working on my in-memory store implementation currently, which might be a good practice range for rdfInterface. When taking the view as an outsider, some things are not clear enough (yet), like how to use certain things or what you have to provide sometimes.

I follow your arguments here and support the third option too. Let us continue shaping the library with external projects and make it viable and fun to use. Might worth some iterations, but we are on a good way IMHO.

zozlak commented 3 years ago

When taking the view as an outsider, some things are not clear enough (yet), like how to use certain things or what you have to provide sometimes.

Sure thing. I didn't put much effort into documenting things so far as I would say it's still in quite early development stage. Please don't hesitate to ask when you run into such issues. They may indicate lack of documentation but also design flaws and it's important to discuss them.

As for now my plan is to:

Only once this is done and I have a feeling rdfInterface works well focus on documenting it well.

First two point of the list above are likely to be ready until the end of March. Can't tell about the others.

I follow your arguments here and support the third option too. Let us continue shaping the library with external projects and make it viable and fun to use. Might worth some iterations, but we are on a good way IMHO.

Ok, I will make the adjustments.

zozlak commented 3 years ago

By the way, I just read https://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal carefully and there will be a change in the expected Literal::getDatatype() behavior:

k00ni commented 3 years ago

Good hint!