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/31 19:03:27 UTC

svn commit: r1163701 - in /incubator/stanbol/branches/jena-reasoners/reasoners: owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/ web/src/main/java/org/apache/stanbol/reasoners/web/resources/

Author: enridaga
Date: Wed Aug 31 17:03:27 2011
New Revision: 1163701

URL: http://svn.apache.org/viewvc?rev=1163701&view=rev
Log:
Fixed a bug which prevented from adding rules correctly (STANBOL-185)

Modified:
    incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java
    incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java?rev=1163701&r1=1163700&r2=1163701&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java (original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java Wed Aug 31 17:03:27 2011
@@ -46,10 +46,9 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractOWLApiReasoningService implements OWLApiReasoningService {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-
     /**
-     * An OWLOntologyManager to be used to place a target ontology. We don't want to use the
-     * manager bound to the input ontologies for that, we don't want to interfere with it.
+     * An OWLOntologyManager to be used to place a target ontology. We don't want to use the manager bound to
+     * the input ontologies for that, we don't want to interfere with it.
      * 
      * Other {@see OWLApiReasoningService}s may want to change this.
      * 
@@ -59,8 +58,8 @@ public abstract class AbstractOWLApiReas
         log.info("createOWLOntologyManager()");
         // We want a single instance here
         OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
-        log.info("manager: {}",manager);
-     // FIXME Which is the other way of doing this?
+        log.info("manager: {}", manager);
+        // FIXME Which is the other way of doing this?
         // Maybe -> OWLOntologyManagerProperties();
         manager.setSilentMissingImportsHandling(true);
         // Listening for missing imports
@@ -70,18 +69,19 @@ public abstract class AbstractOWLApiReas
                 log.warn("Missing import {} ", arg0.getImportedOntologyURI());
             }
         });
-        manager.addOntologyLoaderListener(new OWLOntologyLoaderListener(){
+        manager.addOntologyLoaderListener(new OWLOntologyLoaderListener() {
 
             @Override
             public void finishedLoadingOntology(LoadingFinishedEvent arg0) {
-                log.info("Finished loading {} (imported: {})",arg0.getOntologyID(),arg0.isImported());
+                log.info("Finished loading {} (imported: {})", arg0.getOntologyID(), arg0.isImported());
             }
 
             @Override
             public void startedLoadingOntology(LoadingStartedEvent arg0) {
-                log.info("Started loading {} (imported: {}) ...",arg0.getOntologyID(),arg0.isImported());
-                log.info(" ... from {}",arg0.getDocumentIRI().toString());
-            }});
+                log.info("Started loading {} (imported: {}) ...", arg0.getOntologyID(), arg0.isImported());
+                log.info(" ... from {}", arg0.getDocumentIRI().toString());
+            }
+        });
         return manager;
     }
 
@@ -101,9 +101,9 @@ public abstract class AbstractOWLApiReas
      * @return
      */
     @Override
-    public  Set<OWLAxiom> run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException,
-                                                                   InconsistentInputException {
-        log.info("run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators)");  
+    public Set<OWLAxiom> run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException,
+                                                                                                            InconsistentInputException {
+        log.debug("run(OWLOntology input, List<InferredAxiomGenerator<? extends OWLAxiom>> generators)");
         try {
             // Get the manager
             OWLOntologyManager manager = createOWLOntologyManager();
@@ -120,17 +120,17 @@ public abstract class AbstractOWLApiReas
             Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
             try {
                 OWLOntology output = manager.createOntology();
-                log.info("Created output ontology: {}",output);
-                try{
+                log.debug("Created output ontology: {}", output);
+                try {
                     inferred.fillOntology(manager, output);
-                }catch(InconsistentOntologyException i){
+                } catch (InconsistentOntologyException i) {
                     throw i;
-                }catch(Throwable t){
-                    log.error("Some problem occurred:\n {}",t.getStackTrace());
+                } catch (Throwable t) {
+                    log.error("Some problem occurred:\n {}", t.getStackTrace());
                     throw new ReasoningServiceException();
                 }
-                log.info("Filled ontology: {}",output);
-                log.info("Temporary ID is {}", output.getOntologyID());
+                log.debug("Filled ontology: {}", output);
+                log.debug("Temporary ID is {}", output.getOntologyID());
                 axioms = manager.getOntology(output.getOntologyID()).getAxioms();
                 // IMPORTANT We remove the ontology from the manager
                 manager.removeOntology(output);
@@ -146,7 +146,7 @@ public abstract class AbstractOWLApiReas
              */
             throw new InconsistentInputException();
         } catch (Exception exception) {
-            log.error("An exception have been thrown while executing method run()",exception);
+            log.error("An exception have been thrown while executing method run()", exception);
             throw new ReasoningServiceException();
         }
     }
@@ -166,23 +166,20 @@ public abstract class AbstractOWLApiReas
                              List<InferredAxiomGenerator<? extends OWLAxiom>> generators) throws ReasoningServiceException,
                                                                                          InconsistentInputException {
         log.debug("Called method run(OWLOntology,List<SWRLRule>,List)");
-        OWLOntologyManager manager = createOWLOntologyManager();
-        try {
-            log.debug("Create a input ontology to merge rules in.");
-            OWLOntology input = manager.createOntology();
-            Set<SWRLRule> ruleSet = new HashSet<SWRLRule>();
-            ruleSet.addAll(rules);
-            manager.addAxioms(input, ruleSet);
-            input = manager.getOntology(input.getOntologyID());
-            log.debug("Created ontology: {}", input);
-            log.debug("Calling the run method.");
-            return run(input, generators);
-        } catch (OWLOntologyCreationException e) {
-            log.error("An error have been thrown while attempting to create ontology. Message was: {}",
-                e.getLocalizedMessage());
-            // TODO Add explanation of this exception
-            throw new ReasoningServiceException();
-        }
+        OWLOntologyManager manager = ontology.getOWLOntologyManager();
+
+        log.debug("Adding SWRL rules to the input ontology.");
+        Set<SWRLRule> ruleSet = new HashSet<SWRLRule>();
+        ruleSet.addAll(rules);
+        
+        manager.addAxioms(ontology, ruleSet);
+        if(log.isDebugEnabled())
+            for(OWLAxiom a:ontology.getAxioms()){
+                log.debug("Axiom {}",a);
+            }
+        log.debug("Calling the run method.");
+        return run(ontology, generators);
+
     }
 
     /**
@@ -213,15 +210,15 @@ public abstract class AbstractOWLApiReas
                                  List<SWRLRule> rules,
                                  boolean filtered,
                                  Map<String,List<String>> parameters) throws UnsupportedTaskException,
-                                                          ReasoningServiceException,
-                                                          InconsistentInputException {
-        log.info("Called task {} with data {}",taskID,data);
+                                                                     ReasoningServiceException,
+                                                                     InconsistentInputException {
+        log.info("Called task {} with data {}", taskID, data);
         if (taskID.equals(ReasoningService.Tasks.CLASSIFY)) {
             if (rules != null) {
-                
+
                 return classify(data, rules);
             } else {
-                log.info("No rules attached");
+                log.warn("No rules attached");
                 return classify(data);
             }
         } else if (taskID.equals(ReasoningService.Tasks.ENRICH)) {
@@ -289,7 +286,7 @@ public abstract class AbstractOWLApiReas
      */
     protected Set<OWLAxiom> classify(OWLOntology ontology) throws ReasoningServiceException,
                                                           InconsistentInputException {
-       log.info("classify(OWLOntology ontology)");
+        log.info("classify(OWLOntology ontology)");
         return run(ontology, getClassifyAxiomGenerators());
     }
 

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java?rev=1163701&r1=1163700&r2=1163701&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java (original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java Wed Aug 31 17:03:27 2011
@@ -57,6 +57,7 @@ import org.apache.stanbol.reasoners.web.
 import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
 import org.apache.stanbol.rules.base.api.Recipe;
 import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.base.api.util.RuleList;
 import org.semanticweb.owlapi.apibinding.OWLManager;
 import org.semanticweb.owlapi.io.OWLOntologyCreationIOException;
 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
@@ -280,8 +281,10 @@ public class ReasoningServiceTaskResourc
             } catch (OWLOntologyCreationException e) {
                 throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
             }
+            // Prepare rules
+            List<SWRLRule> rules = prepareOWLApiRules(recipe);
             return executor.executeOWLApiReasoningService(getCurrentTask(),
-                (OWLApiReasoningService) getCurrentService(), input, null, targetGraphID, false, this.parameters);
+                (OWLApiReasoningService) getCurrentService(), input, rules, targetGraphID, false, this.parameters);
         }
         throw new WebApplicationException(new Exception("Unsupported implementation"),
                 Response.Status.INTERNAL_SERVER_ERROR);
@@ -611,10 +614,13 @@ public class ReasoningServiceTaskResourc
             }
             OntologySpace coreSpace = scope.getCoreSpace();
             Set<OWLOntology> coreOntologies = coreSpace.getOntologies(true);
+            log.info("Found {} ontologies in core space",coreOntologies.size());
             OntologySpace customSpace = scope.getCustomSpace();
             Set<OWLOntology> customOntologies = customSpace.getOntologies(true);
+            log.info("Found {} ontologies in custom space",coreOntologies.size());
 
             Set<OWLOntology> sessionOntologies = new HashSet<OWLOntology>();
+            log.info("Found {} ontologies in session space",coreOntologies.size());
 
             if (sessionSpace != null) {
                 // We collect all the ontologies in session (here we use
@@ -800,14 +806,15 @@ public class ReasoningServiceTaskResourc
             } else if (type.isAssignableFrom(OWLOntology.class)) {
                 OWLOntology ready = decantOntology(merged, createOWLOntologyManager());
                 output = ready;
+                //output = merged;
             } else throw new IllegalArgumentException(new Exception(
                     "Only Model.class and OWLOntology.class are allowed"));
             return output;
         } catch (OWLOntologyCreationException e) {
-            log.error("The network for scope/session cannot be retrieved");
+            log.error("The network for scope/session cannot be retrieved:",e);
             throw new IllegalArgumentException();
         } catch (OWLOntologyStorageException e) {
-            log.error("The network for scope/session cannot be retrieved");
+            log.error("The network for scope/session cannot be retrieved:",e);
             throw new IllegalArgumentException("The network for scope/session cannot be retrieved");
         }
     }
