eyereasoner / eye

Euler Yet another proof Engine
https://eyereasoner.github.io/eye/
MIT License
124 stars 17 forks source link

xsd:decimal parsed as xsd:double #108

Open giacomociti opened 6 months ago

giacomociti commented 6 months ago

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 commented 6 months ago

A bug and it is now fixed. Thanks @giacomociti

giacomociti commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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

giacomociti commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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 .