Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literal comparison for Decimal values #77

Open
satra opened this issue Mar 20, 2016 · 3 comments
Open

Literal comparison for Decimal values #77

satra opened this issue Mar 20, 2016 · 3 comments

Comments

@satra
Copy link
Contributor

satra commented Mar 20, 2016

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

@trungdong
Copy link
Owner

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

@satra
Copy link
Contributor Author

satra commented Mar 22, 2016

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.

@trungdong
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants