import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; //import org.semanticweb.owl.inference.OWLReasonerAdapter; //import org.semanticweb.owl.inference.OWLReasonerException; import org.semanticweb.owl.inference.OWLReasonerFactory; import org.semanticweb.owl.model.*; //import org.semanticweb.owl.util.DLExpressivityChecker; //import org.semanticweb.reasonerfactory.pellet.PelletReasonerFactory; import org.mindswap.pellet.owlapi.PelletReasonerFactory; import java.net.URI; import java.util.Set; import java.io.*; public class OCEAN { public static final String PHYSICAL_URI = "file:ontology/TemporalPropEvent.owl"; public static void main(String[] args) { try { Writer output = null; File file = new File("System_state.txt"); output = new BufferedWriter(new FileWriter(file)); // Create our ontology manager in the usual way. OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); // Load a copy of the ontology. OWLOntology ontology = manager.loadOntologyFromPhysicalURI(URI.create(PHYSICAL_URI)); System.out.println("Loaded " + ontology.getURI()); URI ontologyURI = URI.create("http://www.owl-ontologies.com/Ontology1228491465.owl"); // We need a data factory to create various object from. Each ontology has a reference // to a data factory that we can use. OWLDataFactory factory = manager.getOWLDataFactory(); OWLClass IsTrue = factory.getOWLClass(URI.create(ontologyURI+"#IsTrue")); OWLClass KisTrue = factory.getOWLClass(URI.create(ontologyURI+"#KisTrue")); OWLClass IsFalse = factory.getOWLClass(URI.create(ontologyURI+"#IsFalse")); OWLClass KisFalse = factory.getOWLClass(URI.create(ontologyURI+"#KisFalse")); OWLClass IsPending = factory.getOWLClass(URI.create(ontologyURI+"#IsPending")); OWLClass IsFulfilled = factory.getOWLClass(URI.create(ontologyURI+"#IsFulfilled")); OWLClass IsViolated = factory.getOWLClass(URI.create(ontologyURI+"#IsViolated")); output.write("COMMITMENT INDIVIDUALS\n"); OWLClass Commitment=factory.getOWLClass(URI.create(ontologyURI+"#Commitment")); for(OWLIndividual ind: Commitment.getIndividuals(ontology)){ output.write(" " + ontology.getObjectPropertyAssertionAxioms(ind)+"\n"); } output.write("TPPOS INDIVIDUALS\n"); OWLClass TPPos=factory.getOWLClass(URI.create(ontologyURI+"#TPPos")); for(OWLIndividual ind: TPPos.getIndividuals(ontology)){ output.write(" " + ontology.getDataPropertyAssertionAxioms(ind)+"\n"); output.write(" " + ontology.getObjectPropertyAssertionAxioms(ind)+"\n"); } output.write("TPNEG INDIVIDUALS\n"); OWLClass TPNeg=factory.getOWLClass(URI.create(ontologyURI+"#TPNeg")); for(OWLIndividual ind: TPNeg.getIndividuals(ontology)){ output.write(" " + ontology.getDataPropertyAssertionAxioms(ind)+"\n"); output.write(" " + ontology.getObjectPropertyAssertionAxioms(ind)+"\n"); } output.write("HISTORY OF THE SYSTEM\n"); OWLClass Action=factory.getOWLClass(URI.create(ontologyURI+"#Action")); for(OWLIndividual ind: Action.getIndividuals(ontology)){ output.write(" " + ontology.getDataPropertyAssertionAxioms(ind)+"\n"); } output.write("-------------------------------------------------------------------\n"); Set isTrueIndividuals; OWLDescription description; OWLAxiom axiom; AddAxiom addAxiom; Set isFalseIndividuals; /* //assert KisTrue=retrieve(IsTrue) and KisFalse=retrieve(IsFalse) //create a set with all the individuals that for the reasoner belong to IsTrue isTrueIndividuals=IsTrue.getIndividuals(ontology); //create a class with all those individuals description = factory.getOWLObjectOneOf(isTrueIndividuals); //create an Equivalent Axiom axiom = factory.getOWLEquivalentClassesAxiom(KisTrue, description); // We now add the axiom to the ontology, To do this we create an AddAxiom change object. addAxiom = new AddAxiom(ontology, axiom); // We now use the manager to apply the change manager.applyChange(addAxiom); isFalseIndividuals=IsFalse.getIndividuals(ontology); description = factory.getOWLObjectOneOf(isFalseIndividuals); axiom = factory.getOWLEquivalentClassesAxiom(KisFalse, description); addAxiom = new AddAxiom(ontology, axiom); manager.applyChange(addAxiom); */ System.out.println("Equivalent classes axioms of class KisTrue: " + ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisTrue")))); System.out.println("Equivalent classes axioms of class KisFalse: " + ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisFalse")))); // output.write("Dynamic evolution of the state of the system"); output.write(""+ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisTrue")))+"\n"); output.write(""+ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisFalse")))+"\n"); int t=0; int tMax=5; OWLIndividual elapse = factory.getOWLIndividual(URI.create(ontologyURI+"#elapse")); OWLDataProperty happensAt=factory.getOWLDataProperty(URI.create(ontologyURI+"#happensAt")); OWLDataPropertyAssertionAxiom assertion; AddAxiom addAxiomChange; RemoveAxiom removeAxiom; System.out.println("Start the simulation"); output.write("START THE SIMULATION"+"\n"); while (t importsClosure = manager.getImportsClosure(ontology); reasoner.loadOntologies(importsClosure); reasoner.classify(); System.out.println("Instances of IsPending: "); output.write("Instances of IsPending: "+"\n"); for(OWLIndividual ind : reasoner.getIndividuals(IsPending, true)) { System.out.println(" " + ind); output.write(" "+ ind+"\n"); } System.out.println("Instances of IsFulfilled: "); output.write("Instances of IsFulfilled: "+"\n"); for(OWLIndividual ind : reasoner.getIndividuals(IsFulfilled, true)) { System.out.println(" " + ind); output.write(" "+ ind+"\n"); } System.out.println("Instances of IsViolated: "); output.write("Instances of IsViolated: "+"\n"); for(OWLIndividual ind : reasoner.getIndividuals(IsViolated, true)) { System.out.println(" " + ind); output.write(" "+ ind+"\n"); } System.out.println("Instances of IsTrue: "); output.write("Instances of IsTrue: "+"\n"); for(OWLIndividual ind : reasoner.getIndividuals(IsTrue, false)) { System.out.println(" " + ind); output.write(" "+ ind+"\n"); } System.out.println("Instances of IsFalse: "); output.write("Instances of IsFalse: "+"\n"); for(OWLIndividual ind : reasoner.getIndividuals(IsFalse, false)) { System.out.println(" " + ind); output.write(" "+ ind+"\n"); } // Now we want to specify that KIsTrue=retrieve(IsTrue) and KIsFalse=retrieve(IsFalse). //create a set with all the individuals that for the reasoner belong to IsTrue isTrueIndividuals=reasoner.getIndividuals(IsTrue, false); //add to the set all the individuals asserted in the ontology to be IsTrue for(OWLIndividual ind: IsTrue.getIndividuals(ontology)) isTrueIndividuals.add(ind); //create a class with all those individuals description = factory.getOWLObjectOneOf(isTrueIndividuals); //remove the axioms that define KisTrue and KisFalse for(OWLAxiom a: ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisTrue")))){ removeAxiom= new RemoveAxiom(ontology,a); manager.applyChange(removeAxiom); } //create the Equivalent Axioms that define KisTrue and KisFalse axiom = factory.getOWLEquivalentClassesAxiom(KisTrue, description); // We now add the axiom to the ontology, To do this we create an AddAxiom change object. addAxiom = new AddAxiom(ontology, axiom); // We now use the manager to apply the change manager.applyChange(addAxiom); isFalseIndividuals=reasoner.getIndividuals(IsFalse, false); for(OWLIndividual ind: IsFalse.getIndividuals(ontology)) isFalseIndividuals.add(ind); description = factory.getOWLObjectOneOf(isFalseIndividuals); for(OWLAxiom a: ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisFalse")))){ removeAxiom= new RemoveAxiom(ontology,a); manager.applyChange(removeAxiom); } axiom = factory.getOWLEquivalentClassesAxiom(KisFalse, description); addAxiom = new AddAxiom(ontology, axiom); manager.applyChange(addAxiom); System.out.println("Equivalent classes axioms of class KisTrue: " + ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisTrue")))); System.out.println("Equivalent classes axioms of class KisFalse: " + ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisFalse")))); output.write(" " + ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisTrue")))+"\n"); output.write(" "+ontology.getEquivalentClassesAxioms(factory.getOWLClass(URI.create(ontologyURI+"#KisFalse")))+"\n"); // Now save the ontology. The ontology will be saved to the location where // we loaded it from, in the default ontology format //manager.saveOntology(ontology, URI.create("file:/ontology/example.owl")); //increment the system time t++; } output.close(); } catch (OWLException e) { e.printStackTrace(); } catch(UnsupportedOperationException exception) { System.out.println("Unsupported reasoner operation."); } catch(IOException exception) { System.out.println("problem with the output file"); } /*catch(OWLReasonerException ex) { System.out.println("Reasoner error: " + ex.getMessage()); } catch (OWLOntologyCreationException e) { System.out.println("Could not load the pizza ontology: " + e.getMessage()); }*/ } }