You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by en...@apache.org on 2011/08/19 21:58:29 UTC

svn commit: r1159764 [1/4] - in /incubator/stanbol/branches/jena-reasoners/reasoners/hermit: ./ src/main/java/org/apache/stanbol/reasoners/hermit/ src/test/java/org/apache/stanbol/reasoners/hermit/ src/test/resources/

Author: enridaga
Date: Fri Aug 19 19:58:28 2011
New Revision: 1159764

URL: http://svn.apache.org/viewvc?rev=1159764&view=rev
Log:
Implementation of the OWLApi reasoning service for HermiT (STANBOL-185)

Added:
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/HermitReasoningServiceTest.java
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestData.java
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestUtils.java
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/catalog-v001.xml
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/dbpedia_3.6.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/example.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/foaf.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/foaf.rdf   (with props)
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/log4j.properties
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_1.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_1_expected.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_2.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_2_expected.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_3.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_3_expected.owl
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/test_3_rules.owl
Modified:
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml?rev=1159764&r1=1159763&r2=1159764&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml (original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml Fri Aug 19 19:58:28 2011
@@ -17,19 +17,18 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
-  <modelVersion>4.0.0</modelVersion>
 
   <parent>
     <groupId>org.apache.stanbol</groupId>
     <artifactId>stanbol-parent</artifactId>
     <version>0.9.0-incubating-SNAPSHOT</version>
-    <relativePath>../../parent</relativePath>
+    <relativePath>../../../trunk/parent</relativePath>
   </parent>
-
+<modelVersion>4.0.0</modelVersion>
   <artifactId>org.apache.stanbol.reasoners.hermit</artifactId>
   <packaging>bundle</packaging>
 
-  <name>Apache Stanbol Reasoners Hermit Dependency</name>
+  <name>Apache Stanbol Reasoners: Hermit</name>
 
   <repositories>
      <repository>
@@ -56,7 +55,18 @@
       <scope>compile</scope>
     </dependency>
     
-		<!-- Testing deps -->
+		<!--Diagnostic dependencies -->
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<scope>runtime</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<scope>runtime</scope>
+		</dependency>
+		<!-- Dependencies for test -->
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
@@ -67,23 +77,47 @@
 			<artifactId>slf4j-log4j12</artifactId>
 			<scope>test</scope>
 		</dependency>
-    
+		<!-- osgi dependencies -->
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.scr.annotations</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		
+		<!-- Stanbol dependencies -->
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.reasoners.owlapi</artifactId>
+			<version>0.1</version>
+		</dependency>
   </dependencies>
   
   <build>
+  <!-- make it an OSGi bundle -->
     <plugins>
+    	<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-scr-plugin</artifactId>
+			</plugin>
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <version>2.0.1</version>
         <extensions>true</extensions>
         <configuration>
           <instructions>
             <Bundle-ClassPath>.</Bundle-ClassPath>
             <Export-Package>
-              com.clarkparsia.owlapi.explanation,
-              com.clarkparsia.owlapi.explanation.io,
-              com.clarkparsia.owlapi.explanation.util,
+              com.clarkparsia.owlapi.explanation.*,
               com.clarkparsia.owlapi.modularity.locality,
               de.uulm.ecs.ai.owlapi.krssparser,
               de.uulm.ecs.ai.owlapi.krssrenderer,
@@ -140,10 +174,9 @@
           </instructions>
         </configuration>
       </plugin>
-      <plugin>
+      <!-- plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
-        <version>2.0.2</version>
         <configuration>
           <source>1.6</source>
           <target>1.6</target>
@@ -153,114 +186,10 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-resources-plugin</artifactId>
-        <!--  version>2.2</version-->
         <configuration>
           <encoding>${project.build.sourceEncoding}</encoding>
         </configuration>
-      </plugin>
+      </plugin-->
     </plugins>
   </build>
-
-  <profiles>
-    <profile>
-      <!-- this profile executes the bundle on apache felix-->
-      <id>run-on-felix</id>
-      <dependencies>
-        <dependency>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>org.apache.felix.main</artifactId>
-          <version>2.0.2</version>
-          <scope>provided</scope>
-        </dependency>
-        <dependency>
-          <groupId>org.apache.felix.gogo</groupId>
-          <artifactId>org.apache.felix.gogo.commands</artifactId>
-          <version>0.2.2</version>
-        </dependency>
-      </dependencies>
-
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-antrun-plugin</artifactId>
-            <version>1.3</version>
-            <executions>
-              <execution>
-                <id>compile</id>
-                <phase>compile</phase>
-                <goals>
-                  <goal>run</goal>
-                </goals>
-                <configuration>
-                  <tasks>
-                    <property name="plugins" refid="maven.runtime.classpath"/>
-                    <pathconvert pathsep=" " dirsep="/"
-                                 property="project.build.url">
-                      <path path="${project.build.directory}"/>
-                    </pathconvert>
-                    <pathconvert property="plugins.jars" pathsep=":">
-                      <path path="${plugins}"/>
-                      <map from="${project.build.directory}/classes" to=""/>
-                    </pathconvert>
-                    <makeurl property="urls" separator=" " validate="false">
-                      <path path="${plugins.jars}"/>
-                    </makeurl>
-                    <pathconvert pathsep=" " property="bundles">
-                      <path path="${plugins}"/>
-                      <mapper>
-                        <chainedmapper>
-                          <flattenmapper/>
-                          <globmapper from="*" to="file:modules/*"
-                                      casesensitive="no"/>
-                        </chainedmapper>
-                      </mapper>
-                    </pathconvert>
-                    <makeurl property="main.bundle.url"
-                             file="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
-                    <echo file="${project.build.directory}/run.properties">
-                      felix.auto.install=${urls}
-                      felix.auto.start=${main.bundle.url}
-                      org.osgi.framework.storage=${project.build.url}/felix-cache
-                      org.osgi.framework.bootdelegation=*
-                    </echo>
-                    <replace file="${project.build.directory}/run.properties"
-                             token="\" value="\\"/>
-                    <echo file="${project.build.directory}/config.properties">
-                      felix.auto.install="${bundles}"
-                      felix.auto.start=file:modules/${project.artifactId}-${project.version}.jar
-                    </echo>
-                    <copy
-                        file="${maven.dependency.org.apache.felix.org.apache.felix.main.jar.path}"
-                        tofile="${project.build.directory}/felix.jar"/>
-                  </tasks>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
-          <plugin>
-            <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-assembly-plugin</artifactId>
-            <version>2.2-beta-5</version>
-            <executions>
-              <execution>
-                <id>create-executable-jar</id>
-                <phase>package</phase>
-                <goals>
-                  <goal>single</goal>
-                </goals>
-                <configuration>
-                  <descriptors>
-                    <descriptor>${basedir}/src/main/assembly/felix.xml</descriptor>
-                  </descriptors>
-                  <finalName>${project.artifactId}-${project.version}</finalName>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-  </profiles>
-  <groupId>org.apache.stanbol</groupId>
 </project>

Added: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java?rev=1159764&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java (added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java Fri Aug 19 19:58:28 2011
@@ -0,0 +1,25 @@
+package org.apache.stanbol.reasoners.hermit;
+
+import org.apache.stanbol.reasoners.owlapi.AbstractOWLApiReasoningService;
+import org.apache.stanbol.reasoners.owlapi.OWLApiReasoningService;
+import org.semanticweb.HermiT.Configuration;
+import org.semanticweb.HermiT.Reasoner.ReasonerFactory;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.reasoner.OWLReasoner;
+
+/**
+ * This class is the implementation of {@see OWLApiReasoningService} using the
+ * HermiT reasoner
+ */
+public class HermitReasoningService extends AbstractOWLApiReasoningService
+		implements OWLApiReasoningService {
+
+	@Override
+	protected OWLReasoner getReasoner(OWLOntology ontology) {
+		Configuration config = new Configuration();
+		config.ignoreUnsupportedDatatypes = true;
+		ReasonerFactory risfactory = new ReasonerFactory();
+		return risfactory.createReasoner(ontology, config);
+	}
+
+}

Added: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/HermitReasoningServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/HermitReasoningServiceTest.java?rev=1159764&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/HermitReasoningServiceTest.java (added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/HermitReasoningServiceTest.java Fri Aug 19 19:58:28 2011
@@ -0,0 +1,620 @@
+package org.apache.stanbol.reasoners.hermit;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.stanbol.reasoners.owlapi.InconsistentInputException;
+import org.apache.stanbol.reasoners.owlapi.OWLApiReasoningServiceException;
+import org.junit.Before;
+import org.junit.Test;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.AxiomType;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLImportsDeclaration;
+import org.semanticweb.owlapi.model.OWLLogicalAxiom;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyID;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
+import org.semanticweb.owlapi.model.SWRLRule;
+import org.semanticweb.owlapi.reasoner.OWLReasoner;
+import org.semanticweb.owlapi.util.InferredAxiomGenerator;
+import org.semanticweb.owlapi.util.InferredClassAssertionAxiomGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for the HermitReasoningService These tests should be significant for
+ * any OWLApiReasoningService.
+ * 
+ * TODO: we may want to isolate this is a separate test mini-framework.
+ * 
+ */
+public class HermitReasoningServiceTest {
+	private static final Logger log = LoggerFactory
+			.getLogger(HermitReasoningServiceTest.class);
+
+	private HermitReasoningService theinstance;
+
+	/**
+	 * This method instantiate the reasoning services to work with in this tests
+	 */
+	@Before
+	public void setUp() {
+		this.theinstance = new HermitReasoningService();
+	}
+
+	@Test
+	public void testInstantiation() {
+		log.info("Testing the innstantiation of an HermitReasoningService");
+		OWLOntology foaf = TestData.manager.getOntology(IRI
+				.create(TestData.FOAF_NS));
+		// Here we want to be sure that the getReasoner() method creates an
+		// instance correctly
+		HermitReasoningService akindofhermit = new HermitReasoningService() {
+			protected OWLReasoner getReasoner(OWLOntology ontology) {
+				try {
+					OWLReasoner reasoner = super.getReasoner(ontology);
+					assertTrue(reasoner != null);
+					return reasoner;
+				} catch (Throwable t) {
+					log.error(
+							"Some prolem occurred while instantiating the HermitReasoningService. Message was: {}",
+							t.getLocalizedMessage());
+					// We force tests to stop here
+					assertTrue(false);
+					return null;
+				}
+			}
+		};
+		long startHere = System.currentTimeMillis();
+		// This is possible only because the subclass is in this scope...
+		akindofhermit.getReasoner(foaf);
+		long endHere = System.currentTimeMillis();
+		log.info("Instantiating an Hermit reasoner lasts {} milliseconds",
+				(endHere - startHere));
+	}
+
+	private void testRun(String testID, String expectedID) {
+		log.info("Testing the run() method");
+		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);
+			AddImport addImport = new AddImport(testOntology,
+					TestData.factory.getOWLImportsDeclaration(IRI
+							.create(testID)));
+			manager.applyChange(addImport);
+			// We just test class assertions
+			List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
+			gens.add(new InferredClassAssertionAxiomGenerator());
+
+			// Maybe we want to see what is in before
+			if (log.isDebugEnabled())
+				TestUtils.debug(manager.getOntology(testOntologyID), log);
+
+			// Now we test the method
+			log.debug("Running HermiT");
+			Set<OWLAxiom> inferred = this.theinstance.run(
+					manager.getOntology(testOntologyID), gens);
+
+			// Maybe we want to see the inferred axiom list
+			if (log.isDebugEnabled()) {
+				TestUtils.debug(inferred, log);
+			}
+			// These are the set of expected axioms
+			Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(
+					IRI.create(expectedID)).getLogicalAxioms();
+
+			Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
+			for (OWLAxiom expected : expectedAxioms) {
+				if (!inferred.contains(expected)) {
+					log.error("missing expected axiom: {}", expected);
+					missing.add(expected);
+				}
+			}
+			log.info("Are all expected axioms in the result (true)? {}",
+					missing.isEmpty());
+			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 (OWLApiReasoningServiceException 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);
+		}
+	}
+
+	@Test
+	public void testRun() {
+		testRun(TestData.TEST_1_NS, TestData.TEST_1_expected_NS);
+	}
+
+	/**
+	 * Tests the classify() method
+	 */
+	@Test
+	public void testClassify() {
+		testClassify(TestData.TEST_1_NS, TestData.TEST_1_expected_NS);
+	}
+
+	/**
+	 * We may want to test this method with more then 1 ontology. This is why
+	 * the implementation is in aprivate method. This method tests if all the
+	 * logical axioms in testExpectedID ontology are inferences of the testID
+	 * ontology.
+	 * 
+	 * @param testID
+	 *            // The ID of the ontology to be the input (loaded in the
+	 *            TestData.manager)
+	 * @param testExpectedID
+	 *            // The ID of the ontology which contains logical axioms
+	 *            expected in the result
+	 */
+	private void testClassify(String testID, String testExpectedID) {
+		log.info("Testing the classify() method");
+
+		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);
+			manager.applyChange(new AddImport(testOntology, TestData.factory
+					.getOWLImportsDeclaration(IRI.create(testID))));
+
+			// We want class assertions
+			List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
+			gens.add(new InferredClassAssertionAxiomGenerator());
+
+			// Maybe we want to see what is in before
+			if (log.isDebugEnabled())
+				TestUtils.debug(manager.getOntology(testOntologyID), log);
+
+			// Now we test the method
+			log.debug("Running HermiT");
+			Set<OWLAxiom> inferred = this.theinstance.run(
+					manager.getOntology(testOntologyID), gens);
+
+			// Maybe we want to see the inferred axiom list
+			if (log.isDebugEnabled()) {
+				TestUtils.debug(inferred, log);
+			}
+
+			Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(
+					IRI.create(testExpectedID)).getLogicalAxioms();
+			Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
+			for (OWLAxiom expected : expectedAxioms) {
+				if (!inferred.contains(expected)) {
+					log.error("missing expected axiom: {}", expected);
+					missing.add(expected);
+				}
+			}
+			assertTrue(missing.isEmpty());
+
+			// We want only ClassAssertionAxioms in the result set
+			for (OWLAxiom a : inferred) {
+				assertTrue(a instanceof OWLClassAssertionAxiom);
+			}
+			// 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 (OWLApiReasoningServiceException 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);
+		}
+	}
+
+	/**
+	 * We may want to test this method with more then 1 ontology. This is why
+	 * the implementation is in aprivate method. This method tests if all the
+	 * logical axioms in testExpectedID ontology are inferences of the testID
+	 * ontology.
+	 * 
+	 * TODO: This method is the same as classify(String,String), with the only
+	 * difference - the method called. We may want to have this procedure
+	 * isolated.
+	 * 
+	 * @param testID
+	 *            // The ID of the ontology to be the input (loaded in the
+	 *            TestData.manager)
+	 * @param testExpectedID
+	 *            // The ID of the ontology which contains logical axioms
+	 *            expected in the result
+	 */
+	private void testEnrich(String testID, String testExpectedID) {
+		log.info("Testing the enrich() method");
+
+		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));
+
+			// Maybe we want to see what is in before
+			if (log.isDebugEnabled())
+				TestUtils.debug(manager.getOntology(testOntologyID), log);
+
+			// Now we test the method
+			log.debug("Running HermiT");
+			Set<OWLAxiom> inferred = this.theinstance.enrich(manager
+					.getOntology(testOntologyID));
+
+			// Maybe we want to see the inferred axiom list
+			if (log.isDebugEnabled()) {
+				TestUtils.debug(inferred, log);
+			}
+
+			Set<OWLLogicalAxiom> expectedAxioms = manager.getOntology(
+					IRI.create(testExpectedID)).getLogicalAxioms();
+
+			Set<OWLAxiom> missing = new HashSet<OWLAxiom>();
+			for (OWLAxiom expected : expectedAxioms) {
+				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 (OWLApiReasoningServiceException 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);
+		}
+	}
+
+	/**
+	 * This method check if the result types are the ones expected
+	 * 
+	 */
+	@Test
+	public void testEnrichResultTypes() {
+		// We want all kind of Axioms in the result set
+		// Well, not all types, but at least 1 for each
+		// InferredAxiomGenerator<?>
+		AxiomType<?>[] types = { AxiomType.CLASS_ASSERTION,
+				AxiomType.SUBCLASS_OF, AxiomType.SUB_DATA_PROPERTY,
+				AxiomType.SUB_OBJECT_PROPERTY, AxiomType.DISJOINT_CLASSES,
+				AxiomType.EQUIVALENT_DATA_PROPERTIES,
+				AxiomType.EQUIVALENT_OBJECT_PROPERTIES,
+				AxiomType.INVERSE_OBJECT_PROPERTIES,
+				AxiomType.EQUIVALENT_CLASSES, AxiomType.DISJOINT_CLASSES };
+		// Call the test method
+		testEnrichResultTypes(TestData.TEST_1_NS, types);
+	}
+
+	/**
+	 * 
+	 * @param testID
+	 *            // The ontology to run
+	 * @param types
+	 *            // The type of axioms we expect in the result
+	 */
+	private void testEnrichResultTypes(String testID, AxiomType<?>[] types) {
+
+		List<AxiomType<?>> typelist = new ArrayList<AxiomType<?>>();
+		typelist.addAll(Arrays.asList(types));
+		log.info("Testing the enrich() method (result axioms types)");
+
+		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));
+
+			// Maybe we want to see what is in before
+			if (log.isDebugEnabled())
+				TestUtils.debug(manager.getOntology(testOntologyID), log);
+
+			// Now we test the method
+			log.debug("Running HermiT");
+			Set<OWLAxiom> inferred = this.theinstance.enrich(manager
+					.getOntology(testOntologyID));
+
+			// Maybe we want to see the inferred axiom list
+			if (log.isDebugEnabled()) {
+				TestUtils.debug(inferred, log);
+			}
+			for (OWLAxiom a : inferred) {
+				typelist.remove(a.getAxiomType());
+			}
+			if (!typelist.isEmpty()) {
+				for (AxiomType<?> t : typelist)
+					log.error("Missing axiom type: {}", t);
+			}
+			assertTrue(typelist.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 (OWLApiReasoningServiceException 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);
+		}
+
+	}
+
+	@Test
+	public void testEnrich() {
+		testEnrich(TestData.TEST_1_NS, TestData.TEST_1_expected_NS);
+	}
+
+	/**
+	 * Test if the ontology is consistent or not.
+	 */
+	@Test
+	public void testIsConsistent() {
+		// This first ontology is consistent
+		testIsConsistent(TestData.TEST_1_NS, true);
+		// The second is not consistent
+		testIsConsistent(TestData.TEST_2_NS, false);
+	}
+
+	/**
+	 * Check whether the ontology is consistent
+	 * 
+	 * @param testID
+	 *            // The ID of the ontology to test
+	 * @param expected
+	 *            // If it is expected to be consistent or not
+	 */
+	private void testIsConsistent(String testID, boolean expected) {
+		log.info("Testing the isConsistent method");
+		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));
+
+			// Maybe we want to see what is in before
+			if (log.isDebugEnabled())
+				TestUtils.debug(manager.getOntology(testOntologyID), log);
+
+			// Now we test the method
+			log.debug("Running HermiT");
+
+			try {
+				assertTrue(this.theinstance.isConsistent(testOntology) == expected);
+			} catch (OWLApiReasoningServiceException e) {
+				log.error("Error while testing the isConsistent method. Message was: {}",e.getLocalizedMessage());
+				assertTrue(false);
+			}
+
+			// 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);
+		}
+	}
+
+	@Test
+	public void testClassifyWithRules() {
+		testClassifyWithRules(TestData.TEST_3_NS, TestData.TEST_3_rules_NS,
+				TestData.TEST_3_expected_NS);
+	}
+
+	@Test
+	public void testEnrichWithRules() {
+		testEnrichWithRules(TestData.TEST_3_NS, TestData.TEST_3_rules_NS,
+				TestData.TEST_3_expected_NS);
+	}
+
+	private void testClassifyWithRules(String testID, String rulesID,
+			String testExpectedID) {
+		log.info("Testing the classify(OWLOntology,List<SWRL>) method");
+
+		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.classify(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 only two kind of axioms
+				if (expected instanceof OWLSubClassOfAxiom
+						|| expected instanceof OWLClassAssertionAxiom) {
+					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 (OWLApiReasoningServiceException 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);
+		}
+	}
+
+	private void testEnrichWithRules(String testID, String rulesID,
+			String testExpectedID) {
+		log.info("Testing the classify(OWLOntology,List<SWRL>) method");
+
+		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.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 (OWLApiReasoningServiceException 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);
+		}
+	}
+}

