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 2012/03/21 20:52:12 UTC

svn commit: r1303542 - in /incubator/stanbol/branches/0.9.0-incubating: ./ enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/ enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/derefe...

Author: alexdma
Date: Wed Mar 21 19:52:12 2012
New Revision: 1303542

URL: http://svn.apache.org/viewvc?rev=1303542&view=rev
Log:
Merging latest refactor engine changes [1301611:1302384] into branch

Added:
    incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/dereferencer/Dereferencer.java
      - copied unchanged from r1302384, incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/dereferencer/Dereferencer.java
    incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/dereferencer/DereferencerImpl.java
      - copied unchanged from r1302384, incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/dereferencer/DereferencerImpl.java
Removed:
    incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/dereferencer/IDereferencer.java
Modified:
    incubator/stanbol/branches/0.9.0-incubating/   (props changed)
    incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/DefaultRefactorEnhancementEngineConf.java
    incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java
    incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngineConf.java
    incubator/stanbol/branches/0.9.0-incubating/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntitySearcher.java   (props changed)
    incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/pom.xml
    incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java
    incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphSource.java
    incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java
    incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/AbstractOntologySpaceImpl.java
    incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java
    incubator/stanbol/branches/0.9.0-incubating/reasoners/   (props changed)

Propchange: incubator/stanbol/branches/0.9.0-incubating/
------------------------------------------------------------------------------
  Merged /incubator/stanbol/trunk:r1301612-1302384

Modified: incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/DefaultRefactorEnhancementEngineConf.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/DefaultRefactorEnhancementEngineConf.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/DefaultRefactorEnhancementEngineConf.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/DefaultRefactorEnhancementEngineConf.java Wed Mar 21 19:52:12 2012
@@ -72,12 +72,12 @@ public class DefaultRefactorEnhancementE
     }
 
     @Override
