You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2011/07/06 15:51:59 UTC

svn commit: r1143414 [1/2] - in /incubator/stanbol/trunk/reasoners: base/src/test/java/org/apache/stanbol/reasoners/base/ web/src/main/java/org/apache/stanbol/reasoners/web/resources/

Author: alexdma
Date: Wed Jul  6 13:51:59 2011
New Revision: 1143414

URL: http://svn.apache.org/viewvc?rev=1143414&view=rev
Log:
STANBOL-253 :
- removed stdout prints and replaced them with SLF4j logging where necessary
- cleaned up import statements in corresponding classes

Modified:
    incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunReasonerTest.java
    incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunRulesTest.java
    incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java
    incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java
    incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistentRefactoring.java
    incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java
    incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasonersResource.java

Modified: incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunReasonerTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunReasonerTest.java?rev=1143414&r1=1143413&r2=1143414&view=diff
==============================================================================
--- incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunReasonerTest.java (original)
+++ incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunReasonerTest.java Wed Jul  6 13:51:59 2011
@@ -26,38 +26,38 @@ import org.semanticweb.owlapi.model.OWLO
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.semanticweb.owlapi.reasoner.OWLReasoner;
 import org.semanticweb.owlapi.util.InferredOntologyGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- *
