manager.applyChange(new AddAxiom(ont, axiom4));
// In the above code, 33 is an integer, so we can just pass 33 into the
// data factory method. Behind the scenes the OWL API will create a
// typed constant that it will use as the value of the data property
// assertion. We could have manually created the constant as follows:
OWLDatatype intDatatype = factory.getIntegerOWLDatatype();
OWLLiteral thirtyThree = factory.getOWLLiteral("33", intDatatype);
// We would then create the axiom as follows:
factory.getOWLDataPropertyAssertionAxiom(hasAge, john, thirtyThree);
// However, the convenice method is much shorter! We can now create the
// other facts/assertion for Mary. The OWL API uses a change object
// model, which means we can stack up changes (or sets of axioms) and
// apply the changes (or add the axioms) in one go. We will do this for
// Mary
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
axioms.add(factory.getOWLObjectPropertyAssertionAxiom(hasSon, mary,
bill));
axioms.add(factory.getOWLObjectPropertyAssertionAxiom(hasDaughter,
mary, susan));
axioms.add(factory.getOWLDataPropertyAssertionAxiom(hasAge, mary, 31));
// Add facts/assertions for Bill and Susan
axioms.add(factory.getOWLDataPropertyAssertionAxiom(hasAge, bill, 13));
axioms.add(factory.getOWLDataPropertyAssertionAxiom(hasAge, mary, 8));
// Now add all the axioms in one go - there is a convenience method on
// OWLOntologyManager that will automatically generate the AddAxiom
// change objects for us. We need to specify the ontology that the
// axioms should be added to and the axioms to add.
manager.addAxioms(ont, axioms);
// Now specify the genders of John, Mary, Bill and Susan. To do this we
// need the male and female individuals and the hasGender object
// property.
OWLIndividual male = factory.getOWLNamedIndividual(IRI
.create(ontologyIRI + "#male"));
OWLIndividual female = factory.getOWLNamedIndividual(IRI
.create(ontologyIRI + "#female"));
OWLObjectProperty hasGender = factory.getOWLObjectProperty(IRI
.create(ontologyIRI + "#hasGender"));
Set<OWLAxiom> genders = new HashSet<OWLAxiom>();
genders.add(factory.getOWLObjectPropertyAssertionAxiom(hasGender, john,
male));
genders.add(factory.getOWLObjectPropertyAssertionAxiom(hasGender, mary,
female));
genders.add(factory.getOWLObjectPropertyAssertionAxiom(hasGender, bill,
male));
genders.add(factory.getOWLObjectPropertyAssertionAxiom(hasGender,
susan, female));
// Add the facts about the genders
manager.addAxioms(ont, genders);
// Domain and Range Axioms //At this point, we have an ontology
// containing facts about several individuals. We now want to specify
// more information about the various properties that we have used. We
// want to say that the domains and ranges of hasWife, hasSon and
// hasDaughter are the class Person. To do this we need various domain
// and range axioms, and we need a reference to the class Person First
// get a reference to the person class
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI
+ "#Person"));
// Now we add the domain and range axioms that specify the domains and
// ranges of the various properties that we are interested in.
Set<OWLAxiom> domainsAndRanges = new HashSet<OWLAxiom>();
// Domain and then range of hasWife
domainsAndRanges.add(factory.getOWLObjectPropertyDomainAxiom(hasWife,
person));
domainsAndRanges.add(factory.getOWLObjectPropertyRangeAxiom(hasWife,
person));
// Domain and range of hasSon and also hasDaugher
domainsAndRanges.add(factory.getOWLObjectPropertyDomainAxiom(hasSon,
person));
domainsAndRanges.add(factory.getOWLObjectPropertyRangeAxiom(hasSon,
person));
domainsAndRanges.add(factory.getOWLObjectPropertyDomainAxiom(
hasDaughter, person));
domainsAndRanges.add(factory.getOWLObjectPropertyRangeAxiom(
hasDaughter, person));
// We also have the domain of the data property hasAge as Person, and
// the range as integer. We need the integer datatype. The XML Schema
// Datatype URIs are used for data types. The OWL API provide a built in
// set via the XSDVocabulary enum.
domainsAndRanges.add(factory.getOWLDataPropertyDomainAxiom(hasAge,
person));
OWLDatatype integerDatatype = factory.getIntegerOWLDatatype();
domainsAndRanges.add(factory.getOWLDataPropertyRangeAxiom(hasAge,
integerDatatype));
// Now add all of our domain and range axioms
manager.addAxioms(ont, domainsAndRanges);
// Class assertion axioms //We can also explicitly say than an