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

xsd:decimal parsed as xsd:double #108

Open
giacomociti opened this issue May 1, 2024 · 8 comments
Open

xsd:decimal parsed as xsd:double #108

giacomociti opened this issue May 1, 2024 · 8 comments

Comments

@giacomociti
Copy link

the following

@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://www.example.org/> .

:foo :bar "10.5"^^xsd:decimal .

{
    :foo :bar ?value .
    ([] ?datatype) log:dtlit ?value
}
=>
{
    :foo  :type ?datatype
} .

derives :foo :type xsd:double. Is it on purpose or it's a bug?

josd added a commit that referenced this issue May 1, 2024
@josd
Copy link
Collaborator

josd commented May 1, 2024

A bug and it is now fixed.
Thanks @giacomociti

@josd josd closed this as completed May 1, 2024
@giacomociti
Copy link
Author

sorry for nitpicking @josd, but another little issue seems to be present with shorthand syntax

@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://www.example.org/> .

:foo :bar "10.5"^^xsd:decimal, 11.5 , 4.2E9.

{
    :foo :bar ?value .
    ([] ?datatype) log:dtlit ?value
}
=>
{
    ?value a ?datatype
} .

gives

@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.

"10.5"^^xsd:decimal a xsd:decimal.
11.5 a xsd:double.
4200000000.0 a xsd:double.

I think the second value should be decimal and not double

@josd
Copy link
Collaborator

josd commented May 2, 2024

I see your point but when you have numerals that are the result of a calculation eye can't do better than xsd:double.
Take for instance

@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://www.example.org/> .

{
    -1 math:asin ?asin .
    (?asin -2) math:product ?value .
    ([] ?datatype) log:dtlit ?value .
}
=>
{
    :foo :value ?value .
    :foo :type ?datatype .
} .

for which eye will pass

:foo :value 3.141592653589793 .
:foo :type xsd:double.

Another reasoner might do better and pass

:foo :value 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
:foo :type xsd:decimal.

We just want to indice that we have a double precision number with a precision of 1.11e-16

@giacomociti
Copy link
Author

this is understandable when calculations are involved. But in my example, I can see no calculation besides parsing. Also, if the same data:

:foo :bar "10.5"^^xsd:decimal, 11.5 , 4.2E9.

is loaded from a separate file with the --turtle option, the number 11.5 is recognized as xsd:decimal

@josd josd reopened this May 2, 2024
@giacomociti
Copy link
Author

the changes on May 1 (v10.5.9) apparently had an impact on the math:max built-in:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix : <http://example/org/> .

:example1 rdf:value (3.0 7.0) .
:example2 rdf:value ("3.0"^^xsd:decimal "7.0"^^xsd:decimal) .

{
    ?example rdf:value ?value .
    ?value math:max ?max .

} 
=>
{
    ?example :max ?max
} .

with v10.5.8 we get, as expected:

@prefix : <http://example/org/>.

:example1 :max 7.0 .
:example2 :max 7.0 .

But with version v10.5.9 I get

** ERROR ** eam ** error(type_error(evaluable,<http://www.w3.org/2001/XMLSchema#decimal> / 0),context(system:(is)/2,_4652))

The error is due to example2.

Sorry @josd, I keep bothering you with these kinds of little issues, the fact is that the eye reasoner is such an awesome tool and I'm using it for everything :-)

josd added a commit that referenced this issue Jul 22, 2024
@josd
Copy link
Collaborator

josd commented Jul 22, 2024

Thank you very much @giacomociti for your observation and also for your kind words ;-)

The math:max and math:min built-ins should now be fixed in EYE v10.16.24 (2024-07-18)

@giacomociti
Copy link
Author

here I am again :-D

The above fix for math:min and math:max works, but if I split data and rules into separate files:

# data.ttl
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://example/org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

:example2 rdf:value (3.0 7.0) .
:example3 rdf:value ("3.0"^^xsd:decimal "7.0"^^xsd:decimal) .
# rules.n3
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix : <http://example/org/> .

{
    ?example rdf:value ?value .
    ?value math:max ?max .

} 
=>
{
    ?example :max ?max
} .

I get no results if I use --turtle to load the data:

eye --nope --quiet --pass-only-new rules.n3 --turtle data.ttl 

It works fine without the --turtle option

josd added a commit that referenced this issue Sep 3, 2024
@josd
Copy link
Collaborator

josd commented Sep 3, 2024

Thank you very much @giacomociti for finding👍

The --turtle switch invokes a fast C turtle parser and returns rdf:first and rdf:rest triples as list descriptions and we forgot to assemble those to list terms.
It now works fine in v10.20.3

$ eye --nope --quiet --pass-only-new rules.n3 --turtle data.ttl
@prefix : <http://example/org/>.

:example2 :max 7.0 .
:example3 :max 7.0 .

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