Added: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestData.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestData.java?rev=1159764&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestData.java (added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestData.java Fri Aug 19 19:58:28 2011
@@ -0,0 +1,148 @@
+package org.apache.stanbol.reasoners.hermit;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.MissingImportEvent;
+import org.semanticweb.owlapi.model.MissingImportListener;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLException;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyChangeListener;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * We share this data between all the tests. Note: take care, do not leave the
+ * content of these object changed, for example remove your example ontology
+ * from the testDataManager
+ * 
+ */
+public class TestData {
+
+	private static final Logger log = LoggerFactory.getLogger(TestData.class);
+	/**
+	 * Constants (local resources)
+	 */
+	static final String LOCAL_RESOURCE_FOAF = "foaf.rdf";
+	static URL FOAF_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_FOAF);
+	static final String LOCAL_RESOURCE_DBPEDIA = "dbpedia_3.6.owl";
+	static URL DBPEDIA_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_DBPEDIA);
+
+	static final String LOCAL_RESOURCE_TEST_1 = "test_1.owl";
+	static URL TEST_1_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_1);
+	static final String LOCAL_RESOURCE_TEST_1_EXPECTED = "test_1_expected.owl";
+	static URL TEST_1_expected_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_1_EXPECTED);
+	
+	static final String LOCAL_RESOURCE_TEST_2 = "test_2.owl";
+	static URL TEST_2_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_2);
+	static final String LOCAL_RESOURCE_TEST_2_EXPECTED = "test_2_expected.owl";
+	static URL TEST_2_expected_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_2_EXPECTED);
+
+	static final String LOCAL_RESOURCE_TEST_3 = "test_3.owl";
+	static URL TEST_3_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_3);
+	static final String LOCAL_RESOURCE_TEST_3_RULES = "test_3_rules.owl";
+	static URL TEST_3_rules_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_3_RULES);
+	static final String LOCAL_RESOURCE_TEST_3_EXPECTED = "test_3_expected.owl";
+	static URL TEST_3_expected_LOCATION = TestData.class.getResource(System
+			.getProperty("file.separator") + LOCAL_RESOURCE_TEST_3_EXPECTED);
+
+	/**
+	 * Constants
+	 */
+	// EXAMPLE
+	static final String TEST_NS = "http://www.example.org/test/";
+	static final String TEST_1_NS = TEST_NS + "1/";
+	static final String TEST_1_expected_NS = TEST_1_NS + "expected/";
+	static final String TEST_2_NS = TEST_NS +"2/";
+	static final String TEST_2_expected_NS = TEST_2_NS + "expected/";
+	static final String TEST_3_NS = TEST_NS +"3/";
+	static final String TEST_3_rules_NS = TEST_3_NS + "rules/";
+	static final String TEST_3_expected_NS = TEST_3_NS + "expected/";
+	
+	// FOAF
+	static final String FOAF_NS = "http://xmlns.com/foaf/0.1/";
+
+	/**
+	 * Manager, factory
+	 */
+	static final OWLOntologyManager manager = OWLManager
+			.createOWLOntologyManager();
+	static final OWLDataFactory factory = OWLManager
+			.getOWLDataFactory();
+
+	static {
+		try {
+			/**
+			 * Configuration of the manager
+			 */
+			manager.setSilentMissingImportsHandling(true);
+			manager
+					.addMissingImportListener(new MissingImportListener() {
+						@Override
+						public void importMissing(MissingImportEvent event) {
+							log.warn("Missing import! URI was: {}",
+									event.getImportedOntologyURI());
+						}
+					});
+			manager
+					.addOntologyChangeListener(new OWLOntologyChangeListener() {
+						@Override
+						public void ontologiesChanged(
+								List<? extends OWLOntologyChange> arg0)
+								throws OWLException {
+							for (OWLOntologyChange change : arg0) {
+								log.debug("{} TO {}", change,
+										change.getOntology());
+							}
+						}
+					});
+			/**
+			 * Loading test ontologies once for all
+			 */
+			manager.loadOntologyFromOntologyDocument(FOAF_LOCATION
+					.openStream());
+			manager.loadOntologyFromOntologyDocument(DBPEDIA_LOCATION
+					.openStream());
+			// Test 1
+			manager.loadOntologyFromOntologyDocument(TEST_1_LOCATION
+					.openStream());
+			manager.loadOntologyFromOntologyDocument(TEST_1_expected_LOCATION
+					.openStream());
+			// Test 2
+			manager.loadOntologyFromOntologyDocument(TEST_2_LOCATION
+					.openStream());
+			manager.loadOntologyFromOntologyDocument(TEST_2_expected_LOCATION
+					.openStream());
+			// Test 3
+			manager.loadOntologyFromOntologyDocument(TEST_3_LOCATION
+					.openStream());
+			manager.loadOntologyFromOntologyDocument(TEST_3_rules_LOCATION
+					.openStream());
+			manager.loadOntologyFromOntologyDocument(TEST_3_expected_LOCATION
+					.openStream());
+			
+		} catch (OWLOntologyCreationException e) {
+			log.error("A {} have been thrown while creating the ontology"
+					+ ". Message was: {}", e.getClass(),
+					e.getLocalizedMessage());
+		} catch (IOException e) {
+			log.error(
+					"A {} have been thrown while loading the ontology from the location {}",
+					e.getClass(), FOAF_LOCATION.toString());
+			log.error("Message was: {}", e.getLocalizedMessage());
+		}
+	}
+}