@@ -945,6 +952,14 @@ public class ReasoningServiceTaskResourc
                 }
             }
         }
+        try {
+            synchronized (input) {
+                input = decantOntology(input, OWLManager.createOWLOntologyManager());
+            }
+        } catch (OWLOntologyStorageException e) {
+            log.error("Cannot prepare the input");
+            throw new OWLOntologyCreationException();
+        }
         long end = System.currentTimeMillis();
         log.info("[end] Prepared input for OWLApi in {} ms. Size is: {}", (end - start), input.getAxiomCount());
         return input;
@@ -969,6 +984,14 @@ public class ReasoningServiceTaskResourc
                 }
             }
         }
+        try {
+            synchronized (input) {
+                input = decantOntology(input, OWLManager.createOWLOntologyManager());
+            }
+        } catch (OWLOntologyStorageException e) {
+            log.error("Cannot prepare the input");
+            throw new OWLOntologyCreationException();
+        }
         long end = System.currentTimeMillis();
         log.info("[end] Prepared input for OWLApi in {} ms. Size is: {}", (end - start), input.getAxiomCount());
         return input;
@@ -996,8 +1019,13 @@ public class ReasoningServiceTaskResourc
             rules = new ArrayList<SWRLRule>();
             try {
                 Recipe rec = ruleStore.getRecipe(IRI.create(recipe));
-                for(org.apache.stanbol.rules.base.api.Rule r : rec.getkReSRuleList()){
-                    rules.add(r.toSWRL(OWLManager.getOWLDataFactory()));
+                log.debug("Recipe is: {}",rec);
+                RuleList ruleList = rec.getkReSRuleList();
+                log.debug("RuleList is: {}",ruleList);
+                for(org.apache.stanbol.rules.base.api.Rule r : ruleList ){
+                    SWRLRule swrl = r.toSWRL(OWLManager.getOWLDataFactory());
+                    log.debug("Prepared rule: {}",swrl);
+                    rules.add(swrl);
                 }
             } catch (NoSuchRecipeException e) {
                 log.error("Recipe {} does not exists",recipe);