Letractively / rdflib

Automatically exported from code.google.com/p/rdflib
Other
0 stars 0 forks source link

Literal init with both language and datatype #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When you initialize a Literal type with both a language and datatype, only 
datatype is set (language value is discarded and set to None)

But if you manually set a literal object's language attribute, it sticks 
regardless of whether datatype was set.

When you serialize or call the literal's n3() method, it is possible to 
output both language and datatype.

So, the question is, why can't a Literal be initialized with both langauge 
and datatype (ie. via the __new__ method)?

ex.1
>> l = Literal(u'hello',u'en-us',XSD_NS['string'])
>> l.language
None
>> l.n3()
u'"hello"^^<http://xsd.org/string>'

ex.2
>> l = Literal(u'hello',XSD_NS['string'])
>> l.language = u'en-us'
>> l.n3()
u'"hello"@en-us^^<http://xsd.org/string>'

Original issue reported on code.google.com by kyleheus...@gmail.com on 27 Aug 2009 at 10:53

GoogleCodeExporter commented 9 years ago
In RDF literal values cannot have both a language and a datatype. It's either 
or or neither. Thus this should 
reasonably not be changed.

(It *is* possible right now to get those strange serializations by manipulating 
a Literal instance though, but that 
may/should go away as well..)

I propose WontFix.

Original comment by lindstr...@gmail.com on 9 Sep 2009 at 12:34

GoogleCodeExporter commented 9 years ago

Original comment by eik...@gmail.com on 1 Feb 2010 at 7:42

GoogleCodeExporter commented 9 years ago

Original comment by eik...@gmail.com on 1 Feb 2010 at 8:53

GoogleCodeExporter commented 9 years ago
I propose, and I hope to write the patch tonight, that Literal raise a 
TypeError if 
both the args are passed in. Quietly ignoring one of the args isn't useful. 
Also, 
__new__ can have a docstring explaining this with a pointer to the spec, since 
clearly 
it's surprising people. 

In a related fix, Literal's __repr__ shouldn't ever emit datatype and language 
args, 
and it should not omit None args at all, just to save space.

Original comment by drewpca on 2 Feb 2010 at 2:02

GoogleCodeExporter commented 9 years ago

Original comment by drewpca on 2 Feb 2010 at 2:15

GoogleCodeExporter commented 9 years ago
Waiting for review: http://code.google.com/p/rdflib/source/branch?
spec=issue107&branch=/branches/literalnew-81

Original comment by drewpca on 2 Feb 2010 at 3:09

GoogleCodeExporter commented 9 years ago
Merged, with a change to the rdf/xml parser, since an rdf/xml node CAN have a 
lang and 
datatype. (The lang is ignored, says 
http://www.w3.org/TR/REC-rdf-syntax/#section-
Syntax-languages)

Original comment by drewpca on 4 Feb 2010 at 8:10