Reasoning and datatypes of Literals

942 views Asked by At

In Turtle-RDF it is convenient to omit the datatype extension ^^xsd:string for string literals. But when i try to do reasoning with StarDog, http://www.stardog.com/, only the individual :YYY with the extension "green"^^xsd:string is found to be a :GreenButton

@prefix :      <http://stackoverflow.com/q/29075078/1281433#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .


:color   a            owl:DatatypeProperty ;
         rdfs:range   xsd:string ;
         rdfs:domain  :Button .


:XXX     :color       "green"             .
:YYY     :color       "green"^^xsd:string .


:Button         a     rdfs:Class .

:GreenButton    a     rdfs:Class ;
                owl:equivalentClass [ a owl:Restriction;
                                      owl:onProperty :color ;
                                      owl:hasValue "green"
                                    ] .

:TestButton     a     :GreenButton .

Reasoning result:

+-------------+----------+----------------------------------------------------+
|      s      |    p     |         o                                          |
+-------------+----------+----------------------------------------------------+
| :XXX        | rdf:type | :Button                                            |
| :YYY        | rdf:type | :Button                                            |
| :YYY        | rdf:type | :GreenButton                                       |

| :TestButton | rdf:type | :GreenButton                                       |
| :TestButton | :color   | "green"^^<http://www.w3.org/2001/XMLSchema#string> |
  ...

What is the best way to deal with it?

2

There are 2 answers

6
chris On BEST ANSWER

According to the docs:

RDF parsing in Stardog is strict: it requires typed RDF literals to match their explicit datatypes, URIs to be well-formed, etc. In some cases, strict parsing isn’t ideal—it may be disabled using the --strict-parsing=FALSE.

However, even with strict parsing disabled, Stardog’s RDF parser may encounter parse errors from which it cannot recover. And loading data in lax mode may lead to unexpected SPARQL query results. For example, malformed literals ("2.5"^^xsd:int) used in filter evaluation may lead to undesired results.

Have you tried disabling strict-parsing and see what the effects are?

p.s. see Joshua's comment in the question. I am not advising to switch off strict parsing, but it may be the only option if dealing with arbitrary/external data that is sparsely typed (assuming it does resolve the issue).

0
Evren Sirin On

According to OWL semantics "green" and "green"^^xsd:string are actually equivalent. They are also equivalent in RDF 1.1. Stardog does not support RDF 1.1 yet and there is a bug wrt string literal reasoning as you noticed. Your observation is correct: plain literals in OWL axioms are automatically converted to xsd:string but literals in instance assertions are not. There is an open ticket (#2340) for this and you can check release notes in the future to see when this is fixed. Until then the workaround is to always use xsd:string for instances.