You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2011/03/30 19:02:01 UTC
svn commit: r1087016 [1/2] - in /incubator/stanbol/trunk/kres:
reasoners/base/
reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/api/
reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/impl/
reasoners/web/ reasoners/web/src/mai...
Author: alexdma
Date: Wed Mar 30 17:02:00 2011
New Revision: 1087016
URL: http://svn.apache.org/viewvc?rev=1087016&view=rev
Log:
STANBOL-134:
- Moved all consistent refactoring Java and RESTful API to reasoners/base as an extension of the standard refactorer.
- Removed all rules module dependencies on reasoners.
- Replaced printStackTrace() calls from old consistent refactoring methods with slf4j calls.
- Removed unused bogus OntologyStorageResource.
Added:
incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/api/ConsistentRefactorer.java
incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/impl/ConsistentRefactorerImpl.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java
- copied, changed from r1086970, incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java
- copied, changed from r1086970, incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistentRefactoring.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java
- copied, changed from r1086970, incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java
Removed:
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java
incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/OntologyStorageResource.java
Modified:
incubator/stanbol/trunk/kres/reasoners/base/pom.xml
incubator/stanbol/trunk/kres/reasoners/web/pom.xml
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java
incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java
incubator/stanbol/trunk/kres/rules/manager/pom.xml
incubator/stanbol/trunk/kres/rules/refactor/pom.xml
incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/api/Refactorer.java
incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/impl/RefactorerImpl.java
incubator/stanbol/trunk/kres/rules/refactor/src/test/java/org/apache/stanbol/rules/refactor/RefactoringTest.java
incubator/stanbol/trunk/kres/rules/web/pom.xml
incubator/stanbol/trunk/kres/rules/web/src/main/java/org/apache/stanbol/rules/web/RefactorerResource.java
Modified: incubator/stanbol/trunk/kres/reasoners/base/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/base/pom.xml?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/base/pom.xml (original)
+++ incubator/stanbol/trunk/kres/reasoners/base/pom.xml Wed Mar 30 17:02:00 2011
@@ -91,22 +91,12 @@
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
- <!--
- <dependency> <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId> <version>1.5.6</version>
- <scope>provided</scope> </dependency>
- -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>3.4.4</version>
<scope>provided</scope>
</dependency>
- <!--
- <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId>
- <version>1.2.13</version> <scope>provided</scope> </dependency>
- -->
-
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
@@ -149,6 +139,14 @@
<version>2.8.3</version>
<scope>provided</scope>
</dependency>
+
+ <!-- Clerezza deps -->
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.rdf.core</artifactId>
+ <version>0.12-incubating-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
<!-- Stanbol deps -->
<dependency>
@@ -162,6 +160,11 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.rules.refactor</artifactId>
+ <version>${stanbol-version}</version>
+ </dependency>
<!-- Diagnostics deps -->
<dependency>
Added: incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/api/ConsistentRefactorer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/api/ConsistentRefactorer.java?rev=1087016&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/api/ConsistentRefactorer.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/api/ConsistentRefactorer.java Wed Mar 30 17:02:00 2011
@@ -0,0 +1,57 @@
+package org.apache.stanbol.reasoners.base.api;
+
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.refactor.api.Refactorer;
+import org.apache.stanbol.rules.refactor.api.RefactoringException;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+
+/**
+ * A special {@link Refactorer} which includes methods for ensuring/checking consistency in refactored
+ * ontologies.
+ *
+ * @author alessandro
+ *
+ */
+public interface ConsistentRefactorer extends Refactorer {
+
+ /**
+ * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI}
+ * is the {@link IRI} of an IKS ontology and the {@code recipe} is the recipe that needs to be applied to
+ * ontology in order to perform the refactoring. After the refactoring a consistency check is invoked on
+ * the data set.
+ *
+ * @param refactoredDataSetURI
+ * {@link IRI}
+ * @param datasetURI
+ * {@link IRI}
+ * @param recipeIRI
+ * {@link IRI}
+ * @throws RefactoringException
+ * @throws NoSuchRecipeException
+ * @throws InconcistencyException
+ */
+ public void consistentOntologyRefactoring(IRI refactoredOntologyIRI, IRI datasetURI, IRI recipeIRI) throws RefactoringException,
+ NoSuchRecipeException,
+ InconcistencyException;
+
+ /**
+ * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI}
+ * is the URI of an RDF graph in KReS and the {@code recipe} is the recipe that needs to be applied to RDF
+ * graph in order to obtain the refactoring. After the refactoring a consistency check is invoked on the
+ * data set.
+ *
+ * @param datasetURI
+ * {@link UriRef}
+ * @param recipe
+ * {@link UriRef}
+ * @return the refactored {@link MGraph}
+ * @throws InconcistencyException
+ * @throws NoSuchRecipeException
+ * @throws RefactoringException
+ */
+ public OWLOntology consistentOntologyRefactoring(OWLOntology inputOntology, IRI recipeIRI) throws RefactoringException,
+ NoSuchRecipeException,
+ InconcistencyException;
+
+}
Added: incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/impl/ConsistentRefactorerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/impl/ConsistentRefactorerImpl.java?rev=1087016&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/impl/ConsistentRefactorerImpl.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/base/src/main/java/org/apache/stanbol/reasoners/base/impl/ConsistentRefactorerImpl.java Wed Mar 30 17:02:00 2011
@@ -0,0 +1,273 @@
+package org.apache.stanbol.reasoners.base.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Dictionary;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
+import org.apache.stanbol.owlapi.trasformation.JenaToOwlConvert;
+import org.apache.stanbol.reasoners.base.api.ConsistentRefactorer;
+import org.apache.stanbol.reasoners.base.api.InconcistencyException;
+import org.apache.stanbol.reasoners.base.api.Reasoner;
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.base.api.Recipe;
+import org.apache.stanbol.rules.base.api.Rule;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.base.api.util.RuleList;
+import org.apache.stanbol.rules.refactor.api.RefactoringException;
+import org.apache.stanbol.rules.refactor.api.util.URIGenerator;
+import org.apache.stanbol.rules.refactor.impl.RefactorerImpl;
+import org.osgi.service.component.ComponentContext;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
+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.OWLOntologyStorageException;
+import org.semanticweb.owlapi.util.OWLOntologyMerger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.ontology.OntModel;
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.rdf.model.Model;
+
+/**
+ * Default implementation of a {@link ConsistentRefactorer}.
+ *
+ * @author alessandro
+ *
+ */
+@Component(immediate = true, metatype = true)
+@Service(ConsistentRefactorer.class)
+public class ConsistentRefactorerImpl extends RefactorerImpl implements ConsistentRefactorer {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference
+ Reasoner kReSReasoner;
+
+ /**
+ * This default constructor is <b>only</b> intended to be used by the OSGI environment with Service
+ * Component Runtime support.
+ * <p>
+ * DO NOT USE to manually create instances - the ConsistentRefactorerImpl instances do need to be
+ * configured! YOU NEED TO USE
+ * {@link #ConsistentRefactorerImpl(WeightedTcProvider, Serializer, TcManager, ONManager, SemionManager, RuleStore, Reasoner, Dictionary)}
+ * or its overloads, to parse the configuration and then initialise the rule store if running outside an
+ * OSGI environment.
+ */
+ public ConsistentRefactorerImpl() {
+
+ }
+
+ /**
+ * Basic constructor to be used if outside of an OSGi environment. Invokes default constructor.
+ *
+ * @param weightedTcProvider
+ * @param serializer
+ * @param tcManager
+ * @param onManager
+ * @param semionManager
+ * @param ruleStore
+ * @param kReSReasoner
+ * @param configuration
+ */
+ public ConsistentRefactorerImpl(WeightedTcProvider weightedTcProvider,
+ Serializer serializer,
+ TcManager tcManager,
+ ONManager onManager,
+ RuleStore ruleStore,
+ Reasoner kReSReasoner,
+ Dictionary<String,Object> configuration) {
+
+ super(weightedTcProvider, serializer, tcManager, onManager, ruleStore, configuration);
+ this.kReSReasoner = kReSReasoner;
+ activate(configuration);
+ }
+
+ @Override
+ @Activate
+ protected void activate(ComponentContext context) throws IOException {
+ // Nothing different to do wrt the superclass (may change if new parameters are given).
+ super.activate(context);
+ }
+
+ @Override
+ public void consistentOntologyRefactoring(IRI refactoredOntologyIRI, IRI datasetURI, IRI recipeIRI) throws RefactoringException,
+ NoSuchRecipeException,
+ InconcistencyException {
+
+ OWLOntology refactoredOntology = null;
+
+ ClerezzaOntologyStorage ontologyStorage = onManager.getOntologyStore();
+
+ Recipe recipe;
+ try {
+ recipe = ruleStore.getRecipe(recipeIRI);
+
+ RuleList kReSRuleList = recipe.getkReSRuleList();
+
+ OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
+
+ String fingerPrint = "";
+ for (Rule kReSRule : kReSRuleList) {
+ String sparql = kReSRule.toSPARQL();
+
+ OWLOntology refactoredDataSet = ontologyStorage
+ .sparqlConstruct(sparql, datasetURI.toString());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ ontologyManager.saveOntology(refactoredDataSet, new RDFXMLOntologyFormat(), out);
+ if (refactoredOntologyIRI == null) {
+ ByteArrayOutputStream fpOut = new ByteArrayOutputStream();
+ fingerPrint += URIGenerator.createID("", fpOut.toByteArray());
+ }
+
+ } catch (OWLOntologyStorageException e) {
+ log.error(
+ "Failed to store refactored ontology in memory. Consistency checking cannot be performed.",
+ e);
+ }
+
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+
+ try {
+ ontologyManager.loadOntologyFromOntologyDocument(in);
+ } catch (OWLOntologyCreationException e) {
+ log.error(
+ "Failed to reload refactored ontology. Consistency checking cannot be performed.", e);
+ }
+
+ }
+
+ if (refactoredOntologyIRI == null) {
+ refactoredOntologyIRI = IRI.create(URIGenerator.createID("urn://", fingerPrint.getBytes()));
+ }
+ OWLOntologyMerger merger = new OWLOntologyMerger(ontologyManager);
+
+ try {
+
+ refactoredOntology = merger.createMergedOntology(ontologyManager, refactoredOntologyIRI);
+
+ if (!kReSReasoner.consistencyCheck(kReSReasoner.getReasoner(refactoredOntology))) {
+ throw new InconcistencyException(
+ "Semion Refactorer : the refactored data set seems to be inconsistent");
+ } else {
+ ontologyStorage.store(refactoredOntology);
+ }
+ } catch (OWLOntologyCreationException e) {
+ log.error("Failed to merge refactored ontology. Consistency checking cannot be performed.", e);
+ }
+
+ } catch (NoSuchRecipeException e1) {
+ log.error("SemionRefactorer : No Such recipe in the KReS Rule Store", e1);
+ throw e1;
+ }
+
+ if (refactoredOntology == null) {
+ throw new RefactoringException();
+ }
+
+ }
+
+ @Override
+ public OWLOntology consistentOntologyRefactoring(OWLOntology inputOntology, IRI recipeIRI) throws RefactoringException,
+ NoSuchRecipeException,
+ InconcistencyException {
+
+ OWLOntology refactoredOntology = null;
+
+ JenaToOwlConvert jenaToOwlConvert = new JenaToOwlConvert();
+
+ OntModel ontModel = jenaToOwlConvert.ModelOwlToJenaConvert(inputOntology, "RDF/XML");
+
+ Recipe recipe;
+ try {
+ recipe = ruleStore.getRecipe(recipeIRI);
+
+ RuleList kReSRuleList = recipe.getkReSRuleList();
+
+ OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
+
+ for (Rule kReSRule : kReSRuleList) {
+ String sparql = kReSRule.toSPARQL();
+
+ Query sparqlQuery = QueryFactory.create(sparql);
+ QueryExecution qexec = QueryExecutionFactory.create(sparqlQuery, ontModel);
+ Model refactoredModel = qexec.execConstruct();
+
+ OWLOntology refactoredDataSet = jenaToOwlConvert.ModelJenaToOwlConvert(refactoredModel,
+ "RDF/XML");
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ ontologyManager.saveOntology(refactoredDataSet, new RDFXMLOntologyFormat(), out);
+ } catch (OWLOntologyStorageException e) {
+ log.error(
+ "Failed to store refactored ontology in memory. Consistency checking cannot be performed.",
+ e);
+ }
+
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+
+ try {
+ ontologyManager.loadOntologyFromOntologyDocument(in);
+ } catch (OWLOntologyCreationException e) {
+ log.error(
+ "Failed to reload refactored ontology. Consistency checking cannot be performed.", e);
+ }
+
+ }
+
+ OWLOntologyMerger merger = new OWLOntologyMerger(ontologyManager);
+
+ try {
+ IRI defaultOntologyIRI = IRI.create("http://kres.iksproject.eu/semion/autoGeneratedOntology");
+ refactoredOntology = merger.createMergedOntology(ontologyManager, defaultOntologyIRI);
+
+ if (!kReSReasoner.consistencyCheck(kReSReasoner.getReasoner(refactoredOntology))) {
+ throw new InconcistencyException(
+ "Semion Refactorer : the refactored data set seems to be inconsistent");
+ }
+
+ } catch (OWLOntologyCreationException e) {
+ log.error("Failed to merge refactored ontology. Consistency checking cannot be performed.", e);
+ }
+
+ } catch (NoSuchRecipeException e1) {
+ log.error("SemionRefactorer : No Such recipe in the KReS Rule Store", e1);
+ throw e1;
+ }
+
+ if (refactoredOntology == null) {
+ throw new RefactoringException();
+ } else {
+ return refactoredOntology;
+ }
+ }
+
+ @Override
+ @Deactivate
+ protected void deactivate(ComponentContext context) {
+ super.deactivate(context);
+ // Here we also need to unset the reasoner.
+ this.kReSReasoner = null;
+ }
+
+}
Modified: incubator/stanbol/trunk/kres/reasoners/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/pom.xml?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/pom.xml (original)
+++ incubator/stanbol/trunk/kres/reasoners/web/pom.xml Wed Mar 30 17:02:00 2011
@@ -239,6 +239,12 @@
<version>${stanbol-version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.rules.refactor</artifactId>
+ <version>${stanbol-version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>com.hp.hpl.jena</groupId>
Modified: incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java (original)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java Wed Mar 30 17:02:00 2011
@@ -10,6 +10,8 @@ import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
+import org.apache.stanbol.kres.jersey.processors.ViewProcessorImpl;
+import org.apache.stanbol.reasoners.base.api.ConsistentRefactorer;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
@@ -19,13 +21,11 @@ import org.slf4j.LoggerFactory;
import com.sun.jersey.spi.container.servlet.ServletContainer;
-import org.apache.stanbol.kres.jersey.processors.ViewProcessorImpl;
-
/**
* Jersey-based RESTful endpoint for KReS.
- *
- * This OSGi component serves as a bridge between the OSGi context and the
- * Servlet context available to JAX-RS resources.
+ *
+ * This OSGi component serves as a bridge between the OSGi context and the Servlet context available to JAX-RS
+ * resources.
*
* @author andrea.nuzzolese
*/
@@ -50,41 +50,36 @@ public class JerseyEndpoint {
@Reference
HttpService httpService;
+ @Reference
+ ConsistentRefactorer consistentRefactorer;
+
protected ServletContext servletContext;
- public Dictionary<String, String> getInitParams() {
+ public Dictionary<String,String> getInitParams() {
// pass configuration for Jersey resource
// TODO: make the list of enabled JAX-RS resources and providers
// configurable using an OSGi service
- Dictionary<String, String> initParams = new Hashtable<String, String>();
- initParams.put("javax.ws.rs.Application",
- JerseyEndpointApplication.class.getName());
+ Dictionary<String,String> initParams = new Hashtable<String,String>();
+ initParams.put("javax.ws.rs.Application", JerseyEndpointApplication.class.getName());
// make jersey automatically turn resources into Viewable models and
// hence lookup matching freemarker templates
- initParams.put("com.sun.jersey.config.feature.ImplicitViewables",
- "true");
+ initParams.put("com.sun.jersey.config.feature.ImplicitViewables", "true");
return initParams;
}
- protected void activate(ComponentContext ctx) throws IOException,
- ServletException, NamespaceException {
+ protected void activate(ComponentContext ctx) throws IOException, ServletException, NamespaceException {
// register the JAX-RS resources as a servlet under configurable alias
ServletContainer container = new ServletContainer();
String alias = (String) ctx.getProperties().get(ALIAS_PROPERTY);
- String staticUrlRoot = (String) ctx.getProperties().get(
- STATIC_RESOURCES_URL_ROOT_PROPERTY);
- String staticClasspath = (String) ctx.getProperties().get(
- STATIC_RESOURCES_CLASSPATH_PROPERTY);
- String freemakerTemplates = (String) ctx.getProperties().get(
- FREEMARKER_TEMPLATE_CLASSPATH_PROPERTY);
+ String staticUrlRoot = (String) ctx.getProperties().get(STATIC_RESOURCES_URL_ROOT_PROPERTY);
+ String staticClasspath = (String) ctx.getProperties().get(STATIC_RESOURCES_CLASSPATH_PROPERTY);
+ String freemakerTemplates = (String) ctx.getProperties().get(FREEMARKER_TEMPLATE_CLASSPATH_PROPERTY);
- log.info("Registering servlets with HTTP service "
- + httpService.toString());
+ log.info("Registering servlets with HTTP service " + httpService.toString());
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(
- getClass().getClassLoader());
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
httpService.registerServlet(alias, container, getInitParams(), null);
httpService.registerResources(staticUrlRoot, staticClasspath, null);
@@ -95,13 +90,15 @@ public class JerseyEndpoint {
// forward the main KReS OSGi components to the servlet context so that
// they can be looked up by the JAX-RS resources
servletContext = container.getServletContext();
- servletContext.setAttribute(BundleContext.class.getName(),
- ctx.getBundleContext());
- servletContext.setAttribute(STATIC_RESOURCES_URL_ROOT_PROPERTY,
- staticUrlRoot);
- servletContext.setAttribute(
- ViewProcessorImpl.FREEMARKER_TEMPLATE_PATH_INIT_PARAM,
- freemakerTemplates);
+ servletContext.setAttribute(BundleContext.class.getName(), ctx.getBundleContext());
+
+ // Register components
+ servletContext.setAttribute(ConsistentRefactorer.class.getName(), consistentRefactorer);
+
+ // Register templates
+ servletContext.setAttribute(STATIC_RESOURCES_URL_ROOT_PROPERTY, staticUrlRoot);
+ servletContext
+ .setAttribute(ViewProcessorImpl.FREEMARKER_TEMPLATE_PATH_INIT_PARAM, freemakerTemplates);
log.info("Jersey servlet registered at {}", alias);
}
@@ -113,7 +110,6 @@ public class JerseyEndpoint {
servletContext = null;
}
-
protected void bindHttpService(HttpService httpService) {
this.httpService = httpService;
}
Modified: incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java (original)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java Wed Mar 30 17:02:00 2011
@@ -9,6 +9,10 @@ import org.apache.stanbol.kres.jersey.pr
import org.apache.stanbol.kres.jersey.writers.GraphWriter;
import org.apache.stanbol.kres.jersey.writers.OWLOntologyWriter;
import org.apache.stanbol.kres.jersey.writers.ResultSetWriter;
+import org.apache.stanbol.reasoners.web.resources.Classify;
+import org.apache.stanbol.reasoners.web.resources.ConsistencyCheck;
+import org.apache.stanbol.reasoners.web.resources.ConsistentRefactoring;
+import org.apache.stanbol.reasoners.web.resources.Enrichment;
/**
* Statically define the list of available resources and providers to be used by the KReS JAX-RS Endpoint.
@@ -30,6 +34,7 @@ public class JerseyEndpointApplication e
// Reasoner
classes.add(ConsistencyCheck.class);
+ classes.add(ConsistentRefactoring.class);
classes.add(Classify.class);
classes.add(Enrichment.class);
Copied: incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java (from r1086970, incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java?p2=incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java&p1=incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java&r1=1086970&r2=1087016&rev=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java (original)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Classify.java Wed Mar 30 17:02:00 2011
@@ -3,7 +3,7 @@
* and open the template in the editor.
*/
-package org.apache.stanbol.reasoners.web;
+package org.apache.stanbol.reasoners.web.resources;
import java.io.File;
import java.net.URL;
Copied: incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java (from r1086970, incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java?p2=incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java&p1=incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java&r1=1086970&r2=1087016&rev=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java (original)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistencyCheck.java Wed Mar 30 17:02:00 2011
@@ -1,4 +1,4 @@
-package org.apache.stanbol.reasoners.web;
+package org.apache.stanbol.reasoners.web.resources;
import java.io.File;
import java.net.URL;
Added: incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistentRefactoring.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistentRefactoring.java?rev=1087016&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistentRefactoring.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ConsistentRefactoring.java Wed Mar 30 17:02:00 2011
@@ -0,0 +1,110 @@
+package org.apache.stanbol.reasoners.web.resources;
+
+import static javax.ws.rs.core.Response.Status.*;
+
+import java.io.InputStream;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.stanbol.kres.jersey.format.KRFormat;
+import org.apache.stanbol.reasoners.base.api.ConsistentRefactorer;
+import org.apache.stanbol.reasoners.base.api.InconcistencyException;
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.refactor.api.RefactoringException;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+
+/**
+ * Special refactoring services that employ a DL reasoner for ensuring/checking consistency.
+ *
+ * @author alessandro
+ *
+ */
+@Path("/refactor")
+public class ConsistentRefactoring {
+
+ protected ConsistentRefactorer refactorer;
+
+ public ConsistentRefactoring(@Context ServletContext servletContext) {
+ refactorer = (ConsistentRefactorer) (servletContext
+ .getAttribute(ConsistentRefactorer.class.getName()));
+ if (refactorer == null) {
+ throw new IllegalStateException("SemionRefactorer missing in ServletContext");
+ }
+
+ }
+
+ @GET
+ @Path("/consistent")
+ public Response performConsistentRefactoringCreateGraph(@QueryParam("recipe") String recipe,
+ @QueryParam("input-graph") String inputGraph,
+ @QueryParam("output-graph") String outputGraph) {
+
+ IRI recipeIRI = IRI.create(recipe);
+ IRI inputGraphIRI = IRI.create(inputGraph);
+ IRI outputGraphIRI = IRI.create(outputGraph);
+
+ // Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
+
+ try {
+ refactorer.consistentOntologyRefactoring(outputGraphIRI, inputGraphIRI, recipeIRI);
+ return Response.ok().build();
+ } catch (RefactoringException e) {
+ return Response.status(INTERNAL_SERVER_ERROR).build();
+ } catch (NoSuchRecipeException e) {
+ return Response.status(204).build();
+ } catch (InconcistencyException e) {
+ return Response.status(415).build();
+ }
+
+ }
+
+ @POST
+ @Path("/consistent")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces({KRFormat.TURTLE, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL, KRFormat.RDF_XML,
+ KRFormat.OWL_XML, KRFormat.RDF_JSON})
+ public Response consistentRefactoringOfNewGraph(@FormParam("recipe") String recipe,
+ @FormParam("input") InputStream input) {
+
+ IRI recipeIRI = IRI.create(recipe);
+
+ // Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
+
+ OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
+ OWLOntology inputOntology;
+ try {
+ inputOntology = manager.loadOntologyFromOntologyDocument(input);
+
+ OWLOntology outputOntology;
+ try {
+ outputOntology = refactorer.consistentOntologyRefactoring(inputOntology, recipeIRI);
+ } catch (RefactoringException e) {
+ return Response.status(INTERNAL_SERVER_ERROR).build();
+ } catch (NoSuchRecipeException e) {
+ return Response.status(204).build();
+ } catch (InconcistencyException e) {
+ return Response.status(415).build();
+ }
+
+ return Response.ok(outputOntology).build();
+ } catch (OWLOntologyCreationException e) {
+ return Response.status(NOT_FOUND).build();
+ }
+
+ }
+
+}
Copied: incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java (from r1086970, incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java?p2=incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java&p1=incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java&r1=1086970&r2=1087016&rev=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java (original)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/Enrichment.java Wed Mar 30 17:02:00 2011
@@ -3,7 +3,7 @@
* and open the template in the editor.
*/
-package org.apache.stanbol.reasoners.web;
+package org.apache.stanbol.reasoners.web.resources;
import java.io.File;
import java.net.URL;
Modified: incubator/stanbol/trunk/kres/rules/manager/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/manager/pom.xml?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/manager/pom.xml (original)
+++ incubator/stanbol/trunk/kres/rules/manager/pom.xml Wed Mar 30 17:02:00 2011
@@ -1,19 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -112,19 +108,11 @@
</dependency>
<!-- Stanbol deps -->
- <!--
- <dependency>
- <groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.owlapi</artifactId>
- <version>${stanbol-version}</version>
- <scope>provided</scope>
- </dependency>
- -->
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.ontologymanager.ontonet</artifactId>
<version>${stanbol-version}</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.rules.base</artifactId>
@@ -158,19 +146,19 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.apache.clerezza</groupId>
- <artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
- <version>0.9-incubating-SNAPSHOT</version>
- <type>bundle</type>
- </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
+ <version>0.9-incubating-SNAPSHOT</version>
+ <type>bundle</type>
+ </dependency>
</dependencies>
<repositories>
- <repository>
- <id>stlab-cnr-repo</id>
- <url>http://stlab.istc.cnr.it/software/maven/repo</url>
- </repository>
- </repositories>
+ <repository>
+ <id>stlab-cnr-repo</id>
+ <url>http://stlab.istc.cnr.it/software/maven/repo</url>
+ </repository>
+ </repositories>
</project>
Modified: incubator/stanbol/trunk/kres/rules/refactor/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/refactor/pom.xml?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/refactor/pom.xml (original)
+++ incubator/stanbol/trunk/kres/rules/refactor/pom.xml Wed Mar 30 17:02:00 2011
@@ -88,11 +88,6 @@
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.reasoners.base</artifactId>
- <version>${stanbol-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.rules.base</artifactId>
<version>${stanbol-version}</version>
</dependency>
Modified: incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/api/Refactorer.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/api/Refactorer.java?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/api/Refactorer.java (original)
+++ incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/api/Refactorer.java Wed Mar 30 17:02:00 2011
@@ -2,79 +2,58 @@ package org.apache.stanbol.rules.refacto
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.stanbol.reasoners.base.api.InconcistencyException;
import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
-
/**
- * A SemionReengineer provides methods for performing ontology refactorings.
- * Refactoring are performed using recipes that contain sets of rules that describe the refactoring to do.
- * Rules are expressed using the both the SWRL model and the KReS rules language.
+ * A SemionReengineer provides methods for performing ontology refactorings. Refactoring are performed using
+ * recipes that contain sets of rules that describe the refactoring to do. Rules are expressed using the both
+ * the SWRL model and the KReS rules language.
*
* @author andrea.nuzzolese
- *
+ *
*/
public interface Refactorer {
- /**
- * Fetch the mgraph with the selected uri from the storage.
- *
- * @param uriRef {@link UriRef}
- * @return the {@link MGraph}.
- */
- public MGraph getRefactoredDataSet(UriRef uriRef);
-
- /**
- * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI} is the {@link IRI}
- * of an IKS ontology and the {@code recipe} is the recipe that needs to be applied to ontology in order to perform the refactoring.
- *
- * @param refactoredDataSetURI {@link IRI}
- * @param datasetURI {@link IRI}
- * @param recipeIRI {@link IRI}
- */
- public void ontologyRefactoring(IRI refactoredDataSetURI, IRI datasetURI, IRI recipeIRI) throws RefactoringException, NoSuchRecipeException;
-
-
- /**
- * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI} is the URI
- * of an RDF graph in KReS and the {@code recipe} is the recipe that needs to be applied to RDF graph in order to obtain the refactoring.
- *
- * @param datasetURI {@link UriRef}
- * @param recipe {@link UriRef}
- * @return the refactored {@link MGraph}
- * @throws RefactoringException
- * @throws NoSuchRecipeException
- */
- public OWLOntology ontologyRefactoring(OWLOntology datasetURI, IRI recipeIRI) throws RefactoringException, NoSuchRecipeException;
-
- /**
- * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI} is the {@link IRI}
- * of an IKS ontology and the {@code recipe} is the recipe that needs to be applied to ontology in order to perform the refactoring.
- * After the refactoring a consistency check is invoked on the data set.
- *
- * @param refactoredDataSetURI {@link IRI}
- * @param datasetURI {@link IRI}
- * @param recipeIRI {@link IRI}
- * @throws RefactoringException
- * @throws NoSuchRecipeException
- * @throws InconcistencyException
- */
- public void consistentOntologyRefactoring(IRI refactoredOntologyIRI, IRI datasetURI, IRI recipeIRI) throws RefactoringException, NoSuchRecipeException, InconcistencyException;
-
- /**
- * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI} is the URI
- * of an RDF graph in KReS and the {@code recipe} is the recipe that needs to be applied to RDF graph in order to obtain the refactoring.
- * After the refactoring a consistency check is invoked on the data set.
- *
- * @param datasetURI {@link UriRef}
- * @param recipe {@link UriRef}
- * @return the refactored {@link MGraph}
- * @throws InconcistencyException
- * @throws NoSuchRecipeException
- * @throws RefactoringException
- */
- public OWLOntology consistentOntologyRefactoring(OWLOntology inputOntology, IRI recipeIRI) throws RefactoringException, NoSuchRecipeException, InconcistencyException;
-
+ /**
+ * Fetch the mgraph with the selected uri from the storage.
+ *
+ * @param uriRef
+ * {@link UriRef}
+ * @return the {@link MGraph}.
+ */
+ public MGraph getRefactoredDataSet(UriRef uriRef);
+
+ /**
+ * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI}
+ * is the {@link IRI} of an IKS ontology and the {@code recipe} is the recipe that needs to be applied to
+ * ontology in order to perform the refactoring.
+ *
+ * @param refactoredDataSetURI
+ * {@link IRI}
+ * @param datasetURI
+ * {@link IRI}
+ * @param recipeIRI
+ * {@link IRI}
+ */
+ public void ontologyRefactoring(IRI refactoredDataSetURI, IRI datasetURI, IRI recipeIRI) throws RefactoringException,
+ NoSuchRecipeException;
+
+ /**
+ * The refactoring is perfomed by the {@code Refactorer} by invoking this method. The {@code datasetURI}
+ * is the URI of an RDF graph in KReS and the {@code recipe} is the recipe that needs to be applied to RDF
+ * graph in order to obtain the refactoring.
+ *
+ * @param datasetURI
+ * {@link UriRef}
+ * @param recipe
+ * {@link UriRef}
+ * @return the refactored {@link MGraph}
+ * @throws RefactoringException
+ * @throws NoSuchRecipeException
+ */
+ public OWLOntology ontologyRefactoring(OWLOntology datasetURI, IRI recipeIRI) throws RefactoringException,
+ NoSuchRecipeException;
+
}
Modified: incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/impl/RefactorerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/impl/RefactorerImpl.java?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/impl/RefactorerImpl.java (original)
+++ incubator/stanbol/trunk/kres/rules/refactor/src/main/java/org/apache/stanbol/rules/refactor/impl/RefactorerImpl.java Wed Mar 30 17:02:00 2011
@@ -28,11 +28,11 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.ontonet.api.session.Session;
import org.apache.stanbol.ontologymanager.ontonet.api.session.SessionManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.io.ClerezzaOntologyStorage;
-import org.apache.stanbol.reasoners.base.api.InconcistencyException;
-import org.apache.stanbol.reasoners.base.api.Reasoner;
-import org.apache.stanbol.rules.base.api.Rule;
+import org.apache.stanbol.owlapi.trasformation.JenaToClerezzaConverter;
+import org.apache.stanbol.owlapi.trasformation.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;
import org.apache.stanbol.rules.base.api.RuleStore;
import org.apache.stanbol.rules.base.api.util.RuleList;
import org.apache.stanbol.rules.manager.arqextention.CreatePropertyURIStringFromLabel;
@@ -53,24 +53,20 @@ import org.semanticweb.owlapi.util.OWLOn
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.sparql.function.FunctionRegistry;
import com.hp.hpl.jena.sparql.pfunction.PropertyFunctionRegistry;
import com.hp.hpl.jena.update.UpdateAction;
-import org.apache.stanbol.owlapi.trasformation.JenaToClerezzaConverter;
-import org.apache.stanbol.owlapi.trasformation.JenaToOwlConvert;
-import org.apache.stanbol.owlapi.trasformation.OWLAPIToClerezzaConverter;
-
/**
- * The RefactorerImpl is the concrete implementation of the Refactorer interface defined in the
- * KReS APIs. A SemionRefacter is able to perform ontology refactorings and mappings.
+ * The RefactorerImpl is the concrete implementation of the Refactorer interface defined in the KReS APIs. A
+ * SemionRefacter is able to perform ontology refactorings and mappings.
*
* @author andrea.nuzzolese
*
@@ -114,13 +110,10 @@ public class RefactorerImpl implements R
private OntologyScope scope;
@Reference
- Reasoner kReSReasoner;
+ protected ONManager onManager;
@Reference
- ONManager onManager;
- @Reference
- RuleStore ruleStore;
- // @Reference
- // SemionManager semionManager;
+ protected RuleStore ruleStore;
+
@Reference
protected Serializer serializer;
@Reference
@@ -132,8 +125,8 @@ public class RefactorerImpl implements R
* This default constructor is <b>only</b> intended to be used by the OSGI environment with Service
* Component Runtime support.
* <p>
- * DO NOT USE to manually create instances - the RefactorerImpl instances do need to be configured!
- * YOU NEED TO USE
+ * DO NOT USE to manually create instances - the RefactorerImpl instances do need to be configured! YOU
+ * NEED TO USE
* {@link #RefactorerImpl(WeightedTcProvider, Serializer, TcManager, ONManager, SemionManager, RuleStore, Reasoner, Dictionary)}
* or its overloads, to parse the configuration and then initialise the rule store if running outside a
* OSGI environment.
@@ -155,12 +148,11 @@ public class RefactorerImpl implements R
* @param configuration
*/
public RefactorerImpl(WeightedTcProvider weightedTcProvider,
- Serializer serializer,
- TcManager tcManager,
- ONManager onManager, /* SemionManager semionManager, */
- RuleStore ruleStore,
- Reasoner kReSReasoner,
- Dictionary<String,Object> configuration) {
+ Serializer serializer,
+ TcManager tcManager,
+ ONManager onManager, /* SemionManager semionManager, */
+ RuleStore ruleStore,
+ Dictionary<String,Object> configuration) {
this();
this.weightedTcProvider = weightedTcProvider;
this.serializer = serializer;
@@ -168,7 +160,6 @@ public class RefactorerImpl implements R
this.onManager = onManager;
// this.semionManager = semionManager;
this.ruleStore = ruleStore;
- this.kReSReasoner = kReSReasoner;
activate(configuration);
}
@@ -180,81 +171,13 @@ public class RefactorerImpl implements R
@SuppressWarnings("unchecked")
@Activate
protected void activate(ComponentContext context) throws IOException {
- log.info("in " + RefactorerImpl.class + " activate with context " + context);
+ log.info("in " + getClass() + " activate with context " + context);
if (context == null) {
throw new IllegalStateException("No valid" + ComponentContext.class + " parsed in activate!");
}
activate((Dictionary<String,Object>) context.getProperties());
}
- /*
- * public void consistentOntologyRefactoring(IRI refactoredOntologyIRI, IRI datasetURI, IRI recipeIRI)
- * throws RefactoringException, NoSuchRecipeException, InconcistencyException {
- *
- *
- *
- * OWLOntology refactoredOntology = null;
- *
- * OntologyStorage ontologyStorage = onManager.getOntologyStore();
- *
- * OWLOntology owlOntology = ontologyStorage.load(datasetURI);
- *
- * JenaToOwlConvert jenaToOwlConvert = new JenaToOwlConvert();
- *
- * OntModel ontModel = jenaToOwlConvert.ModelOwlToJenaConvert(owlOntology, "RDF/XML");
- *
- * Recipe recipe; try { recipe = ruleStore.getRecipe(recipeIRI);
- *
- * RuleList kReSRuleList = recipe.getkReSRuleList();
- *
- * OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
- *
- * for(Rule kReSRule : kReSRuleList){ String sparql = kReSRule.toSPARQL();
- *
- * Query sparqlQuery = QueryFactory.create(sparql); QueryExecution qexec =
- * QueryExecutionFactory.create(sparqlQuery, ontModel) ; Model refactoredModel = qexec.execConstruct();
- *
- *
- * OWLOntology refactoredDataSet = jenaToOwlConvert.ModelJenaToOwlConvert(refactoredModel, "RDF/XML");
- *
- * ByteArrayOutputStream out = new ByteArrayOutputStream(); try {
- * ontologyManager.saveOntology(refactoredDataSet, new RDFXMLOntologyFormat(), out); } catch
- * (OWLOntologyStorageException e) { // TODO Auto-generated catch block e.printStackTrace(); }
- *
- * ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- *
- * try { ontologyManager.loadOntologyFromOntologyDocument(in); } catch (OWLOntologyCreationException e) {
- * // TODO Auto-generated catch block e.printStackTrace(); }
- *
- * }
- *
- * OWLOntologyMerger merger = new OWLOntologyMerger(ontologyManager);
- *
- * try { refactoredOntology = merger.createMergedOntology(ontologyManager, refactoredOntologyIRI);
- *
- *
- *
- *
- *
- *
- *
- *
- *
- * if(!kReSReasoner.consistencyCheck(kReSReasoner.getReasoner(refactoredOntology ))){ throw
- * newInconcistencyException( "Semion Refactorer : the refactored data set seems to be inconsistent"); }
- * else{ ontologyStorage.store(refactoredOntology); } } catch (OWLOntologyCreationException e) { // TODO
- * Auto-generated catch block e.printStackTrace(); }
- *
- *
- *
- * } catch (NoSuchRecipeException e1) {
- * log.error("Refactorer : No Such recipe in the KReS Rule Store", e1); throw e1; }
- *
- * if(refactoredOntology == null){ throw new RefactoringException(); }
- *
- * }
- */
-
protected void activate(Dictionary<String,Object> configuration) {
String refactoringSessionID = (String) configuration.get(REFACTORING_SESSION_ID);
if (refactoringSessionID == null) refactoringSessionID = _REFACTORING_SESSION_ID_DEFAULT;
@@ -321,210 +244,18 @@ public class RefactorerImpl implements R
log.info("Activated KReS Semion Refactorer");
}
- @Override
- public void consistentOntologyRefactoring(IRI refactoredOntologyIRI, IRI datasetURI, IRI recipeIRI) throws RefactoringException,
- NoSuchRecipeException,
- InconcistencyException {
-
- OWLOntology refactoredOntology = null;
-
- ClerezzaOntologyStorage ontologyStorage = onManager.getOntologyStore();
-
- Recipe recipe;
- try {
- recipe = ruleStore.getRecipe(recipeIRI);
-
- RuleList kReSRuleList = recipe.getkReSRuleList();
-
- OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
-
- String fingerPrint = "";
- for (Rule kReSRule : kReSRuleList) {
- String sparql = kReSRule.toSPARQL();
-
- OWLOntology refactoredDataSet = ontologyStorage
- .sparqlConstruct(sparql, datasetURI.toString());
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- ontologyManager.saveOntology(refactoredDataSet, new RDFXMLOntologyFormat(), out);
- if (refactoredOntologyIRI == null) {
- ByteArrayOutputStream fpOut = new ByteArrayOutputStream();
- fingerPrint += URIGenerator.createID("", fpOut.toByteArray());
- }
-
- } catch (OWLOntologyStorageException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-
- try {
- ontologyManager.loadOntologyFromOntologyDocument(in);
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- if (refactoredOntologyIRI == null) {
- refactoredOntologyIRI = IRI.create(URIGenerator.createID("urn://", fingerPrint.getBytes()));
- }
- OWLOntologyMerger merger = new OWLOntologyMerger(ontologyManager);
-
- try {
-
- refactoredOntology = merger.createMergedOntology(ontologyManager, refactoredOntologyIRI);
-
- if (!kReSReasoner.consistencyCheck(kReSReasoner.getReasoner(refactoredOntology))) {
- throw new InconcistencyException(
- "Semion Refactorer : the refactored data set seems to be inconsistent");
- } else {
- ontologyStorage.store(refactoredOntology);
- }
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- } catch (NoSuchRecipeException e1) {
- log.error("SemionRefactorer : No Such recipe in the KReS Rule Store", e1);
- throw e1;
- }
-
- if (refactoredOntology == null) {
- throw new RefactoringException();
- }
-
- /*
- * UriRef uriRef = new UriRef(refactoredDataSetURI);
- *
- * MGraph mGraph = weightedTcProvider.createMGraph(datasetURI);
- *
- * Set<IRI> ruleIRIs = kReSRuleManager.getRecipe(recipeIRI);
- *
- * for(IRI ruleIRI : ruleIRIs){ Rule kReSRule = kReSRuleManager.getRule(ruleIRI);
- *
- * String sparql = kReSRule.toSPARQL();
- *
- * Query query; try { query = QueryParser.getInstance().parse(sparql); MGraph dataset =
- * weightedTcProvider.getMGraph(datasetURI); mGraph.addAll((SimpleGraph)
- * tcManager.executeSparqlQuery(query, dataset));
- *
- * } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
- *
- * ByteArrayOutputStream out = new ByteArrayOutputStream();
- *
- * SerializingProvider serializingProvider = new JenaSerializerProvider();
- *
- * serializingProvider.serialize(out, mGraph, SupportedFormat.RDF_XML);
- *
- * ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- *
- * OWLOntologyManager owlOntologyManager = onManager.getOwlCacheManager();
- *
- * OWLOntology owlmodel; try { owlmodel = owlOntologyManager.loadOntologyFromOntologyDocument(in);
- * if(kReSReasoner .consistencyCheck(kReSReasoner.getReasoner(owlmodel))){ return uriRef; } else{
- * throw newInconcistencyException(
- * "Semion Refactorer : the refactored data set seems to be inconsistent" ); } } catch
- * (OWLOntologyCreationException e) { throw new InconcistencyException
- * ("Semion Refactorer : the refactored data set seems to be invalid"); }
- */
-
- }
-
- @Override
- public OWLOntology consistentOntologyRefactoring(OWLOntology inputOntology, IRI recipeIRI) throws RefactoringException,
- NoSuchRecipeException,
- InconcistencyException {
-
- OWLOntology refactoredOntology = null;
-
- JenaToOwlConvert jenaToOwlConvert = new JenaToOwlConvert();
-
- OntModel ontModel = jenaToOwlConvert.ModelOwlToJenaConvert(inputOntology, "RDF/XML");
-
- Recipe recipe;
- try {
- recipe = ruleStore.getRecipe(recipeIRI);
-
- RuleList kReSRuleList = recipe.getkReSRuleList();
-
- OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
-
- for (Rule kReSRule : kReSRuleList) {
- String sparql = kReSRule.toSPARQL();
-
- Query sparqlQuery = QueryFactory.create(sparql);
- QueryExecution qexec = QueryExecutionFactory.create(sparqlQuery, ontModel);
- Model refactoredModel = qexec.execConstruct();
-
- OWLOntology refactoredDataSet = jenaToOwlConvert.ModelJenaToOwlConvert(refactoredModel,
- "RDF/XML");
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- ontologyManager.saveOntology(refactoredDataSet, new RDFXMLOntologyFormat(), out);
- } catch (OWLOntologyStorageException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-
- try {
- ontologyManager.loadOntologyFromOntologyDocument(in);
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- OWLOntologyMerger merger = new OWLOntologyMerger(ontologyManager);
-
- try {
- IRI defaultOntologyIRI = IRI.create("http://kres.iksproject.eu/semion/autoGeneratedOntology");
- refactoredOntology = merger.createMergedOntology(ontologyManager, defaultOntologyIRI);
-
- if (!kReSReasoner.consistencyCheck(kReSReasoner.getReasoner(refactoredOntology))) {
- throw new InconcistencyException(
- "Semion Refactorer : the refactored data set seems to be inconsistent");
- }
-
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- } catch (NoSuchRecipeException e1) {
- log.error("SemionRefactorer : No Such recipe in the KReS Rule Store", e1);
- throw e1;
- }
-
- if (refactoredOntology == null) {
- throw new RefactoringException();
- } else {
- return refactoredOntology;
- }
- }
-
@Deactivate
protected void deactivate(ComponentContext context) {
- log.info("in " + RefactorerImpl.class + " deactivate with context " + context);
+ log.info("in " + getClass() + " deactivate with context " + context);
SessionManager kReSSessionManager = onManager.getSessionManager();
kReSSessionManager.destroySession(kReSSessionID);
// semionManager.unregisterRefactorer();
-
this.weightedTcProvider = null;
this.serializer = null;
this.tcManager = null;
this.onManager = null;
this.ruleStore = null;
- this.kReSReasoner = null;
}
@Override
Modified: incubator/stanbol/trunk/kres/rules/refactor/src/test/java/org/apache/stanbol/rules/refactor/RefactoringTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/refactor/src/test/java/org/apache/stanbol/rules/refactor/RefactoringTest.java?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/refactor/src/test/java/org/apache/stanbol/rules/refactor/RefactoringTest.java (original)
+++ incubator/stanbol/trunk/kres/rules/refactor/src/test/java/org/apache/stanbol/rules/refactor/RefactoringTest.java Wed Mar 30 17:02:00 2011
@@ -15,13 +15,12 @@ import org.apache.clerezza.rdf.jena.spar
import org.apache.clerezza.rdf.simple.storage.SimpleTcProvider;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
-import org.apache.stanbol.reasoners.base.impl.ReasonerImpl;
-import org.apache.stanbol.rules.base.api.Rule;
import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
import org.apache.stanbol.rules.base.api.Recipe;
+import org.apache.stanbol.rules.base.api.Rule;
import org.apache.stanbol.rules.base.api.RuleStore;
-import org.apache.stanbol.rules.base.api.util.RuleList;
import org.apache.stanbol.rules.base.api.util.RecipeList;
+import org.apache.stanbol.rules.base.api.util.RuleList;
import org.apache.stanbol.rules.manager.changes.RecipeImpl;
import org.apache.stanbol.rules.manager.parse.RuleParserImpl;
import org.apache.stanbol.rules.refactor.api.Refactorer;
@@ -40,238 +39,206 @@ import org.semanticweb.owlapi.model.OWLO
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
-
-
public class RefactoringTest {
- static RuleStore ruleStore;
- static OWLOntology ontology;
- static IRI recipeIRI;
-
- @BeforeClass
- public static void setup() {
-
- recipeIRI = IRI
- .create("http://kres.iks-project.eu/ontology/meta/rmi_config.owl#MyTestRecipe");
-
- InputStream ontologyStream = RefactoringTest.class
- .getResourceAsStream("/META-INF/test/testKReSOnt.owl");
- InputStream recipeStream = RefactoringTest.class
- .getResourceAsStream("/META-INF/test/rmi.owl");
-
- try {
- final OWLOntology recipeModel = OWLManager
- .createOWLOntologyManager()
- .loadOntologyFromOntologyDocument(recipeStream);
- ontology = OWLManager.createOWLOntologyManager()
- .loadOntologyFromOntologyDocument(ontologyStream);
-
- ruleStore = new RuleStore() {
-
- @Override
- public void setStore(OWLOntology owl) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void saveOntology() throws OWLOntologyStorageException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public RecipeList listRecipes() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<IRI> listIRIRecipes() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getRuleStoreNamespace() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Recipe getRecipe(IRI recipeIRI)
- throws NoSuchRecipeException {
- Recipe recipe = null;
-
- if (recipeIRI != null) {
- OWLDataFactory factory = OWLManager.getOWLDataFactory();
- OWLIndividual recipeIndividual = factory
- .getOWLNamedIndividual(recipeIRI);
- if (recipeIndividual != null) {
- String ruleNS = "http://kres.iks-project.eu/ontology/meta/rmi.owl#";
-
- /**
- * First get the recipe description in the
- * rule/recipe ontology.
- */
- OWLDataProperty hasDescription = factory
- .getOWLDataProperty(IRI.create(ruleNS
- + "hasDescription"));
-
- String recipeDescription = null;
-
- Set<OWLLiteral> descriptions = recipeIndividual
- .getDataPropertyValues(hasDescription,
- recipeModel);
- for (OWLLiteral description : descriptions) {
- recipeDescription = description.getLiteral();
- }
-
- /**
- * Then retrieve the rules associated to the recipe
- * in the rule store.
- */
- OWLObjectProperty objectProperty = factory
- .getOWLObjectProperty(IRI.create(ruleNS
- + "hasRule"));
- Set<OWLIndividual> rules = recipeIndividual
- .getObjectPropertyValues(objectProperty,
- recipeModel);
-
- String kReSRulesInKReSSyntax = "";
-
- /**
- * Fetch the rule content expressed as a literal in
- * Rule Syntax.
- */
- OWLDataProperty hasBodyAndHead = factory
- .getOWLDataProperty(IRI.create(ruleNS
- + "hasBodyAndHead"));
- for (OWLIndividual rule : rules) {
-
- Set<OWLLiteral> kReSRuleLiterals = rule
- .getDataPropertyValues(hasBodyAndHead,
- recipeModel);
-
- for (OWLLiteral kReSRuleLiteral : kReSRuleLiterals) {
- String ruleTmp = kReSRuleLiteral
- .getLiteral().replace("<", "<");
- ruleTmp = ruleTmp.replace(">", ">");
- kReSRulesInKReSSyntax += ruleTmp
- + System
- .getProperty("line.separator");
- }
- }
-
- /**
- * Create the Recipe object.
- */
-
- RuleList ruleList = RuleParserImpl.parse(
- kReSRulesInKReSSyntax).getkReSRuleList();
- recipe = new RecipeImpl(recipeIRI,
- recipeDescription, ruleList);
- } else {
- throw new NoSuchRecipeException(recipeIRI);
- }
- }
-
- return recipe;
- }
-
- @Override
- public OWLOntology getOntology() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getFilePath() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean addRecipe(IRI recipeIRI, String recipeDescription) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public Recipe addRuleToRecipe(String recipeID,
- String kReSRuleInKReSSyntax)
- throws NoSuchRecipeException {
- return null;
-
- }
-
- @Override
- public Recipe addRuleToRecipe(Recipe recipe,
- String kReSRuleInKReSSyntax) {
- return null;
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void createRecipe(String recipeID,
- String rulesInKReSSyntax) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean removeRecipe(Recipe recipe) {
- throw new UnsupportedOperationException(
- "Not supported yet.");
- }
-
- @Override
- public boolean removeRecipe(IRI recipeIRI) {
- throw new UnsupportedOperationException(
- "Not supported yet.");
- }
-
- @Override
- public boolean removeRule(Rule rule) {
- throw new UnsupportedOperationException(
- "Not supported yet.");
- }
- };
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Test
- public void refactoringTest() throws Exception {
- Dictionary<String, Object> emptyConfig = new Hashtable<String, Object>();
-
-
- class SpecialTcManager extends TcManager {
- public SpecialTcManager(QueryEngine qe, WeightedTcProvider wtcp) {
- super();
- bindQueryEngine(qe);
- bindWeightedTcProvider(wtcp);
- }
- }
-
- QueryEngine qe = new JenaSparqlEngine();
- WeightedTcProvider wtcp = new SimpleTcProvider();
- TcManager tcm = new SpecialTcManager(qe, wtcp);
-
- ONManager onm = new ONManagerImpl(tcm,wtcp, emptyConfig);
- Refactorer refactorer = new RefactorerImpl(null,
- new Serializer(), tcm, onm,
- ruleStore, new ReasonerImpl(emptyConfig), emptyConfig);
- try {
- refactorer.ontologyRefactoring(ontology, recipeIRI);
- } catch (RefactoringException e) {
- fail("Error while refactoring.");
- } catch (NoSuchRecipeException e) {
- fail("Error while refactoring: no such recipe");
- }
- }
+ static RuleStore ruleStore;
+ static OWLOntology ontology;
+ static IRI recipeIRI;
+
+ @BeforeClass
+ public static void setup() {
+
+ recipeIRI = IRI.create("http://kres.iks-project.eu/ontology/meta/rmi_config.owl#MyTestRecipe");
+
+ InputStream ontologyStream = RefactoringTest.class
+ .getResourceAsStream("/META-INF/test/testKReSOnt.owl");
+ InputStream recipeStream = RefactoringTest.class.getResourceAsStream("/META-INF/test/rmi.owl");
+
+ try {
+ final OWLOntology recipeModel = OWLManager.createOWLOntologyManager()
+ .loadOntologyFromOntologyDocument(recipeStream);
+ ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(ontologyStream);
+
+ ruleStore = new RuleStore() {
+
+ @Override
+ public void setStore(OWLOntology owl) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void saveOntology() throws OWLOntologyStorageException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public RecipeList listRecipes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Set<IRI> listIRIRecipes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getRuleStoreNamespace() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Recipe getRecipe(IRI recipeIRI) throws NoSuchRecipeException {
+ Recipe recipe = null;
+
+ if (recipeIRI != null) {
+ OWLDataFactory factory = OWLManager.getOWLDataFactory();
+ OWLIndividual recipeIndividual = factory.getOWLNamedIndividual(recipeIRI);
+ if (recipeIndividual != null) {
+ String ruleNS = "http://kres.iks-project.eu/ontology/meta/rmi.owl#";
+
+ /**
+ * First get the recipe description in the rule/recipe ontology.
+ */
+ OWLDataProperty hasDescription = factory.getOWLDataProperty(IRI
+ .create(ruleNS + "hasDescription"));
+
+ String recipeDescription = null;
+
+ Set<OWLLiteral> descriptions = recipeIndividual.getDataPropertyValues(
+ hasDescription, recipeModel);
+ for (OWLLiteral description : descriptions) {
+ recipeDescription = description.getLiteral();
+ }
+
+ /**
+ * Then retrieve the rules associated to the recipe in the rule store.
+ */
+ OWLObjectProperty objectProperty = factory.getOWLObjectProperty(IRI
+ .create(ruleNS + "hasRule"));
+ Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(
+ objectProperty, recipeModel);
+
+ String kReSRulesInKReSSyntax = "";
+
+ /**
+ * Fetch the rule content expressed as a literal in Rule Syntax.
+ */
+ OWLDataProperty hasBodyAndHead = factory.getOWLDataProperty(IRI
+ .create(ruleNS + "hasBodyAndHead"));
+ for (OWLIndividual rule : rules) {
+
+ Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(hasBodyAndHead,
+ recipeModel);
+
+ for (OWLLiteral kReSRuleLiteral : kReSRuleLiterals) {
+ String ruleTmp = kReSRuleLiteral.getLiteral().replace("<", "<");
+ ruleTmp = ruleTmp.replace(">", ">");
+ kReSRulesInKReSSyntax += ruleTmp + System.getProperty("line.separator");
+ }
+ }
+
+ /**
+ * Create the Recipe object.
+ */
+
+ RuleList ruleList = RuleParserImpl.parse(kReSRulesInKReSSyntax).getkReSRuleList();
+ recipe = new RecipeImpl(recipeIRI, recipeDescription, ruleList);
+ } else {
+ throw new NoSuchRecipeException(recipeIRI);
+ }
+ }
+
+ return recipe;
+ }
+
+ @Override
+ public OWLOntology getOntology() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getFilePath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean addRecipe(IRI recipeIRI, String recipeDescription) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Recipe addRuleToRecipe(String recipeID, String kReSRuleInKReSSyntax) throws NoSuchRecipeException {
+ return null;
+
+ }
+
+ @Override
+ public Recipe addRuleToRecipe(Recipe recipe, String kReSRuleInKReSSyntax) {
+ return null;
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void createRecipe(String recipeID, String rulesInKReSSyntax) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean removeRecipe(Recipe recipe) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean removeRecipe(IRI recipeIRI) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean removeRule(Rule rule) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+ } catch (OWLOntologyCreationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void refactoringTest() throws Exception {
+ Dictionary<String,Object> emptyConfig = new Hashtable<String,Object>();
+
+ class SpecialTcManager extends TcManager {
+ public SpecialTcManager(QueryEngine qe, WeightedTcProvider wtcp) {
+ super();
+ bindQueryEngine(qe);
+ bindWeightedTcProvider(wtcp);
+ }
+ }
+
+ QueryEngine qe = new JenaSparqlEngine();
+ WeightedTcProvider wtcp = new SimpleTcProvider();
+ TcManager tcm = new SpecialTcManager(qe, wtcp);
+
+ ONManager onm = new ONManagerImpl(tcm, wtcp, emptyConfig);
+ Refactorer refactorer = new RefactorerImpl(null, new Serializer(), tcm, onm, ruleStore, emptyConfig);
+ try {
+ refactorer.ontologyRefactoring(ontology, recipeIRI);
+ } catch (RefactoringException e) {
+ fail("Error while refactoring.");
+ } catch (NoSuchRecipeException e) {
+ fail("Error while refactoring: no such recipe");
+ }
+ }
}
Modified: incubator/stanbol/trunk/kres/rules/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/rules/web/pom.xml?rev=1087016&r1=1087015&r2=1087016&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/rules/web/pom.xml (original)
+++ incubator/stanbol/trunk/kres/rules/web/pom.xml Wed Mar 30 17:02:00 2011
@@ -223,11 +223,6 @@
</dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.reasoners.base</artifactId>
- <version>${stanbol-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.rules.manager</artifactId>
<version>${stanbol-version}</version>
</dependency>