-    public String[] getScopeCoreOntology() {
+    public String[] getScopeCoreOntologies() {
         return (String[]) conf.get(SCOPE_CORE_ONTOLOGY);
     }
 
     @Override
-    public void setScopeCoreOntology(String[] coreOntologyURI) {
+    public void setScopeCoreOntologies(String[] coreOntologyURI) {
         conf.put(SCOPE_CORE_ONTOLOGY, coreOntologyURI);
     }
 

Modified: incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java Wed Mar 21 19:52:12 2012
@@ -21,31 +21,33 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.Resource;
 import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.TripleCollection;
 import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.access.TcProvider;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
 import org.apache.stanbol.commons.owl.transformation.OWLAPIToClerezzaConverter;
 import org.apache.stanbol.enhancer.engines.refactor.dereferencer.Dereferencer;
-import org.apache.stanbol.enhancer.engines.refactor.dereferencer.IDereferencer;
+import org.apache.stanbol.enhancer.engines.refactor.dereferencer.DereferencerImpl;
 import org.apache.stanbol.enhancer.servicesapi.ContentItem;
 import org.apache.stanbol.enhancer.servicesapi.EngineException;
 import org.apache.stanbol.enhancer.servicesapi.EnhancementEngine;
@@ -55,14 +57,16 @@ import org.apache.stanbol.entityhub.core
 import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
 import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
 import org.apache.stanbol.entityhub.servicesapi.model.Entity;
-import org.apache.stanbol.entityhub.servicesapi.model.Representation;
 import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteManager;
 import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.DuplicateIDException;
 import org.apache.stanbol.ontologymanager.ontonet.api.collector.UnmodifiableOntologyCollectorException;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphContentInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.GraphSource;
 import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
+import org.apache.stanbol.ontologymanager.ontonet.api.io.RootOntologyIRISource;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyProvider;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScope;
-import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologyScopeFactory;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.OntologySpace;
 import org.apache.stanbol.ontologymanager.ontonet.api.scope.ScopeRegistry;
 import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
@@ -84,8 +88,6 @@ import org.semanticweb.owlapi.model.IRI;
 import org.semanticweb.owlapi.model.OWLOntology;
 import org.semanticweb.owlapi.model.OWLOntologyCreationException;
 import org.semanticweb.owlapi.model.OWLOntologyManager;
-import org.semanticweb.owlapi.model.OWLOntologySetProvider;
-import org.semanticweb.owlapi.util.OWLOntologyMerger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -102,7 +104,6 @@ import org.slf4j.LoggerFactory;
  * @author andrea.nuzzolese, alberto.musetti
  * 
  */
-
 @Component(configurationFactory = true, policy = ConfigurationPolicy.REQUIRE, specVersion = "1.1", metatype = true, immediate = true, inherit = true)
 @Service
 @Properties(value = {@Property(name = EnhancementEngine.PROPERTY_NAME, value = "seo_refactoring")
@@ -111,719 +112,434 @@ import org.slf4j.LoggerFactory;
 public class RefactorEnhancementEngine extends AbstractEnhancementEngine<RuntimeException,RuntimeException>
         implements EnhancementEngine, ServiceProperties {
 
-    /*
-     * TODO This are the scope and recipe IDs to be used by this implementation In future implementation this
-     * will be configurable
+    /**
+     * A special input source that allows to bind a physical IRI with an ontology parsed from an input stream.
+     * Due to its unconventional nature it is kept private.
+     * 
+     * @author alexdma
+     * 
      */
-    @Property(value = "seo")
-    public static final String SCOPE = RefactorEnhancementEngineConf.SCOPE;
+    private class GraphContentSourceWithPhysicalIRI extends GraphContentInputSource {
 
-    @Property(value = "")
-    public static final String RECIPE_LOCATION = RefactorEnhancementEngineConf.RECIPE_LOCATION;
+        public GraphContentSourceWithPhysicalIRI(InputStream content, IRI physicalIri) {
+            super(content);
+            bindPhysicalIri(physicalIri);
+        }
+
+    }
+
+    @Property(boolValue = true)
+    public static final String APPEND_OTHER_ENHANCEMENT_GRAPHS = RefactorEnhancementEngineConf.APPEND_OTHER_ENHANCEMENT_GRAPHS;
 
     @Property(value = "google_rich_snippet_rules")
     public static final String RECIPE_ID = RefactorEnhancementEngineConf.RECIPE_ID;
 
+    @Property(value = "")
+    public static final String RECIPE_LOCATION = RefactorEnhancementEngineConf.RECIPE_LOCATION;
+
+    @Property(value = "seo")
+    public static final String SCOPE = RefactorEnhancementEngineConf.SCOPE;
+
     @Property(cardinality = 1000, value = {"http://ontologydesignpatterns.org/ont/iks/kres/dbpedia_demo.owl"})
     public static final String SCOPE_CORE_ONTOLOGY = RefactorEnhancementEngineConf.SCOPE_CORE_ONTOLOGY;
 
     @Property(boolValue = true)
-    public static final String APPEND_OTHER_ENHANCEMENT_GRAPHS = RefactorEnhancementEngineConf.APPEND_OTHER_ENHANCEMENT_GRAPHS;
-
-    @Property(boolValue = true)
     public static final String USE_ENTITY_HUB = RefactorEnhancementEngineConf.USE_ENTITY_HUB;
 
-    @Reference
-    ONManager onManager;
+    private ComponentContext context;
 
     @Reference
-    SessionManager sessionManager;
+    Dereferencer dereferencer;
+
+    private RefactorEnhancementEngineConf engineConfiguration;
+
+    private final Object lock = new Object();
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
     @Reference
-    ReferencedSiteManager referencedSiteManager;
+    ONManager onManager;
 
     @Reference
-    RuleStore ruleStore;
+    OntologyProvider<TcProvider> ontologyProvider;
+
+    private ComponentInstance refactorEngineComponentInstance;
 
     @Reference
     Refactorer refactorer;
 
-    private RefactorEnhancementEngineConf engineConfiguration;
+    @Reference
+    ReferencedSiteManager referencedSiteManager;
 
-    private ComponentInstance refactorEngineComponentInstance;
+    @Reference
+    RuleStore ruleStore;
 
     private OntologyScope scope;
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
+    @Reference
+    SessionManager sessionManager;
 
-    private final Object lock = new Object();
+    /**
+     * Activating the component
+     * 
+     * @param context
+     */
+    @SuppressWarnings("unchecked")
+    @Activate
+    protected void activate(final ComponentContext context) throws ConfigurationException {
+        log.info("in " + RefactorEnhancementEngine.class + " activate with context " + context);
+        if (context == null) {
+            throw new IllegalStateException("No valid" + ComponentContext.class + " parsed in activate!");
+        }
+        super.activate(context);
+        this.context = context;
 
-    private ComponentContext context;
+        Map<String,Object> config = new HashMap<String,Object>();
+        Dictionary<String,Object> properties = (Dictionary<String,Object>) context.getProperties();
+        // copy the properties to a map
+        for (Enumeration<String> e = properties.keys(); e.hasMoreElements();) {
+            String key = e.nextElement();
+            config.put(key, properties.get(key));
+            log.debug("Configuration property: " + key + " :- " + properties.get(key));
+        }
+
+        // Initialize engine-specific features.
+        engineConfiguration = new DefaultRefactorEnhancementEngineConf(properties);
+        initEngine(engineConfiguration);
+
+        log.debug(RefactorEnhancementEngine.class + " activated.");
+    }
 
     @Override
     public int canEnhance(ContentItem ci) throws EngineException {
         /*
-         * The Refactor can enhance only content items that are previously enhanced by other enhancement
-         * engines, as it must be the last engine in the chain.
-         * 
-         * Works only if some enhancement has been produced.
+         * Being a post-processing engine, the Refactor can enhance only content items that are previously
+         * enhanced by other enhancement engines.
          */
-        MGraph mGraph = ci.getMetadata();
-        if (mGraph != null) {
-            return ENHANCE_SYNCHRONOUS;
-        } else {
-            return CANNOT_ENHANCE;
-        }
+        return ci.getMetadata() == null ? CANNOT_ENHANCE : ENHANCE_SYNCHRONOUS;
     }
 
     @Override
     public void computeEnhancements(ContentItem ci) throws EngineException {
-        /*
-         * Retrieve the graph
-         */
-        final MGraph mGraph = ci.getMetadata();
-
-        /*
-         * We filter the entities recognized by the engines
-         */
-        UriRef fiseEntityReference = new UriRef("http://fise.iks-project.eu/ontology/entity-reference");
-        Iterator<Triple> tripleIt = mGraph.filter(null, fiseEntityReference, null);
-
-        /*
-         * Now we prepare the OntoNet environment. First we create the OntoNet session in which run the whole
-         */
-        // String sessionID = null;
 
-        Session tmpSession = null;
+        // Prepare the OntoNet environment. First we create the OntoNet session in which run the whole
+        final Session session;
         try {
-            tmpSession = sessionManager.createSession();
+            session = sessionManager.createSession();
         } catch (SessionLimitException e1) {
-            // TODO Auto-generated catch block
-            e1.printStackTrace();
+            throw new EngineException(
+                    "OntoNet session quota reached. The Refactor Engine requires its own new session to execute.");
         }
+        if (session == null) throw new EngineException(
+                "Failed to create OntoNet session. The Refactor Engine requires its own new session to execute.");
 
-        if (tmpSession != null) {
-
-            final Session session = tmpSession;
-
-            // final String sessionIdentifier = sessionID;
-
-            /*
-             * We retrieve the session space
-             */
-            // OntologySpace sessionSpace = scope.getSessionSpace(sessionIdentifier);
-
-            log.debug("The session space is " + session);
-            while (tripleIt.hasNext()) {
-                Triple triple = tripleIt.next();
-                Resource entityReference = triple.getObject();
-                /*
-                 * the entity uri
-                 */
-                final String entityReferenceString = entityReference.toString().replace("<", "")
-                        .replace(">", "");
-                log.debug("Trying to resolve entity " + entityReferenceString);
-                /**
-                 * We fetch the entity in the OntologyInputSource object
-                 */
-                try {
-
-                    final IRI fetchedIri = IRI.create(entityReferenceString);
+        log.debug("Refactor enhancement job will run in session '{}'.", session.getID());
 
-                    /*
-                     * The RDF graph of an entity is fetched via the EntityHub. The getEntityOntology is a
-                     * method the do the job of asking the entity to the EntityHub and wrap the RDF graph into
-                     * an OWLOntology.
-                     */
-                    OWLOntology fetched = null;
-
-                    if (engineConfiguration.isEntityHubUsed()) {
-                        fetched = getEntityOntology(entityReferenceString);
-                    } else {
-                        Dereferencer dereferencer = new Dereferencer();
-                        try {
-                            fetched = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(
-                                dereferencer.resolve(entityReferenceString));
-                        } catch (OWLOntologyCreationException e) {
-                            log.error("An error occurred while trying to create the ontology related to the entity "
-                                      + entityReferenceString);
-                        } catch (FileNotFoundException e) {
-                            log.error("The entity " + entityReferenceString
-                                      + " does not exist or is unreachable");
-                        }
-                    }
-
-                    if (fetched != null) {
-                        final OWLOntology fetchedFinal = fetched;
-                        OntologyInputSource ontologySource = new OntologyInputSource() {
-
-                            @Override
-                            public boolean hasRootOntology() {
-                                return (fetchedFinal != null);
-                            }
-
-                            @Override
-                            public boolean hasPhysicalIRI() {
-                                return true;
-                            }
-
-                            @Override
-                            public OWLOntology getRootOntology() {
-                                return fetchedFinal;
-                            }
-
-                            @Override
-                            public IRI getPhysicalIRI() {
-                                return fetchedIri;
-                            }
-
-                            @Override
-                            public Set<OWLOntology> getImports(boolean direct) {
-                                // TODO Auto-generated method stub
-                                return null;
-                            }
-
-                            @Override
-                            public String getStorageKey() {
-                                // TODO Auto-generated method stub
-                                return null;
-                            }
-
-                            @Override
-                            public Object getTriplesProvider() {
-                                // TODO Auto-generated method stub
-                                return null;
-                            }
-
-                        };
-                        session.addOntology(ontologySource);
-                    }
-
-                    log.debug("Added " + entityReferenceString + " to the session space of scope "
-                              + engineConfiguration.getScope(), this);
-
-                } catch (UnmodifiableOntologyCollectorException e) {
-                    log.error("Cannot load the entity", e);
+        // Retrieve and filter the metadata graph for entities recognized by the engines.
+        final MGraph metadataGraph = ci.getMetadata(), signaturesGraph = new IndexedMGraph();
+        // FIXME the Stanbol Enhancer vocabulary should be retrieved from somewhere in the enhancer API.
+        final UriRef ENHANCER_ENTITY_REFERENCE = new UriRef(
+                "http://fise.iks-project.eu/ontology/entity-reference");
+        Iterator<Triple> tripleIt = metadataGraph.filter(null, ENHANCER_ENTITY_REFERENCE, null);
+        while (tripleIt.hasNext()) {
+            // Get the entity URI
+            Resource obj = tripleIt.next().getObject();
+            if (!(obj instanceof UriRef)) {
+                log.warn("Invalid UriRef for entity reference {}. Skipping.", obj);
+                continue;
+            }
+            final String entityReference = ((UriRef) obj).getUnicodeString();
+            log.debug("Trying to resolve entity {}", entityReference);
+
+            // Populate the entity signatures graph, by querying either the Entity Hub or the dereferencer.
+            if (engineConfiguration.isEntityHubUsed()) {
+                MGraph result = populateWithEntity(entityReference, signaturesGraph);
+                if (result != signaturesGraph && result != null) {
+                    log.warn("Entity Hub query added triples to a new graph instead of populating the supplied one!"
+                             + " New signatures will be discarded.");
                 }
-
+            } else try {
+                OntologyInputSource<TripleCollection,?> source = new GraphContentSourceWithPhysicalIRI(
+                        dereferencer.resolve(entityReference), IRI.create(entityReference));
+                signaturesGraph.addAll(source.getRootOntology());
+            } catch (FileNotFoundException e) {
+                log.error("Failed to dereference entity " + entityReference + ". Skipping.", e);
+                continue;
             }
+        }
 
+        try {
             /*
-             * Now we merge the RDF from the T-box - the ontologies - and the A-box - the RDF data fetched
+             * The dedicated session for this job will store the following: (1) all the (merged) signatures
+             * for all detected entities; (2) the original content metadata graph returned earlier in the
+             * chain.
+             * 
+             * There is no chance that (2) could be null, as it was previously controlled by the JobManager
+             * through the canEnhance() method and the computeEnhancement is always called iff the former
+             * returns true.
              */
+            session.addOntology(new GraphSource(signaturesGraph));
+            session.addOntology(new GraphSource(metadataGraph));
+        } catch (UnmodifiableOntologyCollectorException e1) {
+            throw new EngineException("Cannot add enhancement graph to OntoNet session for refactoring", e1);
+        }
 
-            final OWLOntologyManager man = OWLManager.createOWLOntologyManager();
+        try {
+            /*
+             * Export the entire session (incl. entities and enhancement graph) as a single merged ontology.
+             * 
+             * TODO the refactorer should have methods to accommodate an OntologyCollector directly instead.
+             */
+            OWLOntology ontology = session.export(OWLOntology.class, true);
+            log.debug("Refactoring recipe IRI is : " + engineConfiguration.getRecipeId());
 
-            OWLOntologySetProvider provider = new OWLOntologySetProvider() {
+            /*
+             * We pass the ontology and the recipe IRI to the Refactor that returns the refactored graph
+             * expressed by using the given vocabulary.
+             * 
+             * To perform the refactoring of the ontology to a given vocabulary we use the Stanbol Refactor.
+             */
+            Recipe recipe = ruleStore.getRecipe(IRI.create(engineConfiguration.getRecipeId()));
 
-                @Override
-                public Set<OWLOntology> getOntologies() {
+            log.debug("Recipe {} contains {} rules.", recipe, recipe.getkReSRuleList().size());
+            log.debug("The ontology to be refactor is {}", ontology);
 
-                    Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
-                    ontologies.addAll(session.getOntologies(true));
-
-                    /*
-                     * We add to the set the graph containing the metadata generated by previous enhancement
-                     * engines. It is important becaus we want to menage during the refactoring also some
-                     * information fron that graph. As the graph is provided as a Clerezza MGraph, we first
-                     * need to convert it to an OWLAPI OWLOntology. There is no chance that the mGraph could
-                     * be null as it was previously controlled by the JobManager through the canEnhance method
-                     * and the computeEnhancement is always called iff the former returns true.
-                     */
-                    OWLOntology fiseMetadataOntology = OWLAPIToClerezzaConverter
-                            .clerezzaGraphToOWLOntology(mGraph);
-                    ontologies.add(fiseMetadataOntology);
-                    return ontologies;
-                }
-            };
+            ontology = refactorer
+                    .ontologyRefactoring(ontology, IRI.create(engineConfiguration.getRecipeId()));
 
             /*
-             * We merge all the ontologies from the session space of the scope into a single ontology that
-             * will be used for the refactoring.
+             * The newly generated ontology is converted to Clarezza format and then added os substitued to
+             * the old mGraph.
              */
-            OWLOntologyMerger merger = new OWLOntologyMerger(provider);
-
-            OWLOntology ontology;
-            try {
-                ontology = merger.createMergedOntology(man,
-                    IRI.create("http://fise.iks-project.eu/dulcifier/integrity-check"));
+            if (engineConfiguration.isInGraphAppendMode()) {
+                log.debug("Metadata of the content will replace old ones.", this);
+            } else {
+                metadataGraph.clear();
+                log.debug("Content metadata will be appended to the existing ones.", this);
+            }
+            metadataGraph.addAll(OWLAPIToClerezzaConverter.owlOntologyToClerezzaTriples(ontology));
 
-                /*
-                 * To perform the refactoring of the ontology to a given vocabulary we use the Stanbol
-                 * Refactor.
-                 */
-
-                log.debug("Refactoring recipe IRI is : " + engineConfiguration.getRecipeId());
-
-                /*
-                 * We pass the ontology and the recipe IRI to the Refactor that returns the refactored graph
-                 * expressed by using the given vocabulary.
-                 */
+        } catch (RefactoringException e) {
+            String msg = "Refactor engine execution failed on content item " + ci + ".";
+            log.error(msg, e);
+            throw new EngineException(msg, e);
+        } catch (NoSuchRecipeException e) {
+            String msg = "Refactor engine could not find recipe " + engineConfiguration.getRecipeId()
+                         + " to refactor content item " + ci + ".";
+            log.error(msg, e);
+            throw new EngineException(msg, e);
+        } catch (Exception e) {
+            throw new EngineException("Refactor Engine has failed.", e);
+        } finally {
+            /*
+             * The session needs to be destroyed anyhow.
+             * 
+             * Clear contents before destroying (FIXME only do this until this is implemented in the
+             * destroySession() method).
+             */
+            for (IRI iri : session.listManagedOntologies()) {
                 try {
-
-                    Recipe recipe = ruleStore.getRecipe(IRI.create(engineConfiguration.getRecipeId()));
-
-                    log.debug("Rules in the recipe are : " + recipe.getkReSRuleList().size(), this);
-
-                    log.debug("The ontology to be refactor is : " + ontology, this);
-
-                    ontology = refactorer.ontologyRefactoring(ontology,
-                        IRI.create(engineConfiguration.getRecipeId()));
-
-                } catch (RefactoringException e) {
-                    log.error("The refactoring engine failed the execution.", e);
-                } catch (NoSuchRecipeException e) {
-                    log.error("The recipe with ID " + engineConfiguration.getRecipeId() + " does not exists",
-                        e);
+                    String key = ontologyProvider.getKey(iri);
+                    ontologyProvider.getStore().deleteTripleCollection(new UriRef(key));
+                } catch (Exception ex) {
+                    log.error("Failed to delete triple collection " + iri, ex);
+                    continue;
                 }
-
-                log.debug("Merged ontologies in " + ontology);
-
-                /*
-                 * The new generated ontology is converted to Clarezza format and than added os substitued to
-                 * the old mGraph.
-                 */
-                if (engineConfiguration.isInGraphAppendMode()) {
-                    mGraph.addAll(OWLAPIToClerezzaConverter.owlOntologyToClerezzaTriples(ontology));
-                    log.debug("Metadata of the content passd have been substituted", this);
-                } else {
-                    // mGraph.removeAll(mGraph);
-                    mGraph.clear();
-                    mGraph.addAll(OWLAPIToClerezzaConverter.owlOntologyToClerezzaTriples(ontology));
-                    log.debug("Metadata of the content is appended to the existent one", this);
-                }
-
-                /*
-                 * The session needs to be destroyed, as it is no more useful.
-                 */
-                sessionManager.destroySession(session.getID());
-
-            } catch (OWLOntologyCreationException e) {
-                log.error("Cannot create the ontology for the refactoring", e);
             }
+            sessionManager.destroySession(session.getID());
         }
-    }
-
-    // /**
-    // * Setup the KReS session
-    // *
-    // * @return
-    // */
-    // private String createAndAddSessionSpaceToScope() {
-    // /*
-    // * Retrieve the session manager
-    // */
-    // // SessionManager sessionManager = onManager.getSessionManager();
-    // log.debug("Starting create session for the dulcifier");
-    //
-    // /*
-    // * Create and setup the session. TODO FIXME This is an operation that should be made easier for
-    // * developers to do through the API
-    // */
-    // Session session = sessionManager.createSession();
-    // // OntologySpaceFactory ontologySpaceFactory = onManager.getOntologySpaceFactory();
-    // // OntologySpace sessionSpace = ontologySpaceFactory.createSessionOntologySpace(scope.getID());
-    // // try {
-    // // scope.addSessionSpace(sessionSpace, session.getID());
-    // // } catch (UnmodifiableOntologySpaceException e) {
-    // // log.error("Failed to add session space to unmodifiable scope " + scope, e);
-    // // }
-    //
-    // /*
-    // * Finally, we return the session ID to be used by the caller
-    // */
-    // log.debug("Session " + session.getID() + " created", this);
-    // return session.getID();
-    // }
-
-    /**
-     * To create the input source necesary to load the ontology inside the scope.
-     * 
-     * @param uri
-     *            -- A resolvable string uri.
-     * @return An OntologyInputSource
-     */
-    private OntologyInputSource oisForScope(final String uri) {
-        /*
-         * The scope factory needs an OntologyInputSource as input for the core ontology space. We want to use
-         * the dbpedia ontology as core ontology of our scope.
-         */
-        OntologyInputSource ois = new OntologyInputSource() {
 
-            @Override
-            public boolean hasRootOntology() {
-                return true;
-            }
+    }
 
-            @Override
-            public boolean hasPhysicalIRI() {
-                return false;
+    @SuppressWarnings("unchecked")
+    protected void createRefactorEngineComponent(ComponentFactory factory) {
+        // both create*** methods sync on the searcherAndDereferencerLock to avoid
+        // multiple component instances because of concurrent calls
+        synchronized (this.lock) {
+            if (refactorEngineComponentInstance == null) {
+                this.refactorEngineComponentInstance = factory.newInstance(OsgiUtils.copyConfig(context
+                        .getProperties()));
             }
+        }
+    }
 
-            @Override
-            public OWLOntology getRootOntology() {
-                try {
-                    /*
-                     * The input stream for the dbpedia ontology is obtained through the dereferencer
-                     * component.
-                     */
-                    // inputStream = dereferencer.resolve(uri);
-                    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
-                    return manager.loadOntologyFromOntologyDocument(IRI.create(uri));
-                    // return getEntityOntology(uri);
-                } catch (Exception e) {
-                    log.error("Cannot load the ontology " + uri, e);
-                }
-                /** If some errors occur **/
-                return null;
-            }
+    @Deactivate
+    protected void deactivate(ComponentContext context) {
 
-            @Override
-            public IRI getPhysicalIRI() {
-                return null;
-            }
+        // Deactivation clears all the rules and releases OntoNet resources.
 
-            @Override
-            public Set<OWLOntology> getImports(boolean direct) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+        IRI recipeId = IRI.create(engineConfiguration.getRecipeId());
+        try {
+            // step 1: get all the rules
+            log.debug("Recipe {} and its associated rules will be removed from the rule store.", recipeId);
+            RuleList recipeRuleList = ruleStore.getRecipe(recipeId).getkReSRuleList();
+
+            // step 2: remove the recipe
+            if (ruleStore.removeRecipe(recipeId)) {
+                log.debug(
+                    "Recipe {} has been removed correctly. Note that its rules will be removed separately.",
+                    recipeId);
+                // step 3: remove the rules
+                if (recipeRuleList != null) for (Rule rule : recipeRuleList)
+                    if (ruleStore.removeRule(rule)) log.debug("Rule {} has been removed correctly",
+                        rule.getRuleName());
+                    else log.error("Rule {} cannot be removed", rule.getRuleName());
+            } else log.error("Recipe {} cannot be removed.", recipeId);
 
-            @Override
-            public String getStorageKey() {
-                // TODO Auto-generated method stub
-                return null;
-            }
+        } catch (NoSuchRecipeException ex) {
+            log.error("The recipe " + engineConfiguration.getRecipeId() + " doesn't exist", ex);
+        }
 
-            @Override
-            public Object getTriplesProvider() {
-                // TODO Auto-generated method stub
-                return null;
-            }
+        // step 4: clear OntoNet resources
+        scope.getCoreSpace().tearDown();
+        scope.tearDown();
+        onManager.getScopeRegistry().deregisterScope(scope);
+        log.debug("OntoNet resources released : scope {}", scope);
 
-        };
+        log.info("in " + RefactorEnhancementEngine.class + " deactivate with context " + context);
 
-        return ois;
     }
 
     /**
-     * Activating the component
+     * Fetch the OWLOntology containing the graph associated to an entity from Linked Data. It uses the Entity
+     * Hub for accessing LOD and fetching entities.
      * 
-     * @param context
+     * @param entityURI
+     *            {@link String}
+     * @return the {@link OWLOntology} of the entity
      */
-    @SuppressWarnings("unchecked")
-    @Activate
-    protected void activate(final ComponentContext context) throws ConfigurationException {
-        super.activate(context);
-
-        this.context = context;
-
-        Map<String,Object> config = new HashMap<String,Object>();
-        Dictionary<String,Object> properties = (Dictionary<String,Object>) context.getProperties();
-        // copy the properties to a map
-
-        for (Enumeration<String> e = properties.keys(); e.hasMoreElements();) {
-            String key = e.nextElement();
-            config.put(key, properties.get(key));
-            log.info("Configuration property: " + key + " :- " + properties.get(key));
+    private MGraph populateWithEntity(String entityURI, MGraph target) {
+        log.debug("Requesting signature of entity {}", entityURI);
+        MGraph graph = target != null ? target : new IndexedMGraph();
+        // Query the Entity Hub
+        Entity signature = referencedSiteManager.getEntity(entityURI);
+        if (signature != null) {
+            RdfRepresentation rdfSignature = RdfValueFactory.getInstance().toRdfRepresentation(
+                signature.getRepresentation());
+            graph.addAll(rdfSignature.getRdfGraph());
         }
+        return graph;
+    }
 
-        engineConfiguration = new DefaultRefactorEnhancementEngineConf(properties);
-
-        initEngine(engineConfiguration);
-
-        log.info("Activated Refactor Enhancement Engine");
-
+    @Override
+    public Map<String,Object> getServiceProperties() {
+        return Collections.unmodifiableMap(Collections.singletonMap(
+            ServiceProperties.ENHANCEMENT_ENGINE_ORDERING,
+            (Object) ServiceProperties.ORDERING_POST_PROCESSING));
     }
 
+    /**
+     * Method for adding ontologies to the scope core ontology.
+     * <ol>
+     * <li>Get all the ontologies from the property.</li>
+     * <li>Create a base scope.</li>
+     * <li>Retrieve the ontology space from the scope.</li>
+     * <li>Add the ontologies to the scope via ontology space.</li>
+     * </ol>
+     */
     private void initEngine(RefactorEnhancementEngineConf engineConfiguration) {
 
-        /*
-         * Get the Scope Factory from the ONM of KReS that allows to create new scopes
-         */
-        OntologyScopeFactory scopeFactory = onManager.getOntologyScopeFactory();
-
-        /*
-         * Adding ontologies to the scope core ontology. 1) Get all the ontologies from the property. 2)
-         * Create a base scope with an empity ontology. 3) Retrieve the ontology space from the scope. 4) Add
-         * the ontologies to the scope via ontology space.
-         */
-        // Step 1
-        String[] coreScopeOntologySet = engineConfiguration.getScopeCoreOntology();
-        /*
-         * String[] coreScopeOntologySet; if (obj instanceof String[]) { coreScopeOntologySet = (String[])
-         * obj; } else { String[] aux = new String[1]; aux[0] = (String) obj; coreScopeOntologySet = aux; }
-         */
-        // Step 2
-        OntologyInputSource oisbase = new OntologyInputSource() {
-
-            @Override
-            public boolean hasRootOntology() {
-                return true;
-            }
-
-            @Override
-            public boolean hasPhysicalIRI() {
-                return false;
-            }
-
-            @Override
-            public OWLOntology getRootOntology() {
-
-                try {
-                    /*
-                     * The input stream for the dbpedia ontology is obtained through the dereferencer
-                     * component.
-                     */
-                    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
-                    return manager.createOntology();
-                } catch (OWLOntologyCreationException e) {
-                    log.error("Cannot create the scope with empity ontology.", e);
-                } catch (Exception e) {
-                    log.error("Cannot create the scope with empity ontology.", e);
-                }
-                /** If some errors occur **/
-                return null;
-            }
-
-            @Override
-            public IRI getPhysicalIRI() {
-                return null;
-            }
-
-            @Override
-            public Set<OWLOntology> getImports(boolean direct) {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            @Override
-            public String getStorageKey() {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            @Override
-            public Object getTriplesProvider() {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-        };
-
         // IRI dulcifierScopeIRI = IRI.create((String) context.getProperties().get(SCOPE));
         String scopeId = engineConfiguration.getScope();
 
-        /*
-         * The scope is created by the ScopeFactory or loaded from the scope registry of KReS
-         */
+        // Create or get the scope with the configured ID
+        ScopeRegistry scopeRegistry = onManager.getScopeRegistry();
         try {
-            scope = scopeFactory.createOntologyScope(scopeId/* dulcifierScopeIRI */, oisbase);
+            scope = onManager.getOntologyScopeFactory().createOntologyScope(scopeId);
+            // No need to deactivate a newly created scope.
         } catch (DuplicateIDException e) {
-            ScopeRegistry scopeRegistry = onManager.getScopeRegistry();
-            scope = scopeRegistry.getScope(scopeId/* dulcifierScopeIRI */);
+            scope = scopeRegistry.getScope(scopeId);
+            scopeRegistry.setScopeActive(scopeId, false);
         }
-
-        /*
-         * Step 3
-         */
+        // All resolvable ontologies stated in the configuration are loaded into the core space.
         OntologySpace ontologySpace = scope.getCoreSpace();
-
-        /*
-         * Step 4
-         */
         ontologySpace.tearDown();
-        for (int o = 0; o < coreScopeOntologySet.length; o++) {
-            OntologyInputSource ois = oisForScope(coreScopeOntologySet[o]);
-            try {
-                ontologySpace.addOntology(ois);
-            } catch (UnmodifiableOntologyCollectorException ex) {
-                log.error("Unmodifiable Ontology SpaceException.", ex);
+        String[] coreScopeOntologySet = engineConfiguration.getScopeCoreOntologies();
+        List<String> success = new ArrayList<String>(), failed = new ArrayList<String>();
+        try {
+            log.info("Will now load requested ontology into the core space of scope '{}'.", scopeId);
+            OWLOntologyManager sharedManager = OWLManager.createOWLOntologyManager();
+            IRI physicalIRI = null;
+            for (int o = 0; o < coreScopeOntologySet.length; o++) {
+                String url = coreScopeOntologySet[o];
+                try {
+                    physicalIRI = IRI.create(url);
+                } catch (Exception e) {
+                    failed.add(url);
+                }
+                try {
+                    // TODO replace with a Clerezza equivalent
+                    ontologySpace.addOntology(new RootOntologyIRISource(physicalIRI, sharedManager));
+                    success.add(url);
+                } catch (OWLOntologyCreationException e) {
+                    log.error("Failed to load ontology from physical location " + physicalIRI
+                              + " Continuing with next...", e);
+                    failed.add(url);
+                }
             }
+        } catch (UnmodifiableOntologyCollectorException ex) {
+            log.error("Ontology space {} was found locked for modification. Cannot populate.", ontologySpace);
         }
+        for (String s : success)
+            log.info(" >> {} : SUCCESS", s);
+        for (String s : failed)
+            log.info(" >> {} : FAILED", s);
         ontologySpace.setUp();
-
-        log.debug("The set of ontologies loaded in the core scope space is: "
-                  + ontologySpace.getOntologies(true)
-                  + "\nN.B. The root.owl ontology is the first (on the list) ontology added when the scope is created.");
+        if (!scopeRegistry.containsScope(scopeId)) scopeRegistry.registerScope(scope);
+        scopeRegistry.setScopeActive(scopeId, true);
 
         /*
          * The first thing to do is to create a recipe in the rule store that can be used by the engine to
          * refactor the enhancement graphs.
          */
-        log.debug("Start create the Recipe", this);
-
-        ruleStore.addRecipe(IRI.create(engineConfiguration.getRecipeId()), null);
-
-        log.debug("The recipe has been created", this);
+        String recipeId = engineConfiguration.getRecipeId();
+        ruleStore.addRecipe(IRI.create(recipeId), null);
+        log.debug("Initialised blank recipe with ID {}", recipeId);
 
         /*
          * The set of rule to put in the recipe can be provided by the user. A default set of rules is
          * provided in /META-INF/default/seo_rules.sem. Use the property engine.refactor in the felix console
          * to pass to the engine your set of rules.
          */
-
         String recipeLocation = engineConfiguration.getRecipeLocation();
 
         InputStream recipeStream = null;
         String recipeString = null;
 
         if (recipeLocation != null && !recipeLocation.isEmpty()) {
-            IDereferencer dereferencer = new Dereferencer();
+            Dereferencer dereferencer = new DereferencerImpl();
             try {
                 recipeStream = dereferencer.resolve(recipeLocation);
+                log.debug("Loaded recipe from external source {}", recipeLocation);
             } catch (FileNotFoundException e) {
-                log.error("Recipe Stream is null.", this);
+                log.error("Recipe Stream is null.", e);
             }
-            log.debug("Loaded recipe from an external source.", this);
         } else {
-            recipeStream = RefactorEnhancementEngine.class
-                    .getResourceAsStream("/META-INF/default/seo_rules.sem");
-            log.debug("Loaded default recipe.", this);
+            // TODO remove this part (or manage it better in the @Activate method).
+            String loc = "/META-INF/default/seo_rules.sem";
+            recipeStream = getClass().getResourceAsStream(loc);
+            log.debug("Loaded default recipe in {}.", loc);
         }
 
         if (recipeStream != null) {
-
-            recipeString = "";
-
             BufferedReader reader = new BufferedReader(new InputStreamReader(recipeStream));
-
+            recipeString = "";
             String line = null;
             try {
-                while ((line = reader.readLine()) != null) {
+                while ((line = reader.readLine()) != null)
                     recipeString += line;
-                }
             } catch (IOException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
+                log.error("Failed to load Refactor Engine recipe from stream. Aborting read. ", e);
+                recipeString = null;
             }
         }
-
-        log.debug("Recipe: " + recipeString, this);
-
-        /*
-         * step 3
-         */
-        try {
-            // ruleStore.addRuleToRecipe(recipeIRI.toString(), kReSRuleSyntax);
-            ruleStore.addRuleToRecipe(engineConfiguration.getRecipeId(), recipeString);
-            log.debug("Added rules to recipe " + engineConfiguration.getRecipeId());
+        log.debug("Recipe content follows :\n{}", recipeString);
+        if (recipeString != null) try {
+            ruleStore.addRuleToRecipe(recipeId, recipeString);
+            log.debug("Added rules to recipe {}", recipeId);
         } catch (NoSuchRecipeException e) {
-            log.error("The recipe does not exists: ", e);
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    protected void createRefactorEngineComponent(ComponentFactory factory) {
-        // both create*** methods sync on the searcherAndDereferencerLock to avoid
-        // multiple component instances because of concurrent calls
-        synchronized (this.lock) {
-            if (refactorEngineComponentInstance == null) {
-                this.refactorEngineComponentInstance = factory.newInstance(OsgiUtils.copyConfig(context
-                        .getProperties()));
-            }
-        }
-    }
-
-    protected void deactivate(ComponentContext context) {
-
-        /*
-         * Deactivating the dulcifier. The procedure require: 1) get all the rules from the recipe 2) remove
-         * the recipe. 3) remove the single rule. 4) tear down the scope ontologySpace and the scope itself.
-         */
-
-        try {
-            /*
-             * step 1: get all the rule
-             */
-            log.debug("Removing recipe " + engineConfiguration.getRecipeId() + " from RuleStore.", this);
-            RuleList recipeRuleList = ruleStore.getRecipe(IRI.create(engineConfiguration.getRecipeId()))
-                    .getkReSRuleList();
-
-            /*
-             * step 2: remove the recipe
-             */
-            if (ruleStore.removeRecipe(IRI.create(engineConfiguration.getRecipeId()))) {
-                log.debug("The recipe " + engineConfiguration.getRecipeId() + " has been removed correctly");
-            } else {
-                log.error("The recipe " + engineConfiguration.getRecipeId() + " can not be removed");
-            }
-
-            /*
-             * step 3: remove the rules
-             */
-            for (Rule rule : recipeRuleList) {
-                if (ruleStore.removeRule(rule)) {
-                    log.debug("The rule " + rule.getRuleName() + " has been removed correctly");
-                } else {
-                    log.error("The rule " + rule.getRuleName() + " can not be removed");
-                }
-            }
-
-            /*
-             * step 4:
-             */
-            scope.getCoreSpace().tearDown();
-            scope.tearDown();
-
-        } catch (NoSuchRecipeException ex) {
-            log.error("The recipe " + engineConfiguration.getRecipeId() + " doesn't exist", ex);
-        }
-
-        log.info("Deactivated Refactor Enhancement Engine");
-
-    }
-
-    @Override
-    public Map<String,Object> getServiceProperties() {
-        return Collections.unmodifiableMap(Collections.singletonMap(
-            ServiceProperties.ENHANCEMENT_ENGINE_ORDERING,
-            (Object) ServiceProperties.ORDERING_POST_PROCESSING));
-    }
-
-    /**
-     * Fetch the OWLOntology containing the graph associated to an entity from Linked Data. It uses the Entity
-     * Hub for accessing LOD and fetching entities.
-     * 
-     * @param entityURI
-     *            {@link String}
-     * @return the {@link OWLOntology} of the entity
-     */
-    private OWLOntology getEntityOntology(String entityURI) {
-
-        OWLOntology fetchedOntology = null;
-
-        log.debug("Asking entity: " + entityURI);
-        /*
-         * Ask to the entityhub the fetch the entity.
-         */
-        Entity entitySign = referencedSiteManager.getEntity(entityURI);
-
-        /*
-         * Wrap the entity graph into an owl ontology.
-         */
-        MGraph entityMGraph = null;
-
-        if (entitySign != null) {
-            Representation entityRepresentation = entitySign.getRepresentation();
-            RdfRepresentation entityRdfRepresentation = RdfValueFactory.getInstance().toRdfRepresentation(
-                entityRepresentation);
-            TripleCollection tripleCollection = entityRdfRepresentation.getRdfGraph();
-            entityMGraph = new SimpleMGraph();
-            entityMGraph.addAll(tripleCollection);
-        }
-
-        if (entityMGraph != null) {
-            /*
-             * OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); final OWLOntology fetched =
-             * manager.loadOntologyFromOntologyDocument(dereferencer.resolve(entityReferenceString));
-             */
-
-            fetchedOntology = OWLAPIToClerezzaConverter.clerezzaGraphToOWLOntology(entityMGraph);
+            log.error("Failed to add rules to recipe {}. Recipe was not found.", recipeId);
         }
-
-        return fetchedOntology;
-
     }
 
 }

Modified: incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngineConf.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngineConf.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngineConf.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngineConf.java Wed Mar 21 19:52:12 2012
@@ -74,9 +74,9 @@ public interface RefactorEnhancementEngi
 
     public void setRecipeId(String recipeId);
 
-    public String[] getScopeCoreOntology();
+    public String[] getScopeCoreOntologies();
 
-    public void setScopeCoreOntology(String[] coreOntologyIRI);
+    public void setScopeCoreOntologies(String[] coreOntologyIRI);
 
     public boolean isInGraphAppendMode();
 

Propchange: incubator/stanbol/branches/0.9.0-incubating/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntitySearcher.java
------------------------------------------------------------------------------
  Merged /incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/site/AbstractEntitySearcher.java:r1301612-1302384

Modified: incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/pom.xml?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/pom.xml (original)
+++ incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/pom.xml Wed Mar 21 19:52:12 2012
@@ -107,12 +107,16 @@
 		<!-- Stanbol deps -->
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
-			<artifactId>org.apache.stanbol.commons.stanboltools.offline</artifactId>
+			<artifactId>org.apache.stanbol.commons.indexedgraph</artifactId>
 		</dependency>
-		<dependency>
+ 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.commons.owl</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.commons.stanboltools.offline</artifactId>
+		</dependency>
 
 		<!-- Persistence deps -->
 		<dependency>

Modified: incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/collector/OntologyCollector.java Wed Mar 21 19:52:12 2012
@@ -138,7 +138,7 @@ public interface OntologyCollector exten
      * @return
      */
     int getOntologyCount(boolean withClosure);
-    
+
     int getOntologyCount();
 
     /**
@@ -186,4 +186,11 @@ public interface OntologyCollector exten
      * removing the writelock).
      */
     void tearDown();
+
+    /**
+     * TODO replace with Ontology IDs
+     * 
+     * @return
+     */
+    Set<IRI> listManagedOntologies();
 }

Modified: incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphSource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphSource.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphSource.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/api/io/GraphSource.java Wed Mar 21 19:52:12 2012
@@ -1,19 +1,19 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.stanbol.ontologymanager.ontonet.api.io;
 
 import org.apache.clerezza.rdf.core.Graph;
@@ -31,22 +31,16 @@ import org.apache.clerezza.rdf.core.acce
  */
 public class GraphSource extends AbstractClerezzaGraphInputSource {
 
-    public GraphSource(UriRef graphId) {
-        this(graphId, TcManager.getInstance());
-    }
-
     public GraphSource(TripleCollection graph) {
         if (graph instanceof Graph) bindRootOntology((Graph) graph);
         else if (graph instanceof MGraph) bindRootOntology(((MGraph) graph).getGraph());
         else throw new IllegalArgumentException("GraphSource supports only Graph and MGraph types. "
                                                 + graph.getClass() + " is not supported.");
-        try {
-            // TODO how can I know the physical iri?
-            // bindPhysicalIri(rootOntology.getOntologyID().getDefaultDocumentIRI());
-        } catch (Exception e) {
-            // Ontology might be anonymous, no physical IRI then...
-            bindPhysicalIri(null);
-        }
+        bindPhysicalIri(null);
+    }
+
+    public GraphSource(UriRef graphId) {
+        this(graphId, TcManager.getInstance());
     }
 
     /**

Modified: incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/AbstractOntologyCollectorImpl.java Wed Mar 21 19:52:12 2012
@@ -74,6 +74,11 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractOntologyCollectorImpl implements OntologyCollector, Lockable,
         OntologyInputSourceHandler, OWLExportable {
 
+    @Override
+    public Set<IRI> listManagedOntologies() {
+        return managedOntologies;
+    }
+    
     protected String _id = null;
 
     /**

Modified: incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/AbstractOntologySpaceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/AbstractOntologySpaceImpl.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/AbstractOntologySpaceImpl.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/owlapi/AbstractOntologySpaceImpl.java Wed Mar 21 19:52:12 2012
@@ -251,6 +251,14 @@ public abstract class AbstractOntologySp
         return listeners;
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public <O> Set<O> getManagedOntologies(Class<O> returnType, boolean withClosure) {
+        if (!OWLOntology.class.isAssignableFrom(returnType)) throw new UnsupportedOperationException(
+                "This implementation can only get objects of type " + OWLOntology.class);
+        return (Set<O>) getOntologies(withClosure);
+    }
+
     @Override
     public IRI getNamespace() {
         return this.namespace;
@@ -262,14 +270,6 @@ public abstract class AbstractOntologySp
                 managedOntologies.values());
     }
 
-    @SuppressWarnings("unchecked")
-    @Override
-    public <O> Set<O> getManagedOntologies(Class<O> returnType, boolean withClosure) {
-        if (!OWLOntology.class.isAssignableFrom(returnType)) throw new UnsupportedOperationException(
-                "This implementation can only get objects of type " + OWLOntology.class);
-        return (Set<O>) getOntologies(withClosure);
-    }
-
     @Override
     public OWLOntology getOntology(IRI ontologyIri) {
         log.debug("Requesting ontology {} from space {}", ontologyIri, getNamespace() + getID());
@@ -303,6 +303,11 @@ public abstract class AbstractOntologySp
     }
 
     @Override
+    public int getOntologyCount() {
+        return getOntologyCount(true);
+    }
+
+    @Override
     public int getOntologyCount(boolean withClosure) {
         if (!withClosure) return managedOntologies.keySet().size();
         else {
@@ -316,11 +321,6 @@ public abstract class AbstractOntologySp
     }
 
     @Override
-    public int getOntologyCount() {
-        return getOntologyCount(true);
-    }
-
-    @Override
     public Set<Class<?>> getSupportedOntologyTypes() {
         return Collections.unmodifiableSet(supportedTypes);
     }
@@ -335,6 +335,11 @@ public abstract class AbstractOntologySp
         return locked;
     }
 
+    @Override
+    public Set<IRI> listManagedOntologies() {
+        return managedOntologies.keySet();
+    }
+
     private void performAdd(OntologyInputSource<?,?> ontSrc) {
 
         Object obj = ontSrc.getRootOntology();

Modified: incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java?rev=1303542&r1=1303541&r2=1303542&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/session/SessionImpl.java Wed Mar 21 19:52:12 2012
@@ -128,16 +128,18 @@ public class SessionImpl extends Abstrac
     @Override
     protected OWLOntology exportToOWLOntology(boolean merge) {
         OWLOntology o = super.exportToOWLOntology(merge);
-        List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
-        OWLOntologyManager ontologyManager = o.getOWLOntologyManager();
-        OWLDataFactory df = ontologyManager.getOWLDataFactory();
-        // Add import declarations for attached scopes.
-        for (String scopeID : attachedScopes.keySet()) {
-            IRI physIRI = attachedScopes.get(scopeID).getDocumentIRI();
-            changes.add(new AddImport(o, df.getOWLImportsDeclaration(physIRI)));
+        if (!attachedScopes.isEmpty()) {
+            List<OWLOntologyChange> changes = new LinkedList<OWLOntologyChange>();
+            OWLOntologyManager ontologyManager = o.getOWLOntologyManager();
+            OWLDataFactory df = ontologyManager.getOWLDataFactory();
+            // Add import declarations for attached scopes.
+            for (String scopeID : attachedScopes.keySet()) {
+                IRI physIRI = attachedScopes.get(scopeID).getDocumentIRI();
+                changes.add(new AddImport(o, df.getOWLImportsDeclaration(physIRI)));
+            }
+            // Commit
+            ontologyManager.applyChanges(changes);
         }
-        // Commit
-        ontologyManager.applyChanges(changes);
         return o;
     }
 

Propchange: incubator/stanbol/branches/0.9.0-incubating/reasoners/
------------------------------------------------------------------------------
  Merged /incubator/stanbol/trunk/reasoners:r1301612-1302384