Added: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestUtils.java?rev=1159764&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestUtils.java (added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/java/org/apache/stanbol/reasoners/hermit/TestUtils.java Fri Aug 19 19:58:28 2011
@@ -0,0 +1,37 @@
+package org.apache.stanbol.reasoners.hermit;
+
+import java.util.Set;
+
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.slf4j.Logger;
+
+
+public class TestUtils {
+
+	public static void debug(OWLOntology ont,Logger log) {
+		// For debug only
+		if (log.isDebugEnabled()) {
+			// We show all axioms in this ontology
+			log.debug("OntologyID: {}", ont.getOntologyID());
+			log.debug("Imports:");
+			// Imports
+			for (OWLOntology o : ont.getOWLOntologyManager().getImports(ont)) {
+				log.debug(" - {}", o);
+			}
+			log.debug("Axioms:");
+			for (OWLAxiom a : ont.getAxioms())
+				log.debug(" - {}", a);
+		}
+	}
+
+	public static void debug(Set<? extends OWLAxiom> ax,Logger log) {
+		if (log.isDebugEnabled()) {
+			log.debug("Axioms: ");
+			for (OWLAxiom a : ax) {
+				log.debug(" - {}", a);
+			}
+		}
+	}
+
+}

Added: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/catalog-v001.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/catalog-v001.xml?rev=1159764&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/catalog-v001.xml (added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/test/resources/catalog-v001.xml Fri Aug 19 19:58:28 2011
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+    <group id="Folder Repository, directory=, recursive=true, Auto-Update=true, version=2" prefer="public" xml:base="">
+        <uri id="Automatically generated entry, Timestamp=1313268802660" name="http://dbpedia.org/ontology/" uri="dbpedia_3.6.owl"/>
+    </group>
+</catalog>