So I have been able to add some classes to an ontology and save them to a file. Now I would like to be able to add a Datatype to my class but I am confused about how to do this probably very simple thing. This is what I have been trying:
OWLClass currentClass =df.getOWLClass(IRI.create("Base"));
OWLDataProperty owlAttr = df.getOWLDataProperty(IRI.create("#" + "name");
OWLLiteralImplString lit = new OWLLiteralImplString("test"); //This is probably on the wrong path
DefaultPrefixManager defaultPrefixManager = new DefaultPrefixManager();
OWLDatatype datatype = df.getOWLDatatype("xsd:string",defaultPrefixManager);
OWLAxiom axiom = df.getOWLDatatypeDefinitionAxiom(datatype, ?); //having trouble find a range.
Edit #1 So I'm a little concerned my question isn't clear. What I am trying to do would be similar to this in Java:
public class Car{
}
I currently am able to create a class using the owlapi but what I am looking to do would be like adding a datamember to my Java class:
public class Car{
public String manufacturer;
}
Using Protege I can produce this which I think is what I want to be able to make with the owlapi:
<!-- http://www.co-ode.org/ontologies/ont.owl#manufacturer -->
<DatatypeProperty rdf:about="http://www.co-ode.org/ontologies/ont.owl#manufacturer">
<rdfs:domain rdf:resource="http://www.co-ode.org/ontologies/ont.owl#Car"/>
<rdfs:range rdf:resource="&xsd;string"/>
</DatatypeProperty>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.co-ode.org/ontologies/ont.owl#Car -->
<Class rdf:about="http://www.co-ode.org/ontologies/ont.owl#Car"/>
Something like this might help:
OWLDatatype datatype = factory.getOWLDatatype("xsd:string",pm);
OWLLiteral lit= factory.getOWLLiteral("1", datatype);
Maybe you want to define min and max restriction:
OWLDataUnionOf union = factory.getOWLDataUnionOf( factory.getOWLDatatypeMinInclusiveRestriction(1), factory.getOWLDatatypeMaxInclusiveRestriction(10));
OWLDatatypeDefinitionAxiom axiom = factory.getOWLDatatypeDefinitionAxiom(datatype, union);
Edit #1: I have added new code based on the edited question.
PrefixManager pm= new DefaultPrefixManager("http://www.co-ode.org/ontologies/ont.owl#");
OWLDataPropertyExpression man= factory.getOWLDataProperty("manufacturer", pm);
OWLClass car= factory.getOWLClass("Car", pm);
OWLDatatype dt = factory.getOWLDatatype("xsd:string",pm);
OWLDataPropertyDomainAxiom domain=factory.getOWLDataPropertyDomainAxiom(man, car);
OWLDataPropertyRangeAxiom range= factory.getOWLDataPropertyRangeAxiom(man, dt);