Author: alexdma
Date: Thu Feb 9 16:47:52 2012
New Revision: 1242393
URL: http://svn.apache.org/viewvc?rev=1242393&view=rev
Log:
Replacing references to commons.owl which were undone by a recent commit
(STANBOL-463)
Modified:
incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java
Modified:
incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java?rev=1242393&r1=1242392&r2=1242393&view=diff
==============================================================================
---
incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java
(original)
+++
incubator/stanbol/trunk/enhancer/engines/refactor/src/main/java/org/apache/stanbol/enhancer/engines/refactor/RefactorEnhancementEngine.java
Thu Feb 9 16:47:52 2012
@@ -16,7 +16,7 @@
*/
package org.apache.stanbol.enhancer.engines.refactor;
- import java.io.BufferedReader;
+import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -43,6 +43,7 @@ import org.apache.felix.scr.annotations.
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.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.servicesapi.ContentItem;
@@ -67,7 +68,6 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
import
org.apache.stanbol.ontologymanager.ontonet.api.session.SessionLimitException;
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionManager;
-import org.apache.stanbol.owl.transformation.OWLAPIToClerezzaConverter;
import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
import org.apache.stanbol.rules.base.api.Recipe;
import org.apache.stanbol.rules.base.api.Rule;
@@ -103,49 +103,36 @@ import org.slf4j.LoggerFactory;
*
*/
-@Component(
- configurationFactory=true,
- policy=ConfigurationPolicy.REQUIRE,
- specVersion="1.1",
- metatype = true,
- immediate = true,
- inherit = true
- )
+@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")
-
+@Properties(value = {@Property(name = EnhancementEngine.PROPERTY_NAME, value =
"seo_refactoring")
+
})
-public class RefactorEnhancementEngine extends
AbstractEnhancementEngine<RuntimeException, RuntimeException> implements
EnhancementEngine, ServiceProperties {
+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
*/
- @Property(value="seo")
- public static final String SCOPE = "engine.refactor.scope";
-
- @Property(value="")
- public static final String RECIPE_LOCATION =
"engine.refactor.recipe.location";
-
- @Property(value="google_rich_snippet_rules")
- public static final String RECIPE_ID = "engine.refactor.recipe.id";
-
- @Property( cardinality = 1000,
- value={
-
"http://ontologydesignpatterns.org/ont/iks/kres/dbpedia_demo.owl",
- ""
- }
- )
- public static final String SCOPE_CORE_ONTOLOGY =
"engine.refactor.scope.core.ontology";
-
- @Property(boolValue=true)
- public static final String APPEND_OTHER_ENHANCEMENT_GRAPHS =
"engine.refactor.append.graphs";
-
- @Property(boolValue=true)
- public static final String USE_ENTITY_HUB =
"engine.refactor.entityhub";
-
-
+ @Property(value = "seo")
+ public static final String SCOPE = "engine.refactor.scope";
+
+ @Property(value = "")
+ public static final String RECIPE_LOCATION =
"engine.refactor.recipe.location";
+
+ @Property(value = "google_rich_snippet_rules")
+ public static final String RECIPE_ID = "engine.refactor.recipe.id";
+
+ @Property(cardinality = 1000, value =
{"http://ontologydesignpatterns.org/ont/iks/kres/dbpedia_demo.owl",
+ ""})
+ public static final String SCOPE_CORE_ONTOLOGY =
"engine.refactor.scope.core.ontology";
+
+ @Property(boolValue = true)
+ public static final String APPEND_OTHER_ENHANCEMENT_GRAPHS =
"engine.refactor.append.graphs";
+
+ @Property(boolValue = true)
+ public static final String USE_ENTITY_HUB = "engine.refactor.entityhub";
@Reference
ONManager onManager;
@@ -163,23 +150,22 @@ public class RefactorEnhancementEngine e
Refactorer refactorer;
private RefactorEnhancementEngineConf engineConfiguration;
-
+
private ComponentInstance refactorEngineComponentInstance;
-
+
private OntologyScope scope;
-
+
private final Logger log = LoggerFactory.getLogger(getClass());
-
+
private final Object lock = new Object();
private ComponentContext context;
-
-
+
@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.
+ * 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.
*/
@@ -207,8 +193,8 @@ public class RefactorEnhancementEngine e
/*
* Now we prepare the OntoNet environment. First we create the OntoNet
session in which run the whole
*/
- //String sessionID = null;
-
+ // String sessionID = null;
+
Session tmpSession = null;
try {
tmpSession = sessionManager.createSession();
@@ -216,21 +202,18 @@ public class RefactorEnhancementEngine e
// TODO Auto-generated catch block
e1.printStackTrace();
}
-
-
- if(tmpSession != null){
-
+ if (tmpSession != null) {
+
final Session session = tmpSession;
-
- //final String sessionIdentifier = sessionID;
-
+
+ // final String sessionIdentifier = sessionID;
+
/*
* We retrieve the session space
*/
- //OntologySpace sessionSpace =
scope.getSessionSpace(sessionIdentifier);
-
-
+ // OntologySpace sessionSpace =
scope.getSessionSpace(sessionIdentifier);
+
log.debug("The session space is " + session);
while (tripleIt.hasNext()) {
Triple triple = tripleIt.next();
@@ -238,22 +221,23 @@ public class RefactorEnhancementEngine e
/*
* the entity uri
*/
- final String entityReferenceString =
entityReference.toString().replace("<", "").replace(">", "");
+ 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);
-
+
/*
- * 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.
+ * 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 {
@@ -265,34 +249,35 @@ public class RefactorEnhancementEngine 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");
+ 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
@@ -310,41 +295,41 @@ public class RefactorEnhancementEngine e
// 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);
}
-
+
}
-
+
/*
* Now we merge the RDF from the T-box - the ontologies - and the
A-box - the RDF data fetched
*/
-
+
final OWLOntologyManager man =
OWLManager.createOWLOntologyManager();
-
+
OWLOntologySetProvider provider = new OWLOntologySetProvider() {
-
+
@Override
public Set<OWLOntology> getOntologies() {
-
+
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.
+ * 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);
@@ -352,49 +337,52 @@ public class RefactorEnhancementEngine e
return ontologies;
}
};
-
+
/*
- * We merge all the ontologies from the session space of the scope
into a single ontology that will be
- * used for the refactoring.
+ * We merge all the ontologies from the session space of the scope
into a single ontology that
+ * will be used for the refactoring.
*/
OWLOntologyMerger merger = new OWLOntologyMerger(provider);
-
+
OWLOntology ontology;
try {
ontology = merger.createMergedOntology(man,
IRI.create("http://fise.iks-project.eu/dulcifier/integrity-check"));
-
+
/*
- * To perform the refactoring of the ontology to a given
vocabulary we use the Stanbol Refactor.
+ * 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.
*/
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()));
-
+
+ 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);
+ log.error("The recipe with ID " +
engineConfiguration.getRecipeId() + " does not exists",
+ e);
}
-
+
log.debug("Merged ontologies in " + ontology);
-
+
/*
- * The new generated ontology is converted to Clarezza format
and than added os substitued to the
- * old mGraph.
+ * 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));
@@ -404,13 +392,12 @@ public class RefactorEnhancementEngine e
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);
}
@@ -527,30 +514,30 @@ public class RefactorEnhancementEngine e
@SuppressWarnings("unchecked")
@Activate
protected void activate(final ComponentContext context) throws
ConfigurationException {
- super.activate(context);
-
+ 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();){
+ 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));
}
-
+
engineConfiguration = new
DefaultRefactorEnhancementEngineConf(properties);
-
+
initEngine(engineConfiguration);
-
+
log.info("Activated Refactor Enhancement Engine");
}
-
- private void initEngine(RefactorEnhancementEngineConf engineConfiguration){
-
+
+ private void initEngine(RefactorEnhancementEngineConf engineConfiguration)
{
+
/*
* Get the Scope Factory from the ONM of KReS that allows to create
new scopes
*/
@@ -564,15 +551,9 @@ public class RefactorEnhancementEngine e
// 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;
- }
- */
+ * 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() {
@@ -700,8 +681,7 @@ public class RefactorEnhancementEngine e
.getResourceAsStream("/META-INF/default/seo_rules.sem");
log.debug("Loaded default recipe.", this);
}
-
-
+
if (recipeStream != null) {
recipeString = "";
@@ -718,8 +698,8 @@ public class RefactorEnhancementEngine e
e.printStackTrace();
}
}
-
- log.debug("Recipe: "+recipeString, this);
+
+ log.debug("Recipe: " + recipeString, this);
/*
* step 3
@@ -732,15 +712,15 @@ public class RefactorEnhancementEngine 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 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()));
}
}
}
@@ -751,15 +731,14 @@ public class RefactorEnhancementEngine e
* 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();
+ RuleList recipeRuleList =
ruleStore.getRecipe(IRI.create(engineConfiguration.getRecipeId()))
+ .getkReSRuleList();
/*
* step 2: remove the recipe
@@ -846,6 +825,5 @@ public class RefactorEnhancementEngine e
return fetchedOntology;
}
-
}