2

I'm trying to set up some lightweight, on-demand data validation outside of any reasoning system or triple-store provided load-time validation. I'm using GraphDB 8.3.

Let's say I load the following triples, using the Ontology of Biomedical Investigations (OBI), http://purl.obolibrary.org/obo/obi.owl:

PREFIX : <http://example.com/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
insert data {
    graph :data
    {
        :measurement1 a <http://purl.obolibrary.org/obo/IAO_0000032> ;
            <http://purl.obolibrary.org/obo/IAO_0000004> "100.1"^^xsd:double .
        :measurement2 a <http://purl.obolibrary.org/obo/IAO_0000032> ;
            <http://purl.obolibrary.org/obo/IAO_0000004> "100"^^xsd:int .
    }
}

That says that :measurement1 and :measurement2 have measurement values. The range of <http://purl.obolibrary.org/obo/IAO_0000004> is xsd:double. I know that I can check for datatypes that aren't exactly the same as the specified range with something like the query below.

As you can see in the comments embedded in my query, I'd like to say that that :measurement2's value of "100"^^xsd:int is acceptable because all integers are contained within the set of double-precision floating point numbers. (Right?)

Is there an existing ontology that says that xsd:int is a sub-something of xsd:double?

PREFIX : <http://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
# loaded obi into http://example.com/ontology
select distinct ?stype ?p ?ptype ?propdom ?proprange ?otype ?odatatype where {
    {
        graph :data
        {
            ?s ?p ?o .
            bind (datatype(?o) as ?odatatype)
        }
        optional {
            graph <http://example.com/ontology> {
                values ?ptype {
                    owl:ObjectProperty owl:DatatypeProperty
                }
                ?p a ?ptype
            }
        }   
        optional {
            ?o a ?otype
        }   
        optional {
            ?s a ?stype
        }   
        optional {
            {
                graph <http://example.com/ontology> {
                    ?p rdfs:domain ?propdom
                }
            }   
        }
        optional {
            {
                graph <http://example.com/ontology> {
                    ?p rdfs:range ?proprange
                }
            }   
        }
    }
    minus
    {
        ?s rdf:type ?o 
    }
    #       minus
    #    {
    #        ?odatatype rdfs:subClassOf+ ?proprange
    #    }
    filter ( ?odatatype != ?proprange )
}
Mark Miller
  • 3,011
  • 1
  • 14
  • 34

4 Answers4

3

XSD datatypes do not have subclasses. There are derived types: xsd:int is a derived type of xsd:integer; it is an XSD-defined feature.

xsd:int not a derived type of xsd:double.

What is important in datatypes is the value : "100"^^xsd:int and "100"^^xsd:double are the same value. SHACL can express this.

See "Atomic Types" in https://www.w3.org/TR/xpath-datamodel-3/#types-hierarchy

TallTed
  • 9,069
  • 2
  • 22
  • 37
AndyS
  • 16,345
  • 17
  • 21
  • << the value : `"100"^^xsd:int` and `"100"^^xsd:double` are the same value. SHACL can express this. >> Well, this is kind of true, and false, according to the standard. This is a very bizarre fact of the XSD standard. The value spaces of `xsd:int` and `xsd:double` are disjoint, which means that whatever value `"100"^^xsd:int` denotes, it ought to be different from the value that `"100"^^xsd:double` denotes. However, the description of the value space of `xsd:int` and that of `xsd:double` suggest that they both contain numbers, as expected (that is, with the example, the number one hundred). – Antoine Zimmermann Oct 04 '17 at 19:45
3

To answer your questions:

all integers are contained within the set of double-precision floating point numbers. (Right?)

Wrong! As you say, xsd:double contains the set of double-precision floating point numbers, which does not contain numbers like the Graham number and other big integers.

Is there an existing ontology that says that xsd:int is a sub-something of xsd:double?

If there is (I doubt there is), it's inconsistent with the spec of XSDs (see comment above).

To this, I should add the fact that XSD defines the value space of xsd:decimal as disjoint from that of xsd:double. This implies that the value space of xsd:int is also disjoint from the one of xsd:double.

In general, I would recommend that you use xsd:decimal instead of xsd:double whenever possible. xsd:double suggests that it is never possible that the systems using your data or ontology are going to deal with better precisions or bigger numbers that those of xsd:double.

Antoine Zimmermann
  • 5,314
  • 18
  • 36
1

If there are any such ontologies, they are most certainly custom user designed. I am not aware of any W3C standards to this effect. This (https://www.w3.org/TR/xmlschema-2/#built-in-datatypes) diagram shows integer to be "derived" from decimal, though I am not sure to what extent this can be used as an ersatz subClassOf or anything of the sort.

Aqualung
  • 19
  • 3
  • Tip for creating useful answers, if you're going to quote something from the questioner, highlight the text then press the double-quote icon. It will format the text so that it stands apart from your answer. Welcome to stackoverflow – shrewmouse Sep 22 '17 at 17:13
  • I like that illustration. In this case, maybe I will have to rely to the triplestore's load-time validator. I'll post my experiences. – Mark Miller Sep 22 '17 at 17:25
1

To an extent, the specs do that. See for example: https://www.w3.org/TR/swbp-xsch-datatypes/#sec-values

However, without any reasoner to do this, you'll have to replicate datatype reasoning on intervals and values common to multiple datatypes.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • From a reasoner perspective (in the RDF, RDFS, OWL DL, OWL Full semantics), the specs do *not* do all that. The values of `xsd:int` and the values of `xsd:double` are disjoint. However, for RDF with support for XSD reasoning, or with OWL, it is the case that all `xsd:int`s are also `xsd:decimal`s, and in OWL (but not in RDF(S)), the `rdfs:subClassOf` relation between `xsd:int` and `xsd:decimal` is implied. – Antoine Zimmermann Oct 04 '17 at 19:55