+ * 
  * @author elvio
  */
 public class RunReasonerTest {
 
     public OWLOntologyManager owlmanager;
+
     public OWLOntology owl;
 
+    private Logger log = LoggerFactory.getLogger(getClass());
+
     public RunReasonerTest() throws OWLOntologyCreationException {
         this.owlmanager = OWLManager.createOWLOntologyManager();
-        this.owl = owlmanager.loadOntologyFromOntologyDocument(new File("./src/main/resources/TestFile/ProvaParent.owl"));
+        this.owl = owlmanager.loadOntologyFromOntologyDocument(new File(
+                "./src/main/resources/TestFile/ProvaParent.owl"));
     }
 
     @BeforeClass
-    public static void setUpClass() throws Exception {
-    }
+    public static void setUpClass() throws Exception {}
 
     @AfterClass
-    public static void tearDownClass() throws Exception {
-    }
+    public static void tearDownClass() throws Exception {}
 
     @Before
-    public void setUp() {
-    }
+    public void setUp() {}
 
     @After
-    public void tearDown() {
-    }
-
-   
+    public void tearDown() {}
 
     /**
      * Test of runClassifyInference method, of class RunReasoner.
@@ -73,16 +73,11 @@ public class RunReasonerTest {
 
         CreateReasoner reasonerforcheck = new CreateReasoner(inf);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
-
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            inf.getOntologyID());
+        assertNotNull(inf);
         int ax = inf.getAxiomCount();
-        
-        if(inf!=null){
-            assertEquals(10, ax);
-        // TODO review the generated test code and remove the default call to fail.
-        }else{
-            fail("Some errors occur with runClassifyInference of KReSCreateReasoner.");
-        }
+        assertEquals(10, ax);
 
     }
 
@@ -95,21 +90,17 @@ public class RunReasonerTest {
 
         CreateReasoner reasoner = new CreateReasoner(owl);
         RunReasoner instance = new RunReasoner(reasoner.getReasoner());
-        
+
         owl = instance.runClassifyInference(owl);
 
         CreateReasoner reasonerforcheck = new CreateReasoner(owl);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
 
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            owl.getOntologyID());
+        assertNotNull(owl);
         int ax = owl.getAxiomCount();
-
-        if(owl!=null){
-            assertEquals(true,(ax>contin));
-        // TODO review the generated test code and remove the default call to fail.
-        }else{
-            fail("Some errors occur with runClassifyInference of KReSCreateReasoner.");
-        }
+        assertTrue(ax > contin);
 
     }
 
@@ -119,54 +110,48 @@ public class RunReasonerTest {
     @Test
     public void testIsConsistence() {
         OWLReasoner expris = (new ReasonerFactory()).createReasoner(owl);
-        //expris.prepareReasoner();
+        // expris.prepareReasoner();
         CreateReasoner reasoner = new CreateReasoner(owl);
         RunReasoner instance = new RunReasoner(reasoner.getReasoner());
         boolean expResult = expris.isConsistent();
         boolean result = instance.isConsistent();
-        if(result){
-            assertEquals(expResult, result);
-        // TODO review the generated test code and remove the default call to fail.
-        }else{
-            fail("Some errors occur with isConsistence of KReSCreateReasoner.");
-        }
+
+        assertTrue(result);
+        assertEquals(expResult, result);
     }
 
     /**
      * Test of runGeneralInference method, of class RunReasoner.
      */
     @Test
-    public void testRunGeneralInference_0args(){
+    public void testRunGeneralInference_0args() {
         CreateReasoner reasoner = new CreateReasoner(owl);
         RunReasoner instance = new RunReasoner(reasoner.getReasoner());
         OWLOntology result = instance.runGeneralInference();
 
         CreateReasoner reasonerforcheck = new CreateReasoner(result);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            owl.getOntologyID());
 
         OWLReasoner expris = (new ReasonerFactory()).createReasoner(owl);
-        //expris.prepareReasoner();
-        InferredOntologyGenerator iogpellet  = new InferredOntologyGenerator(expris);
+        // expris.prepareReasoner();
+        InferredOntologyGenerator iogpellet = new InferredOntologyGenerator(expris);
 
         iogpellet.fillOntology(owlmanager, owl);
 
         Set<OWLAxiom> setx = owl.getAxioms();
         Iterator<OWLAxiom> iter = setx.iterator();
 
-            while(iter.hasNext()){
-                OWLAxiom axiom = iter.next();
-                if(axiom.toString().contains("Equivalent")){
-                 owl.getOWLOntologyManager().removeAxiom(owl,axiom);
-                }
+        while (iter.hasNext()) {
+            OWLAxiom axiom = iter.next();
+            if (axiom.toString().contains("Equivalent")) {
+                owl.getOWLOntologyManager().removeAxiom(owl, axiom);
             }
-
-        if(result!=null){
-            assertEquals(owl, result);
-        // TODO review the generated test code and remove the default call to fail.
-        }else{
-            fail("Some errors occur with RunGeneralInference of KReSCreateReasoner.");
         }
+
+        assertNotNull(result);
+        assertEquals(owl, result);
     }
 
     /**
@@ -181,20 +166,17 @@ public class RunReasonerTest {
 
         CreateReasoner reasonerforcheck = new CreateReasoner(result);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
-        
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            owl.getOntologyID());
+
         OWLReasoner expris = (new ReasonerFactory()).createReasoner(owl);
-        //expris.prepareReasoner();
-        InferredOntologyGenerator iogpellet  =new InferredOntologyGenerator(expris);
+        // expris.prepareReasoner();
+        InferredOntologyGenerator iogpellet = new InferredOntologyGenerator(expris);
         iogpellet.fillOntology(owlmanager, owl);
         OWLOntology expResult = owl;
 
-        if(result!=null){
-         assertEquals(expResult, result);
-        // TODO review the generated test code and remove the default call to fail.
-        }else{
-            fail("Some errors occur with RunGeneralInference with new ontology of KReSCreateReasoner.");
-        }
+        assertNotNull(result);
+        assertEquals(expResult, result);
     }
 
 }
\ No newline at end of file

Modified: incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunRulesTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunRulesTest.java?rev=1143414&r1=1143413&r2=1143414&view=diff
==============================================================================
--- incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunRulesTest.java (original)
+++ incubator/stanbol/trunk/reasoners/base/src/test/java/org/apache/stanbol/reasoners/base/RunRulesTest.java Wed Jul  6 13:51:59 2011
@@ -24,25 +24,35 @@ import org.semanticweb.owlapi.model.OWLA
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.hp.hpl.jena.ontology.OntModel;
 import com.hp.hpl.jena.rdf.model.ModelFactory;
 
 /**
- *
+ * 
  * @author elvio
  */
 public class RunRulesTest {
 
+    private Logger log = LoggerFactory.getLogger(getClass());
+
     public OWLOntologyManager owlmanagertarget;
+
     public OWLOntologyManager owlnamagerswrlt;
+
     public OWLOntology owltarget;
+
     public OWLOntology owlswrl;
+
     public OntModel jenaswrl;
 
     public RunRulesTest() throws OWLOntologyCreationException, IOException {
-        this.owltarget = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("./src/main/resources/TestFile/ProvaParent.owl"));
-        this.owlswrl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("./src/main/resources/TestFile/OnlyRuledProvaParent.owl"));
+        this.owltarget = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(
+            new File("./src/main/resources/TestFile/ProvaParent.owl"));
+        this.owlswrl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(
+            new File("./src/main/resources/TestFile/OnlyRuledProvaParent.owl"));
         this.owlmanagertarget = owltarget.getOWLOntologyManager();
         this.owlnamagerswrlt = owlswrl.getOWLOntologyManager();
         this.jenaswrl = ModelFactory.createOntologyModel();
@@ -50,90 +60,80 @@ public class RunRulesTest {
     }
 
     @BeforeClass
-    public static void setUpClass() throws Exception {
-    }
+    public static void setUpClass() throws Exception {}
 
     @AfterClass
-    public static void tearDownClass() throws Exception {
-    }
+    public static void tearDownClass() throws Exception {}
 
     @Before
-    public void setUp() {
-    }
+    public void setUp() {}
 
     @After
-    public void tearDown() {
-    }
+    public void tearDown() {}
 
     /**
      * Test of runRulesReasoner method, of class RunRules.
      */
     @Test
-    public void testRunRulesReasoner_OWLOntology_1() throws OWLOntologyCreationException{
+    public void testRunRulesReasoner_OWLOntology_1() throws OWLOntologyCreationException {
+
+        OWLOntology newmodel = OWLManager.createOWLOntologyManager()
+                .createOntology(owltarget.getOntologyID());
+        RunRules instance = new RunRules(owlswrl, owltarget);
 
-        OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(owltarget.getOntologyID());
-        RunRules instance = new RunRules(owlswrl,owltarget);
-       
         newmodel = instance.runRulesReasoner(newmodel);
-        
+
         CreateReasoner reasonerforcheck = new CreateReasoner(newmodel);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
-        
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            newmodel.getOntologyID());
+
         Iterator<OWLAxiom> axiom = newmodel.getAxioms().iterator();
         Iterator<OWLAxiom> axt = owltarget.getAxioms().iterator();
 
-        String inferedaxiom ="ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
+        String inferedaxiom = "ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
         String ax;
-        
-        if(newmodel!=null){
-        while(axt.hasNext()){
+
+        assertNotNull(newmodel);
+
+        while (axt.hasNext()) {
             ax = axt.next().toString();
-            if(ax.equals(inferedaxiom))
-                fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
-        // TODO review the generated test code and remove the default call to fail.
-        }}else{
-            fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
+            if (ax.equals(inferedaxiom)) fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
         }
 
-        if(newmodel!=null){
-        while(axiom.hasNext()){
+        while (axiom.hasNext()) {
             ax = axiom.next().toString();
-            if(ax.equals(inferedaxiom))
-                assertEquals(inferedaxiom, ax.toString());
-        // TODO review the generated test code and remove the default call to fail.
-        }}else{
-            fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
+            if (ax.equals(inferedaxiom)) assertEquals(inferedaxiom, ax.toString());
         }
+
     }
 
     /**
      * Test of runRulesReasoner method, of class RunRules.
      */
     @Test
-    public void testRunRulesReasoner_0args_1(){
+    public void testRunRulesReasoner_0args_1() {
 
-        RunRules instance = new RunRules(owlswrl,owltarget);
+        RunRules instance = new RunRules(owlswrl, owltarget);
         OWLOntology newmodel = instance.runRulesReasoner();
 
         CreateReasoner reasonerforcheck = new CreateReasoner(newmodel);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            newmodel.getOntologyID());
 
         Iterator<OWLAxiom> axiom = newmodel.getAxioms().iterator();
 
-        String inferedaxiom ="ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
+        String inferedaxiom = "ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
         String ax;
 
-        if(newmodel!=null){
-        while(axiom.hasNext()){
+        assertNotNull(newmodel);
+
+        while (axiom.hasNext()) {
             ax = axiom.next().toString();
-            if(ax.equals(inferedaxiom))
-                assertEquals(inferedaxiom, ax.toString());
-        // TODO review the generated test code and remove the default call to fail.
-        }}else{
-            fail("Some errors occur with runRulesReasoner in KReSRunRules.");
+            if (ax.equals(inferedaxiom)) assertEquals(inferedaxiom, ax.toString());
         }
+
     }
 
     /**
@@ -142,69 +142,63 @@ public class RunRulesTest {
     @Test
     public void testRunRulesReasoner_OWLOntology_2() throws OWLOntologyCreationException {
 
-        OWLOntology newmodel = OWLManager.createOWLOntologyManager().createOntology(owltarget.getOntologyID());
-        RunRules instance = new RunRules(jenaswrl.getBaseModel(),owltarget);
+        OWLOntology newmodel = OWLManager.createOWLOntologyManager()
+                .createOntology(owltarget.getOntologyID());
+        RunRules instance = new RunRules(jenaswrl.getBaseModel(), owltarget);
 
         newmodel = instance.runRulesReasoner(newmodel);
 
         CreateReasoner reasonerforcheck = new CreateReasoner(newmodel);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            newmodel.getOntologyID());
 
         Iterator<OWLAxiom> axiom = newmodel.getAxioms().iterator();
         Iterator<OWLAxiom> axt = owltarget.getAxioms().iterator();
 
-        String inferedaxiom ="ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
+        String inferedaxiom = "ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
         String ax;
 
-        if(newmodel!=null){
-        while(axt.hasNext()){
+        assertNotNull(newmodel);
+
+        while (axt.hasNext()) {
             ax = axt.next().toString();
-            if(ax.equals(inferedaxiom))
-                fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
-        // TODO review the generated test code and remove the default call to fail.
-        }}else{
-            fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
-        }
-        
-        if(newmodel!=null){
-        while(axiom.hasNext()){
+            if (ax.equals(inferedaxiom)) fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
+        }
+
+        while (axiom.hasNext()) {
             ax = axiom.next().toString();
-            if(ax.equals(inferedaxiom))
-                assertEquals(inferedaxiom, ax.toString());
-        // TODO review the generated test code and remove the default call to fail.
-        }}else{
-            fail("Some errors occur with runRulesReasoner with new ontology in KReSRunRules.");
+            if (ax.equals(inferedaxiom)) assertEquals(inferedaxiom, ax.toString());
         }
+
     }
 
     /**
      * Test of runRulesReasoner method, of class RunRules.
      */
     @Test
-    public void testRunRulesReasoner_0args_2(){
+    public void testRunRulesReasoner_0args_2() {
 
-        RunRules instance = new RunRules(jenaswrl,owltarget);
+        RunRules instance = new RunRules(jenaswrl, owltarget);
         OWLOntology newmodel = instance.runRulesReasoner();
 
         CreateReasoner reasonerforcheck = new CreateReasoner(newmodel);
         RunReasoner run = new RunReasoner(reasonerforcheck.getReasoner());
-        System.out.println(":::::::::::::::: consistency check "+run.isConsistent());
+        log.debug("Ontology {} is " + (run.isConsistent() ? "consistent" : "NOT consistent") + ".",
+            newmodel.getOntologyID());
 
         Iterator<OWLAxiom> axiom = newmodel.getAxioms().iterator();
 
-        String inferedaxiom ="ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
+        String inferedaxiom = "ObjectPropertyAssertion(<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#hasUncle> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#Tom> <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#John>)";
         String ax;
 
-        if(newmodel!=null){
-        while(axiom.hasNext()){
+        assertNotNull(newmodel);
+
+        while (axiom.hasNext()) {
             ax = axiom.next().toString();
-            if(ax.equals(inferedaxiom))
-                assertEquals(inferedaxiom, ax.toString());
-        // TODO review the generated test code and remove the default call to fail.
-        }}else{
-            fail("Some errors occur with runRulesReasoner in KReSRunRules.");
+            if (ax.equals(inferedaxiom)) assertEquals(inferedaxiom, ax.toString());
         }
+
     }
 
 }
\ No newline at end of file

Modified: incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java?rev=1143414&r1=1143413&r2=1143414&view=diff
==============================================================================
--- incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java (original)
+++ incubator/stanbol/trunk/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java Wed Jul  6 13:51:59 2011
@@ -5,16 +5,12 @@
 
 package org.apache.stanbol.reasoners.web.resources;
 
-import static javax.ws.rs.core.MediaType.TEXT_HTML;
+import static javax.ws.rs.core.MediaType.*;
+import static javax.ws.rs.core.Response.Status.*;
 
-import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -31,9 +27,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
 
 import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.format.KRFormat;
@@ -55,468 +49,384 @@ import org.apache.stanbol.rules.manager.
 import org.apache.stanbol.rules.manager.changes.RuleStoreImpl;
 import org.apache.stanbol.rules.manager.parse.RuleParserImpl;
 import org.semanticweb.owlapi.apibinding.OWLManager;
-import org.semanticweb.owlapi.io.FileDocumentTarget;
-import org.semanticweb.owlapi.io.StreamDocumentTarget;
 import org.semanticweb.owlapi.io.StringDocumentTarget;
 import org.semanticweb.owlapi.model.AddImport;
-import org.semanticweb.owlapi.model.AxiomType;
 import org.semanticweb.owlapi.model.IRI;
-import org.semanticweb.owlapi.model.OWLAnnotation;
-import org.semanticweb.owlapi.model.OWLAnnotationProperty;
 import org.semanticweb.owlapi.model.OWLAxiom;
 import org.semanticweb.owlapi.model.OWLClass;
 import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
 import org.semanticweb.owlapi.model.OWLDataFactory;
 import org.semanticweb.owlapi.model.OWLDataProperty;
-import org.semanticweb.owlapi.model.OWLDatatype;
 import org.semanticweb.owlapi.model.OWLIndividual;
 import org.semanticweb.owlapi.model.OWLLiteral;
 import org.semanticweb.owlapi.model.OWLObjectProperty;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyChange;
-import org.semanticweb.owlapi.model.OWLOntologyCreationException;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
 import org.semanticweb.owlapi.model.SWRLRule;
 import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Resource;
 import com.sun.jersey.api.view.Viewable;
 import com.sun.jersey.multipart.FormDataParam;
 
 /**
- *
+ * 
  * @author elvio
  */
 @Path("/reasoners/classify")
-public class Classify extends BaseStanbolResource{
+public class Classify extends BaseStanbolResource {
 
-     private RuleStore kresRuleStore;
-     private OWLOntology inputowl;
-     private OWLOntology scopeowl;
+    private RuleStore kresRuleStore;
 
-	protected ONManager onm;
-	protected ClerezzaOntologyStorage storage;
-	protected ServletContext servletContext;
+    private OWLOntology inputowl;
 
-	private Logger log = LoggerFactory.getLogger(getClass());
+    protected ONManager onm;
+
+    protected ClerezzaOntologyStorage storage;
+
+    protected ServletContext servletContext;
+
+    private Logger log = LoggerFactory.getLogger(getClass());
 
     /**
      * To get the RuleStoreImpl where are stored the rules and the recipes
-     *
-	 * @param servletContext
-	 *            {To get the context where the REST service is running.}
+     * 
+     * @param servletContext
+     *            {To get the context where the REST service is running.}
      */
-    public Classify(@Context ServletContext servletContext){
+    public Classify(@Context ServletContext servletContext) {
         this.servletContext = servletContext;
 
         // Retrieve the rule store
         this.kresRuleStore = (RuleStore) ContextHelper.getServiceFromContext(RuleStore.class, servletContext);
-        
-		// Retrieve the ontology network manager
+
+        // Retrieve the ontology network manager
         this.onm = (ONManager) ContextHelper.getServiceFromContext(ONManager.class, servletContext);
-        this.storage = (ClerezzaOntologyStorage) ContextHelper.getServiceFromContext(ClerezzaOntologyStorage.class, servletContext);
-       
-       if (kresRuleStore == null) {
-			log
-					.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
-			this.kresRuleStore = new RuleStoreImpl(onm,
-					new Hashtable<String, Object>(), "");
-			log
-					.debug("PATH TO OWL FILE LOADED: "
-							+ kresRuleStore.getFilePath());
+        this.storage = (ClerezzaOntologyStorage) ContextHelper.getServiceFromContext(
+            ClerezzaOntologyStorage.class, servletContext);
+
+        if (kresRuleStore == null) {
+            log.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+            this.kresRuleStore = new RuleStoreImpl(onm, new Hashtable<String,Object>(), "");
+            log.debug("PATH TO OWL FILE LOADED: " + kresRuleStore.getFilePath());
         }
     }
 
-     /**
-	 * 
-	 * @param owl
-	 *            {OWLOntology object contains a single recipe}
+    /**
+     * 
+     * @param owl
+     *            {OWLOntology object contains a single recipe}
      * @return {An Set<SWRLRule> that contains the SWRL rule.}
      */
-	private Set<SWRLRule> fromRecipeToModel(OWLOntology owl)
-			throws NoSuchRecipeException {
+    private Set<SWRLRule> fromRecipeToModel(OWLOntology owl) throws NoSuchRecipeException {
+
+        // FIXME: why the heck is this method re-instantiating a rule store?!?
+        RuleStore store = new RuleStoreImpl(onm, new Hashtable<String,Object>(), owl);
+
+        OWLDataFactory factory = owl.getOWLOntologyManager().getOWLDataFactory();
+
+        IRI recipeclass = IRI.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe");
+        OWLClass claz = factory.getOWLClass(recipeclass);
+
+        Set<OWLAxiom> axioms = owl.getReferencingAxioms(claz);
 
-		// FIXME: why the heck is this method re-instantiating a rule store?!?
-		RuleStore store = new RuleStoreImpl(onm,
-				new Hashtable<String, Object>(), owl);
-
-		OWLDataFactory factory = owl.getOWLOntologyManager()
-				.getOWLDataFactory();
-		
-		IRI recipeclass = IRI.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe");
-		OWLClass claz = factory.getOWLClass(recipeclass);
-		
-		Set<OWLAxiom> axioms = owl.getReferencingAxioms(claz);
-		
         IRI recipeiri = null;
-        for(OWLAxiom axiom : axioms){
-        	if(axiom instanceof OWLClassAssertionAxiom){
-        		OWLClassAssertionAxiom caa = (OWLClassAssertionAxiom) axiom;
-        		recipeiri = IRI.create(caa.getIndividual().toStringID());
-        	}
+        for (OWLAxiom axiom : axioms) {
+            if (axiom instanceof OWLClassAssertionAxiom) {
+                OWLClassAssertionAxiom caa = (OWLClassAssertionAxiom) axiom;
+                recipeiri = IRI.create(caa.getIndividual().toStringID());
+            }
         }
 
-        if(recipeiri == null) {
-        	throw new NoSuchRecipeException(null);
+        if (recipeiri == null) {
+            throw new NoSuchRecipeException(null);
         }
-        
-		OWLIndividual recipeIndividual = factory
-				.getOWLNamedIndividual(recipeiri);
-
-		OWLObjectProperty objectProperty = factory
-				.getOWLObjectProperty(IRI
-						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
-		Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(
-				objectProperty, store.getOntology());
+
+        OWLIndividual recipeIndividual = factory.getOWLNamedIndividual(recipeiri);
+
+        OWLObjectProperty objectProperty = factory.getOWLObjectProperty(IRI
+                .create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
+        Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(objectProperty,
+            store.getOntology());
         String kReSRules = "";
-        for(OWLIndividual rule : rules){
-			OWLDataProperty hasBodyAndHead = factory
-					.getOWLDataProperty(IRI
-							.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
-			Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(
-					hasBodyAndHead, store.getOntology());
-
-			for(OWLLiteral kReSRuleLiteral : kReSRuleLiterals){
-				kReSRules += kReSRuleLiteral.getLiteral()
-						+ System.getProperty("line.separator");
-			}
-		}
+        for (OWLIndividual rule : rules) {
+            OWLDataProperty hasBodyAndHead = factory.getOWLDataProperty(IRI
+                    .create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
+            Set<OWLLiteral> kReSRuleLiterals = rule
+                    .getDataPropertyValues(hasBodyAndHead, store.getOntology());
+
+            for (OWLLiteral kReSRuleLiteral : kReSRuleLiterals) {
+                kReSRules += kReSRuleLiteral.getLiteral() + System.getProperty("line.separator");
+            }
+        }
 
         KB kReSKB = RuleParserImpl.parse(kReSRules);
         RuleList listrules = kReSKB.getkReSRuleList();
         Iterator<Rule> iterule = listrules.iterator();
         Set<SWRLRule> swrlrules = new HashSet<SWRLRule>();
-        while(iterule.hasNext()){
+        while (iterule.hasNext()) {
             Rule singlerule = iterule.next();
-            //System.out.println("Single rule: "+singlerule.toSPARQL());
-            //System.out.println("To KReS Syntax: "+singlerule.toKReSSyntax());
-            //System.out.println("Single OWLAPI SWRL: "+singlerule.toSWRL(factory));
-            //Resource resource = singlerule.toSWRL(jenamodel); <-- FIXME This method does not work properly
+            // Resource resource = singlerule.toSWRL(jenamodel); <-- FIXME This method does not work properly
             swrlrules.add(singlerule.toSWRL(factory));
         }
         return swrlrules;
 
     }
+
     @POST
-    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-	@Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE,
-			KRFormat.OWL_XML })
-	public Response classify(
-			@FormParam(value = "session") String session,
-			@FormParam(value = "scope") String scope,
-			@FormParam(value = "recipe") String recipe
-	){
-		return ontologyClassify(session,scope,recipe,null,null,null);
-	}
-   /**
-	 * To run a classifying reasoner on a RDF input File or IRI on the base of a
-	 * Scope (or an ontology) and a recipe. Can be used either HermiT or an
-	 * owl-link server reasoner end-point
-	 * 
-	 * @param session
-	 *            {A string contains the session IRI used to classify the
-	 *            input.}
-	 * @param scope
-	 *            {A string contains either a specific scope's ontology or the
-	 *            scope IRI used to classify the input.}
-	 * @param recipe
-	 *            {A string contains the recipe IRI from the service
-	 *            http://localhost:port/kres/recipe/recipeName.}
+    @Consumes(APPLICATION_FORM_URLENCODED)
+    @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML})
+    public Response classify(@FormParam(value = "session") String session,
+                             @FormParam(value = "scope") String scope,
+                             @FormParam(value = "recipe") String recipe) {
+        return ontologyClassify(session, scope, recipe, null, null, null);
+    }
+
+    /**
+     * To run a classifying reasoner on a RDF input File or IRI on the base of a Scope (or an ontology) and a
+     * recipe. Can be used either HermiT or an owl-link server reasoner end-point
+     * 
+     * @param session
+     *            {A string contains the session IRI used to classify the input.}
+     * @param scope
+     *            {A string contains either a specific scope's ontology or the scope IRI used to classify the
+     *            input.}
+     * @param recipe
+     *            {A string contains the recipe IRI from the service
+     *            http://localhost:port/kres/recipe/recipeName.}
      * @Param file {A file in a RDF (eihter RDF/XML or owl) to be classified.}
-	 * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or
-	 *        OWL) to be classified.}
-	 * @Param owllink_endpoint {A string contains the ressoner server end-point
-	 *        URL.}
+     * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or OWL) to be classified.}
+     * @Param owllink_endpoint {A string contains the ressoner server end-point URL.}
      * @return Return: <br/>
-     *          200 The ontology is retrieved, containing only class axioms <br/>
-     *          400 To run the session is needed the scope <br/>
-     *          404 No data is retrieved <br/>
-     *          409 Too much RDF inputs <br/>
-     *          500 Some error occurred
+     *         200 The ontology is retrieved, containing only class axioms <br/>
+     *         400 To run the session is needed the scope <br/>
+     *         404 No data is retrieved <br/>
+     *         409 Too much RDF inputs <br/>
+     *         500 Some error occurred
      */
     @POST
-    @Consumes(MediaType.MULTIPART_FORM_DATA)
-	@Produces(value = { KRFormat.RDF_XML, KRFormat.TURTLE,
-			KRFormat.OWL_XML })
-	public Response ontologyClassify(
-			@FormDataParam(value = "session") String session,
-			@FormDataParam(value = "scope") String scope,
-			@FormDataParam(value = "recipe") String recipe,
-			@FormDataParam(value = "input-graph") String input_graph,
-			@FormDataParam(value = "file") File file,
-			@FormDataParam(value = "owllink-endpoint") String owllink_endpoint) {
-
-      try{
-      
-      if((session!=null)&&(scope==null)){
-           log.error("ERROR: Cannot load session without scope.");
-           return Response.status(Status.BAD_REQUEST).build();
-        }
+    @Consumes(MULTIPART_FORM_DATA)
+    @Produces(value = {KRFormat.RDF_XML, KRFormat.TURTLE, KRFormat.OWL_XML})
+    public Response ontologyClassify(@FormDataParam(value = "session") String session,
+                                     @FormDataParam(value = "scope") String scope,
+                                     @FormDataParam(value = "recipe") String recipe,
+                                     @FormDataParam(value = "input-graph") String input_graph,
+                                     @FormDataParam(value = "file") File file,
+                                     @FormDataParam(value = "owllink-endpoint") String owllink_endpoint) {
+
+        try {
+
+            if ((session != null) && (scope == null)) {
+                log.error("Unspecified scope parameter for session {} , cannot classify.", session);
+                return Response.status(BAD_REQUEST).build();
+            }
 
-       //Check for input conflict. Only one input at once is allowed
-       if((file!=null)&&(input_graph!=null)){
-           System.err.println("ERROR: Cannot handle both parameters: file and input graph");
-           return Response.status(Status.CONFLICT).build();
-       }
-
-      //Load input file or graph
-      if(file!=null)
-				this.inputowl = OWLManager.createOWLOntologyManager()
-						.loadOntologyFromOntologyDocument(file);
-      if(input_graph!=null)
-				this.inputowl = OWLManager.createOWLOntologyManager()
-						.loadOntologyFromOntologyDocument(
-								IRI.create(input_graph));
-      if(inputowl==null&&(session==null||scope==null))
-        return Response.status(Status.NOT_FOUND).build();
-      if(inputowl==null){
-          if(scope!=null)
-					this.inputowl = OWLManager.createOWLOntologyManager()
-							.createOntology();
-          else{
-					this.inputowl = OWLManager.createOWLOntologyManager()
-							.createOntology();
-          }
-      }
-
-       //Create list to add ontologies as imported
-       OWLOntologyManager mgr = inputowl.getOWLOntologyManager();
-			OWLDataFactory factory = inputowl.getOWLOntologyManager()
-					.getOWLDataFactory();
-       List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
-       
-       boolean ok = false;
-
-      //Load ontologies from scope, RDF input and recipe
-      //Try to resolve scope IRI
-      if((scope!=null)&&(session==null))
-      try{
-          IRI iri = IRI.create(scope);
-					ScopeRegistry reg = onm.getScopeRegistry();
-          OntologyScope ontoscope = reg.getScope(iri);
-					Iterator<OWLOntology> importscope = ontoscope
-							.getCustomSpace().getOntologies().iterator();
-					Iterator<OntologySpace> importsession = ontoscope
-							.getSessionSpaces().iterator();
-
-					// Add ontology as import form scope, if it is anonymus we
-					// try to add single axioms.
-          while(importscope.hasNext()){
-            OWLOntology auxonto = importscope.next();
-            if(!auxonto.getOntologyID().isAnonymous()){
-							additions.add(new AddImport(inputowl, factory
-									.getOWLImportsDeclaration(auxonto
-											.getOWLOntologyManager()
-											.getOntologyDocumentIRI(auxonto))));
-            }else{
-                mgr.addAxioms(inputowl,auxonto.getAxioms());
+            // Check for input conflict. Only one input at once is allowed
+            if ((file != null) && (input_graph != null)) {
+                log.error("Parameters file and input-graph are mutually exclusive and cannot be specified together.");
+                return Response.status(CONFLICT).build();
+            }
+
+            // Load input file or graph
+            if (file != null) this.inputowl = OWLManager.createOWLOntologyManager()
+                    .loadOntologyFromOntologyDocument(file);
+            if (input_graph != null) this.inputowl = OWLManager.createOWLOntologyManager()
+                    .loadOntologyFromOntologyDocument(IRI.create(input_graph));
+            if (inputowl == null && (session == null || scope == null)) return Response.status(NOT_FOUND)
+                    .build();
+            if (inputowl == null) {
+                if (scope != null) this.inputowl = OWLManager.createOWLOntologyManager().createOntology();
+                else {
+                    this.inputowl = OWLManager.createOWLOntologyManager().createOntology();
+                }
             }
-         }
 
-         //Add ontology form sessions
-         while(importsession.hasNext()){
-						Iterator<OWLOntology> sessionontos = importsession
-								.next().getOntologies().iterator();
-             while(sessionontos.hasNext()){
-                OWLOntology auxonto = sessionontos.next();
-                if(!auxonto.getOntologyID().isAnonymous()){
-								additions
-										.add(new AddImport(
-												inputowl,
-												factory
-														.getOWLImportsDeclaration(auxonto
-																.getOWLOntologyManager()
-																.getOntologyDocumentIRI(
-																		auxonto))));
-                }else{
-                    mgr.addAxioms(inputowl,auxonto.getAxioms());
+            // Create list to add ontologies as imported
+            OWLOntologyManager mgr = inputowl.getOWLOntologyManager();
+            OWLDataFactory factory = inputowl.getOWLOntologyManager().getOWLDataFactory();
+            List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+
+            // Load ontologies from scope, RDF input and recipe
+            // Try to resolve scope IRI
+            if ((scope != null) && (session == null)) try {
+                IRI iri = IRI.create(scope);
+                ScopeRegistry reg = onm.getScopeRegistry();
+                OntologyScope ontoscope = reg.getScope(iri);
+                Iterator<OWLOntology> importscope = ontoscope.getCustomSpace().getOntologies().iterator();
+                Iterator<OntologySpace> importsession = ontoscope.getSessionSpaces().iterator();
+
+                // Add ontology as import form scope, if it is anonymus we
+                // try to add single axioms.
+                while (importscope.hasNext()) {
+                    OWLOntology auxonto = importscope.next();
+                    if (!auxonto.getOntologyID().isAnonymous()) {
+                        additions.add(new AddImport(inputowl, factory.getOWLImportsDeclaration(auxonto
+                                .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+                    } else {
+                        mgr.addAxioms(inputowl, auxonto.getAxioms());
+                    }
                 }
-         }
 
-         }
-          
-      }catch(Exception e){
-          System.err.println("ERROR: Problem with scope: "+scope);
-          e.printStackTrace();
-          Response.status(Status.NOT_FOUND).build();
-      }
-
-      //Get Ontologies from session
-      if((session!=null)&&(scope!=null))
-      try{
-          IRI iri = IRI.create(scope);
-					ScopeRegistry reg = onm.getScopeRegistry();
-          OntologyScope ontoscope = reg.getScope(iri);
-					SessionOntologySpace sos = ontoscope.getSessionSpace(IRI
-							.create(session));
-					/*
-					for(OWLOntology a:ontoscope.getCoreSpace().getOntologies()){	
-						System.out.println("CORE ONTOLOGY: "+a);
-					}
-					*/
-					for(OWLOntology a:ontoscope.getCustomSpace().getOntologies()){
-						//System.out.println("CUSTOM ONTOLOGY: "+a);
-						mgr.addAxioms(inputowl, a.getAxioms());
-					}
-					Set<OWLOntology> ontos = sos.getOntologyManager()
-							.getOntologies();
-					for(OWLOntology a:ontos){
-							//System.out.println("SESSION ONTOLOGY: "+a);
-							mgr.addAxioms(inputowl, a.getAxioms());
-					}
-		            inputowl = mgr.getOntology(inputowl.getOntologyID());
-
-      }catch(Exception e){
-					System.err.println("ERROR: Problem with session: "
-							+ session);
-          e.printStackTrace();
-          Response.status(Status.NOT_FOUND).build();
-      }
-
-			// After gathered the all ontology as imported now we apply the
-			// changes
-      if(additions.size()>0)
-        mgr.applyChanges(additions);
-
-      inputowl = mgr.getOntology(inputowl.getOntologyID());
-      
-      //Run HermiT if the reasonerURL is null;
-      if(owllink_endpoint==null){
-    	  /**
-    	   * If we run hermit, we must remove all datatype assertions
-    	   * from the ontology. Non default datatypes, such http://dbpedia.org/datatype/hour
-    	   * would break the process
-    	   */
-    	  Set<OWLAxiom> removeThese = new HashSet<OWLAxiom>();
-    	  for(OWLAxiom axiom: inputowl.getAxioms()){
-    		  if(!axiom.getDatatypesInSignature().isEmpty()){
-    			  removeThese.add(axiom);
-    		  }
-    	  }
-    	  inputowl.getOWLOntologyManager().removeAxioms(inputowl, removeThese);
-    	  inputowl = inputowl.getOWLOntologyManager().getOntology(inputowl.getOntologyID());
-       try{
-       if(recipe!=null) {
-    	   OWLOntologyManager mngr = OWLManager
-			.createOWLOntologyManager();
-						OWLOntology recipeowl = mngr
-								.loadOntologyFromOntologyDocument(
-										IRI.create(recipe));
-						//OWLOntology rulesOntology = mngr.createOntology();
-						Set<SWRLRule> swrlRules = fromRecipeToModel(recipeowl);
-						inputowl.getOWLOntologyManager().addAxioms(inputowl, swrlRules);
-						inputowl = inputowl.getOWLOntologyManager().getOntology(inputowl.getOntologyID());
-       }
-       
-       StringDocumentTarget tgt = new StringDocumentTarget();;
-       
-       inputowl.getOWLOntologyManager().saveOntology(inputowl,tgt);
-       inputowl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new ByteArrayInputStream(tgt.toString().getBytes()));
-//for (OWLAnnotationProperty ax : inputowl.getAnnotationPropertiesInSignature())      
-//    System.out.println(ax);
-
-            //Create the reasoner for the classification
-					CreateReasoner newreasoner = new CreateReasoner(
-							inputowl);
-					// Prepare and start the reasoner to classify ontology's
-					// resources
-					RunReasoner reasoner = new RunReasoner(newreasoner
-							.getReasoner());
-
-					// Create a new OWLOntology model where to put the inferred
-					// axioms
-					OWLOntology output = OWLManager.createOWLOntologyManager()
-							.createOntology(inputowl.getOntologyID());
-            //Initial input axioms count
-            int startax = output.getAxiomCount();
-            //Run the classification
-            output = reasoner.runClassifyInference(output);
-            
-//            output.getOWLOntologyManager().saveOntology(output,new FileDocumentTarget(new File("./dioschifoso.owl")));
-            
-            //End output axioms count
-            int endax = output.getAxiomCount();
-
-            if((endax-startax)>0){
-                //Some inference is retrieved
-                return Response.ok(output).build();
-            }else{
-                //No data is retrieved
-                return Response.status(Status.NOT_FOUND).build();
+                // Add ontology form sessions
+                while (importsession.hasNext()) {
+                    Iterator<OWLOntology> sessionontos = importsession.next().getOntologies().iterator();
+                    while (sessionontos.hasNext()) {
+                        OWLOntology auxonto = sessionontos.next();
+                        if (!auxonto.getOntologyID().isAnonymous()) {
+                            additions.add(new AddImport(inputowl, factory.getOWLImportsDeclaration(auxonto
+                                    .getOWLOntologyManager().getOntologyDocumentIRI(auxonto))));
+                        } else {
+                            mgr.addAxioms(inputowl, auxonto.getAxioms());
+                        }
+                    }
+
+                }
+
+            } catch (Exception e) {
+                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
             }
 
-       }catch (InconsistentOntologyException exc){
-           System.err.println("CHECK ONTOLOGY CONSISTENCE");
-           return Response.status(Status.NOT_FOUND).build();
-        }
+            // Get Ontologies from session
+            if ((session != null) && (scope != null)) try {
+                IRI iri = IRI.create(scope);
+                ScopeRegistry reg = onm.getScopeRegistry();
+                OntologyScope ontoscope = reg.getScope(iri);
+                SessionOntologySpace sos = ontoscope.getSessionSpace(IRI.create(session));
+                for (OWLOntology a : ontoscope.getCustomSpace().getOntologies())
+                    mgr.addAxioms(inputowl, a.getAxioms());
+                for (OWLOntology a : sos.getOntologyManager().getOntologies())
+                    mgr.addAxioms(inputowl, a.getAxioms());
+
+                inputowl = mgr.getOntology(inputowl.getOntologyID());
 
-				// If there is an owl-link server end-point specified in the
-				// form
-      }else{
-
-      try{
-       if(recipe!=null) {
-
-    	   OWLOntologyManager mngr = OWLManager
-			.createOWLOntologyManager();
-						OWLOntology recipeowl = mngr
-								.loadOntologyFromOntologyDocument(
-										IRI.create(recipe));
-						OWLOntology rulesOntology = mngr.createOntology();
-						Set<SWRLRule> swrlRules = fromRecipeToModel(recipeowl);
-						mngr.addAxioms(rulesOntology, swrlRules);
-						rulesOntology = mngr.getOntology(rulesOntology.getOntologyID());
-						// Create a reasoner to run rules contained in the
-						// recipe by using the server and-point
-						RunRules rulereasoner = new RunRules(rulesOntology,
-								inputowl, new URL(owllink_endpoint));
-						// Run the rule reasoner to the input RDF with the added
-						// top-ontology
-         inputowl = rulereasoner.runRulesReasoner();
-       }
-					// Create the reasoner for the consistency check by using
-					// the server and-point
-					CreateReasoner newreasoner = new CreateReasoner(
-							inputowl, new URL(owllink_endpoint));
-					// Prepare and start the reasoner to classify ontology's
-					// resources
-					RunReasoner reasoner = new RunReasoner(newreasoner
-							.getReasoner());
-
-					// Create a new OWLOntology model where to put the inferred
-					// axioms
-					OWLOntology output = OWLManager.createOWLOntologyManager()
-							.createOntology(inputowl.getOntologyID());
-         //Initial input axioms count
-         int startax = output.getAxiomCount();
-         //Run the classification
-         output = reasoner.runClassifyInference(output);
-         //End output axioms count
-         int endax = output.getAxiomCount();
-
-            if((endax-startax)>0){
-                //Some inference is retrieved
-                return Response.ok(output).build();
-            }else{
-                //No data is retrieved
-                return Response.status(Status.NOT_FOUND).build();
+            } catch (Exception e) {
+                throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
             }
 
-      }catch (InconsistentOntologyException exc){
-           System.err.println("CHECK ONTOLOGY CONSISTENCE");
-            return Response.status(Status.NOT_FOUND).build();
-      }
-      }
-      }catch(Exception e){
-          throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
-      }
+            // After gathered the all ontology as imported now we apply the
+            // changes
+            if (additions.size() > 0) mgr.applyChanges(additions);
+
+            inputowl = mgr.getOntology(inputowl.getOntologyID());
+
+            // Run HermiT if the reasonerURL is null;
+            if (owllink_endpoint == null) {
+                /**
+                 * If we run hermit, we must remove all datatype assertions from the ontology. Non default
+                 * datatypes, such http://dbpedia.org/datatype/hour would break the process
+                 */
+                Set<OWLAxiom> removeThese = new HashSet<OWLAxiom>();
+                for (OWLAxiom axiom : inputowl.getAxioms()) {
+                    if (!axiom.getDatatypesInSignature().isEmpty()) {
+                        removeThese.add(axiom);
+                    }
+                }
+                inputowl.getOWLOntologyManager().removeAxioms(inputowl, removeThese);
+                inputowl = inputowl.getOWLOntologyManager().getOntology(inputowl.getOntologyID());
+                try {
+                    if (recipe != null) {
+                        OWLOntologyManager mngr = OWLManager.createOWLOntologyManager();
+                        OWLOntology recipeowl = mngr.loadOntologyFromOntologyDocument(IRI.create(recipe));
+                        // OWLOntology rulesOntology = mngr.createOntology();
+                        Set<SWRLRule> swrlRules = fromRecipeToModel(recipeowl);
+                        inputowl.getOWLOntologyManager().addAxioms(inputowl, swrlRules);
+                        inputowl = inputowl.getOWLOntologyManager().getOntology(inputowl.getOntologyID());
+                    }
+
+                    // FIXME : quick dirty fix (hack?)
+                    StringDocumentTarget tgt = new StringDocumentTarget();
+
+                    inputowl.getOWLOntologyManager().saveOntology(inputowl, tgt);
+                    inputowl = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(
+                        new ByteArrayInputStream(tgt.toString().getBytes()));
+
+                    // Create the reasoner for the classification
+                    CreateReasoner newreasoner = new CreateReasoner(inputowl);
+                    // Prepare and start the reasoner to classify ontology resources.
+                    RunReasoner reasoner = new RunReasoner(newreasoner.getReasoner());
+
+                    // Create a new OWLOntology model where to put the inferred axioms
+                    OWLOntology output = OWLManager.createOWLOntologyManager().createOntology(
+                        inputowl.getOntologyID());
+                    // Initial input axioms count
+                    int startax = output.getAxiomCount();
+                    // Run the classification
+                    output = reasoner.runClassifyInference(output);
+                    // End output axioms count
+                    int endax = output.getAxiomCount();
+
+                    if ((endax - startax) > 0) {
+                        // Some inference is retrieved
+                        return Response.ok(output).build();
+                    } else {
+                        // No data is retrieved
+                        return Response.status(NOT_FOUND).build();
+                    }
+
+                } catch (InconsistentOntologyException exc) {
+                    log.error("Cannot classify inconsistent ontology " + inputowl.getOntologyID(), exc);
+                    return Response.status(PRECONDITION_FAILED).build();
+                }
+
+                // If there is an owl-link server end-point specified in the form
+            } else {
+
+                try {
+                    if (recipe != null) {
+
+                        OWLOntologyManager mngr = OWLManager.createOWLOntologyManager();
+                        OWLOntology recipeowl = mngr.loadOntologyFromOntologyDocument(IRI.create(recipe));
+                        OWLOntology rulesOntology = mngr.createOntology();
+                        Set<SWRLRule> swrlRules = fromRecipeToModel(recipeowl);
+                        mngr.addAxioms(rulesOntology, swrlRules);
+                        rulesOntology = mngr.getOntology(rulesOntology.getOntologyID());
+                        // Create a reasoner to run rules contained in the
+                        // recipe by using the server and-point
+                        RunRules rulereasoner = new RunRules(rulesOntology, inputowl, new URL(
+                                owllink_endpoint));
+                        // Run the rule reasoner to the input RDF with the added
+                        // top-ontology
+                        inputowl = rulereasoner.runRulesReasoner();
+                    }
+                    // Create the reasoner for the consistency check by using
+                    // the server and-point
+                    CreateReasoner newreasoner = new CreateReasoner(inputowl, new URL(owllink_endpoint));
+                    // Prepare and start the reasoner to classify ontology's
+                    // resources
+                    RunReasoner reasoner = new RunReasoner(newreasoner.getReasoner());
+
+                    // Create a new OWLOntology model where to put the inferred
+                    // axioms
+                    OWLOntology output = OWLManager.createOWLOntologyManager().createOntology(
+                        inputowl.getOntologyID());
+                    // Initial input axioms count
+                    int startax = output.getAxiomCount();
+                    // Run the classification
+                    output = reasoner.runClassifyInference(output);
+                    // End output axioms count
+                    int endax = output.getAxiomCount();
+
+                    if ((endax - startax) > 0) {
+                        // Some inference is retrieved
+                        return Response.ok(output).build();
+                    } else {
+                        // No data is retrieved
+                        return Response.status(NO_CONTENT).build();
+                    }
+
+                } catch (InconsistentOntologyException exc) {
+                    log.error("Cannot classify ionconsistent ontology " + inputowl.getOntologyID(), exc);
+                    return Response.status(PRECONDITION_FAILED).build();
+                }
+            }
+        } catch (Exception e) {
+            throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
+        }
 
     }
-    
+
     @GET
     @Produces(TEXT_HTML)
     public Response getView() {