OWL: restrict property value to a numeric string
In my database I have things with string properties. Some of the property values match n开发者_开发百科umeric 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?
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.
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#> .
: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#">
<rdf:Description rdf:about="http://www.foo.bar.com#x">
<myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">123</myDataTypeProperty>
</rdf:Description>
<rdf:Description rdf:about="http://www.foo.bar.com#y">
<myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#string">some string</myDataTypeProperty>
</rdf:Description>
<rdf:Description rdf:about="http://www.foo.bar.com#z">
<myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2004-12-06</myDataTypeProperty>
</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.
精彩评论