prov
prov copied to clipboard
Literal comparison for Decimal values
@trungdong in prov/model.py the way literal comparison is implemented, it results in:
pm.Literal(10, datatype=pm.XSD_DECIMAL) != pm.Literal(10.0, datatype=pm.XSD_DECIMAL)
is that intended?
@satra, this is unintended. It is caused by the conversion from the value of a Literal
into string below:
class Literal(object):
def __init__(self, value, datatype=None, langtag=None):
self._value = six.text_type(value) # value is always a string
I'm not sure there is a good solution for this, unless the equality check of Literal
understands XSD values.
This is clearly undesirable. However, I'm reluctant to implement the handling of XSD types in equality check, which might be time-consuming.
I wonder if there is a simple solution.
i agree that this shouldn't be done in equality. by representing the value as a string, it may also have some unfortunate side effects especially for floating point numbers.
one option is to handle it in the representation as is done in rdflib, which maps literals to native python types.
http://rdflib.readthedocs.org/en/stable/rdf_terms.html#literals
a number of the current failures are from lexical comparison of decimals.
Thank you for the pointer, @satra. We've actually done that for a few XSD datatypes, but now I can extend that to cover more with the example in rdflib.