public boolean addRecipe(IRI recipeName, Vector<IRI> rules, String recipeDescription) {
boolean ok = false;
OWLClass ontocls = factory.getOWLClass(IRI.create(owlIDrmi + "Recipe"));
OWLClass kresrule = factory.getOWLClass(IRI.create(owlIDrmi + "KReSRule"));
OWLNamedIndividual ontoind = factory.getOWLNamedIndividual(recipeName);
OWLDataProperty description = factory.getOWLDataProperty(IRI.create(owlIDrmi + "hasDescription"));
OWLDataProperty sequence = factory.getOWLDataProperty(IRI.create(owlIDrmi + "hasSequence"));
OWLObjectProperty hasrule = factory.getOWLObjectProperty(IRI.create(owlIDrmi + "hasRule"));
OWLObjectProperty start = factory.getOWLObjectProperty(IRI.create(owlIDrmi + "startWith"));
OWLObjectProperty end = factory.getOWLObjectProperty(IRI.create(owlIDrmi + "endWith"));
OWLObjectProperty precedes = factory.getOWLObjectProperty(IRI.create("http://www.ontologydesignpatterns.org/cp/owl/sequence.owl#directlyPrecedes"));
OWLObjectPropertyAssertionAxiom objectPropAssertion;
if (((recipeName != null) || !recipeName.toString().isEmpty()) && ((rules != null) || !rules.isEmpty())) {
if (!owlmodel.containsAxiom(factory.getOWLClassAssertionAxiom(ontocls, ontoind))) {
//Add the rule istance
OWLClassAssertionAxiom classAssertion = factory.getOWLClassAssertionAxiom(ontocls, ontoind);
owlmanager.addAxiom(owlmodel, classAssertion);
//start and end
OWLNamedIndividual ind = factory.getOWLNamedIndividual(rules.firstElement());
if (owlmodel.containsAxiom(factory.getOWLClassAssertionAxiom(kresrule, ind))) {
objectPropAssertion = factory.getOWLObjectPropertyAssertionAxiom(start, ontoind, ind);
owlmanager.addAxiom(owlmodel, objectPropAssertion);
ok = true;
} else {
log.error("The rule with IRI " + ind.getIRI() + " is not inside the ontology. Pleas check its IRI.");
ok = false;
return (ok);
}
ind = factory.getOWLNamedIndividual(rules.lastElement());
if (owlmodel.containsAxiom(factory.getOWLClassAssertionAxiom(kresrule, ind))) {
objectPropAssertion = factory.getOWLObjectPropertyAssertionAxiom(end, ontoind, ind);
owlmanager.addAxiom(owlmodel, objectPropAssertion);
ok = true;
} else {
log.error("The rule with IRI " + ind.getIRI() + " is not inside the ontology. Pleas check its IRI.");
ok = false;
return (ok);
}
//Add the sequence string
OWLDataPropertyAssertionAxiom dataPropAssertion = factory.getOWLDataPropertyAssertionAxiom(sequence, ontoind, rules.toString().replace("[", "").replace("]", ""));
owlmanager.addAxiom(owlmodel, dataPropAssertion);
//Add description
if ((recipeDescription != null) || !recipeDescription.isEmpty()) {
//Add the rule description
dataPropAssertion = factory.getOWLDataPropertyAssertionAxiom(description, ontoind, recipeDescription);
owlmanager.addAxiom(owlmodel, dataPropAssertion);
ok = true;
}
//Add single rule
/*
* BUGFIX - previously the check was done on rules.size()-1.
* The right code is rules.size(). Moreover is need also a control "if(r+1>(rules.size()-1)) break;" because the last rule has not successive rules.
*
*/
for (int r = 0; r < rules.size(); r++) {
ind = factory.getOWLNamedIndividual(rules.get(r));
if (owlmodel.containsAxiom(factory.getOWLClassAssertionAxiom(kresrule, ind))) {
//Add the rule to the recipes
objectPropAssertion = factory.getOWLObjectPropertyAssertionAxiom(hasrule, ontoind, ind);
owlmanager.addAxiom(owlmodel, objectPropAssertion);
ok = true;
//Add precedes
if (r + 1 > (rules.size() - 1)) {
break;
}
OWLNamedIndividual indf = factory.getOWLNamedIndividual(rules.get(r + 1));
if (owlmodel.containsAxiom(factory.getOWLClassAssertionAxiom(kresrule, indf))) {
objectPropAssertion = factory.getOWLObjectPropertyAssertionAxiom(precedes, ind, indf);
owlmanager.addAxiom(owlmodel, objectPropAssertion);
ok = true;
} else {
log.error("The rule with IRI " + indf.getIRI() + " is not inside the ontology. Pleas check its IRI.");
ok = false;
return (ok);
}
} else {
log.error("The rule with IRI " + ind.getIRI() + " is not inside the ontology. Pleas check its IRI.");