@SuppressWarnings("unused")
@Test
public void testDataRanges() throws OWLException {
// Data ranges are used as the types of literals, as the ranges for data
// properties
OWLOntologyManager m = create();
// OWLDatatype represents named datatypes in OWL
// The OWL2Datatype enum defines built in OWL 2 Datatypes
OWLDatatype integer = df.getOWLDatatype(OWL2Datatype.XSD_INTEGER
.getIRI());
// For common data types there are some convenience methods of
// OWLDataFactory
OWLDatatype integerDatatype = df.getIntegerOWLDatatype();
OWLDatatype floatDatatype = df.getFloatOWLDatatype();
OWLDatatype doubleDatatype = df.getDoubleOWLDatatype();
OWLDatatype booleanDatatype = df.getBooleanOWLDatatype();
// The top datatype is rdfs:Literal
OWLDatatype rdfsLiteral = df.getTopDatatype();
// Custom data ranges can be built up from these basic datatypes
// Get hold of a literal that is an integer value 18
OWLLiteral eighteen = df.getOWLLiteral(18);
OWLDatatypeRestriction integerGE18 = df.getOWLDatatypeRestriction(
integer, OWLFacet.MIN_INCLUSIVE, eighteen);
OWLDataProperty hasAge = df
.getOWLDataProperty(IRI
.create("http://www.semanticweb.org/ontologies/dataranges#hasAge"));
OWLDataPropertyRangeAxiom rangeAxiom = df.getOWLDataPropertyRangeAxiom(
hasAge, integerGE18);
OWLOntology o = m.createOntology(IRI
.create("http://www.semanticweb.org/ontologies/dataranges"));
// Add the range axiom to our ontology
m.addAxiom(o, rangeAxiom);
// Now create a datatype definition axiom
OWLDatatypeDefinitionAxiom datatypeDef = df
.getOWLDatatypeDefinitionAxiom(
df.getOWLDatatype(IRI
.create("http://www.semanticweb.org/ontologies/dataranges#age")),
integerGE18);
// Add the definition to our ontology
m.addAxiom(o, datatypeDef);
// Dump our ontology
StreamDocumentTarget target = new StreamDocumentTarget(
new ByteArrayOutputStream());
m.saveOntology(o, target);
}