views:

34

answers:

2

In my database I have things with string properties. Some of the property values match numeric strings (only contain digits). I'd like to give these things a special type (a subtype of what they are). Is such a thing possible in OWL?

A: 

Is actually something you can do in RDF. For any literal in RDF you can specify the type with something like this (in turtle/RDF) ...

@prefix xsd: <http://www.w3.org/2001/XMLSchema#&gt; .
:x :myDataTypeProperty "123"^^xsd:integer .
:y :myDataTypeProperty "some string"^^xsd:string .
:z :myDataTypeProperty "2004-12-06"^^xsd:date .

Same example in RDF/XML

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns="http://www.foo.bar.com#"&gt;
  <rdf:Description rdf:about="http://www.foo.bar.com#x"&gt;
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"&gt;123&lt;/myDataTypeProperty&gt;
  </rdf:Description>
  <rdf:Description rdf:about="http://www.foo.bar.com#y"&gt;
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#string"&gt;some string</myDataTypeProperty>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.foo.bar.com#z"&gt;
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#date"&gt;2004-12-06&lt;/myDataTypeProperty&gt;
  </rdf:Description>
</rdf:RDF>

In the XMLSchema (XSD) spec you can find out all the supported datatypes. But be sure that you only use the ones mentioned in the SPARQL spec

You could mint your own data types if you wanted and have something like:

:x :myDataTypeProperty "123"^^ns:MyClassificationScheme .

And you could go further and say that ...

ns:MyClassificationScheme rdfs:subClassOf xsd:integer .

When you issue SPARQL query against data you can specify the type when you issue apply filters, like this:

SELECT * WHERE { 
   ?person :born ?birthDate .
   FILTER ( ?birthDate > "2005-02-28"^^xsd:date ) .
}

I hope this answered your question.

Edited

As panzi mentioned my answer was going in the wrong direcction. I leave it anyway.

msalvadores
I know that but it isn't what I want. I have a `xsd:string` datatype property that is already filled with values in my database. SOME of these values happen to match integers. I'd like resources witch such properties to be automatically of some special sub-class. It would be more handy than a `FILTER REGEX` in the query (but such a query would also be ok, just not as handy). Basically I want a regular expression (or "type conversion to `xsd:integer` supporting string") based value restriction.
panzi
Ok, I got it. I think I completelly misunderstood your question. I've added a different answer ..
msalvadores
+1  A: 

I think that you need are Datatype Restrictions in combination with xsd:pattern.

The following axiom is from OWL 2 Primer ...

:Teenager  rdfs:subClassOf
       [ rdf:type             owl:Restriction ;
         owl:onProperty       :hasAge ;
         owl:someValuesFrom   
          [ rdf:type             rdfs:Datatype ;
            owl:onDatatype       xsd:integer ;
            owl:withRestrictions (  [ xsd:minExclusive     "12"^^xsd:integer ]
                                    [ xsd:maxInclusive     "19"^^xsd:integer ]
            )
          ]
       ] .

... and if you shift it a bit with xsd:pattern we can have something like ...

:YourClass  rdfs:subClassOf
       [ rdf:type             owl:Restriction ;
         owl:onProperty       :yourHasNumericProperty ;
         owl:someValuesFrom   
          [ rdf:type             rdfs:Datatype ;
            owl:onDatatype       xsd:integer ;
            owl:withRestrictions  ([xsd:pattern "E[1-9][0-9]*"])
          ]
       ] .

With xsd:pattern you can do Datatype Restriction based on regular expressions.

I hope this gives you some directions.

msalvadores