use of org.semanticweb.owlapi.model.SWRLRule in project stanbol by apache.
the class HermitReasoningServiceTest method testEnrichWithRules.
private void testEnrichWithRules(String testID, String rulesID, String testExpectedID) {
log.info("Testing the task ENRICH with rules");
OWLOntologyManager manager = TestData.manager;
// We prepare the input ontology
try {
OWLOntology testOntology = manager.createOntology();
OWLOntologyID testOntologyID = testOntology.getOntologyID();
log.debug("Created test ontology with ID: {}", testOntologyID);
OWLImportsDeclaration importTest = TestData.factory.getOWLImportsDeclaration(IRI.create(testID));
manager.applyChange(new AddImport(testOntology, importTest));
Set<SWRLRule> rules = manager.getOntology(IRI.create(rulesID)).getAxioms(AxiomType.SWRL_RULE);
// Maybe we want to see the list of rules
if (log.isDebugEnabled()) {
log.debug("List of {} rules: ", rules.size());
TestUtils.debug(rules, log);
}
log.debug("We add the rules to the ontology");
manager.addAxioms(manager.getOntology(testOntologyID), rules);
// Maybe we want to see what is in before
if (log.isDebugEnabled())
log.debug("Content of the input is:");
TestUtils.debug(manager.getOntology(testOntologyID), log);
// Now we test the method
log.debug("Running HermiT");
Set<OWLAxiom> inferred = this.theinstance.runTask(ReasoningService.Tasks.ENRICH, manager.getOntology(testOntologyID));
// Maybe we want to see the inferred axiom list
if (log.isDebugEnabled()) {
log.debug("{} inferred axioms:", inferred.size());
TestUtils.debug(inferred, log);
}
Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(IRI.create(testExpectedID)).getLogicalAxioms();
Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
for (OWLAxiom expected : expectedAxioms) {
// We consider here all kind of axioms
if (!inferred.contains(expected)) {
log.error("missing expected axiom: {}", expected);
missing.add(expected);
}
}
assertTrue(missing.isEmpty());
// We want to remove the ontology from the manager
manager.removeOntology(testOntology);
} catch (OWLOntologyCreationException e) {
log.error("An {} have been thrown while creating the input ontology for test", e.getClass());
assertTrue(false);
} catch (ReasoningServiceException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (InconsistentInputException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
} catch (UnsupportedTaskException e) {
log.error("An {} have been thrown while executing the reasoning", e.getClass());
assertTrue(false);
}
}
use of org.semanticweb.owlapi.model.SWRLRule in project stanbol by apache.
the class SWRLAdpterTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
try {
List<SWRLRule> rules = (List<SWRLRule>) ruleAdapter.adaptTo(recipeGood, SWRLRule.class);
StringBuilder sb = new StringBuilder();
for (SWRLRule rule : rules) {
sb.append(rule.toString());
}
Assert.assertNotSame(sb.toString(), "");
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
Assert.fail(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
}
}
use of org.semanticweb.owlapi.model.SWRLRule in project stanbol by apache.
the class AbstractOWLApiReasoningService method run.
/**
* Merges the SWRL rules in the input ontology, then calls run(OWLOntology,List<InferredAxiomGenerator<?
* extends OWLAxiom>>)
*
* @param ontology
* @param rules
* @param generators
* @return
*/
@Override
public Set<OWLAxiom> run(OWLOntology ontology, List<SWRLRule> rules, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException, InconsistentInputException {
log.debug("Called method run(OWLOntology,List<SWRLRule>,List)");
OWLOntologyManager manager = ontology.getOWLOntologyManager();
log.debug("Adding SWRL rules to the input ontology.");
Set<SWRLRule> ruleSet = new HashSet<SWRLRule>();
ruleSet.addAll(rules);
manager.addAxioms(ontology, ruleSet);
if (log.isDebugEnabled())
for (OWLAxiom a : ontology.getAxioms()) {
log.debug("Axiom {}", a);
}
log.debug("Calling the run method.");
return run(ontology, generators);
}
Aggregations