prov icon indicating copy to clipboard operation
prov copied to clipboard

Literal comparison for Decimal values

Open satra opened this issue 8 years ago • 3 comments

@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 avatar Mar 20 '16 02:03 satra

@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.

trungdong avatar Mar 21 '16 15:03 trungdong

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.

satra avatar Mar 22 '16 17:03 satra

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.

trungdong avatar Mar 23 '16 16:03 trungdong