You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by co...@apache.org on 2011/03/20 17:13:09 UTC

svn commit: r1083484 [1/9] - in /incubator/stanbol/trunk/kres/reasoners/web: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/stanbol/ src/main/java/org/apache/stanbol/reasoners/ src/main/java/org/a...

Author: concelvio
Date: Sun Mar 20 16:13:06 2011
New Revision: 1083484

URL: http://svn.apache.org/viewvc?rev=1083484&view=rev
Log:
STANBOL-39:
1) Created the module rules/web and adding required pom.xml and src directory
2) Moved rclasses  Classify.java, ConsistencyCheck.java, Enrichment.java from eu.iksproject.kres.jersey to org.apache.stanbol.reasoners.web (module reasonerss/web)
3) The tests are commented because they need othe service to be done. So they will be integration test.
4) Added JerseyEndpoint.java, JerseyEndpointApplication.java and JettyServer.java

Added:
    incubator/stanbol/trunk/kres/reasoners/web/   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/pom.xml
    incubator/stanbol/trunk/kres/reasoners/web/src/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/java/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/
    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/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/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JettyServer.java
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/add.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/addRule.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/ajax-loader.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/anonymous_48.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/black_gear_128.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/black_gear_16.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/caos_puzzle.jpg   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/compass_48.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/compass_map_48.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/configure.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/delete.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/download.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/download_rdf.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/external.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/favicon-black.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/favicon-sw.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/favicon.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/fise_logo_cropped.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/fise_logo_white.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/fise_logo_white_small.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/foldable_folded.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/foldable_unfolded.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/header_bg.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/iks_project_logo.jpg   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/kresLogo.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/kresLogoExtended.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/loading.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/next.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/organization_48.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/previous.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/rdf.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/rdf_flyer.64.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/rdf_flyer_16.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/rdf_flyer_24.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/rules.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/stlabLogo.jpg   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/stlabLogo.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/sw-cube.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/user_48.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/user_group_48.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/images/wikipedia_w_16.png   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/jit-yc.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/jit.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/jquery-1.4.2.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/jquery.rdfquery.core-1.0.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/json2.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/jsonToTurtle.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/kres.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/prettify/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/prettify/kres.css
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/prettify/prettify.css
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/prettify/prettify.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/scout.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/scripts/tinybox.js
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/fise.css
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/date-bottom.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/date-top.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/footer.jpg   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/frontphoto.jpg   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/header.jpg   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/images/wrapbg.gif   (with props)
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/kres.css
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/static/style/kress.css
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/ajax/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/ajax/contentitem.ftl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/imports/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/imports/common.ftl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/imports/contentitem.ftl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/imports/entities.ftl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/imports/kres.ftl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/META-INF/templates/imports/sparql.ftl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/RuleOntology/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/RuleOntology/OffLineKReSOntologyRules.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/RuleOntology/TestKReSOntologyRules.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/RuleOntology/TestRuleFileExample.txt
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/RuleOntology/rmi_config.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/TestFile/
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/TestFile/OnlyRuledProvaParent.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/TestFile/OnlyRuledProvaParentRDFXML.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/TestFile/ProvaParent.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/TestFile/RuledProvaParent.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/main/resources/TestFile/RuledProvaParentRDFXML.owl
    incubator/stanbol/trunk/kres/reasoners/web/src/test/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/stanbol/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/stanbol/reasoners/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/stanbol/reasoners/web/
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/stanbol/reasoners/web/ClassifyTest.java
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/stanbol/reasoners/web/ConsistencyCheckTest.java
    incubator/stanbol/trunk/kres/reasoners/web/src/test/java/org/apache/stanbol/reasoners/web/EnrichmentTest.java

Propchange: incubator/stanbol/trunk/kres/reasoners/web/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Mar 20 16:13:06 2011
@@ -0,0 +1 @@
+target

Added: incubator/stanbol/trunk/kres/reasoners/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/reasoners/web/pom.xml?rev=1083484&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/pom.xml (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/pom.xml Sun Mar 20 16:13:06 2011
@@ -0,0 +1,363 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.stanbol</groupId>
+		<artifactId>stanbol-parent</artifactId>
+		<version>0.9-SNAPSHOT</version>
+		<relativePath>../../parent</relativePath>
+	</parent>
+
+	<groupId>org.apache.stanbol</groupId>
+	<artifactId>org.apache.stanbol.reasoners.web</artifactId>
+	<version>${stanbol-version}</version>
+	<packaging>bundle</packaging>
+
+	<name>Apache Stanbol Reasoner Web</name>
+	<description>Set of rest services to deal with reasoners</description>
+
+	<properties>
+		<kres-version>0.7</kres-version>
+	</properties>
+
+	<dependencies>
+
+		<!-- dependencies on other IKS modules -->
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.core</artifactId>
+			<version>0.12-incubating-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.rdfjson</artifactId>
+			<version>0.3-incubating-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.jaxrs.rdf.providers</artifactId>
+			<version>0.13-incubating-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
+			<version>0.9-incubating-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.rdfjson</artifactId>
+			<version>0.3-incubating-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- specific deps for this project -->
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-server</artifactId>
+			<version>${jersey-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-core</artifactId>
+			<version>${jersey-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-json</artifactId>
+			<version>${jersey-version}</version>
+			<exclusions>
+				<!-- jaxb is now part of java 6 -->
+				<exclusion>
+					<groupId>com.sun.xml.bind</groupId>
+					<artifactId>jaxb-api</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>com.sun.xml.bind</groupId>
+					<artifactId>jaxb-impl</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<!--
+			<dependency> <groupId>com.sun.jersey.contribs</groupId>
+			<artifactId>jersey-multipart</artifactId> <version>1.4</version>
+			</dependency>
+		-->
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>2.4</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>freemarker</groupId>
+			<artifactId>freemarker</artifactId>
+			<version>2.3.9</version>
+		</dependency>
+		<!-- indirect dependency for freemarker -->
+		<dependency>
+			<groupId>org.codehaus.jettison</groupId>
+			<artifactId>jettison</artifactId>
+			<version>1.2</version>
+		</dependency>
+
+		<!-- servlet container, most useful for the tests -->
+		<dependency>
+			<groupId>org.mortbay.jetty</groupId>
+			<artifactId>jetty</artifactId>
+			<version>6.1.22</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- generic tax -->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>1.4</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.4</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- OSGi tax -->
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<version>4.1.0</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<version>4.1.0</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.scr.annotations</artifactId>
+			<version>1.2.0</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- for tests -->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-simple</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.7</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-all</artifactId>
+			<version>1.6</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-client</artifactId>
+			<version>${jersey-version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.ops4j.pax.exam</groupId>
+			<artifactId>pax-exam</artifactId>
+			<version>${pax-exam-version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.ops4j.pax.exam</groupId>
+			<artifactId>pax-exam-junit</artifactId>
+			<version>${pax-exam-version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.ops4j.pax.exam</groupId>
+			<artifactId>pax-exam-container-default</artifactId>
+			<version>${pax-exam-version}</version>
+			<scope>test</scope>
+		</dependency>
+
+
+		<!-- KReS -->
+		<!--
+			<dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.api</artifactId>
+			<version>${kres-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>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.ontologymanager.store</artifactId>
+			<version>${stanbol-version}</version>
+		</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>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.reengineer.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>
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.rules.refactor</artifactId>
+			<version>${stanbol-version}</version>
+		</dependency>
+                <dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.kres.jersey</artifactId>
+			<version>${stanbol-version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!--
+			<dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.manager</artifactId>
+			<version>${kres-version}</version> <scope>provided</scope>
+			</dependency> <dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.rules</artifactId>
+			<version>${kres-version}</version> <scope>provided</scope>
+			</dependency> <dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.semion.manager</artifactId>
+			<version>${kres-version}</version> <scope>provided</scope>
+			</dependency> <dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.semion.refactorer</artifactId>
+			<version>${kres-version}</version> <scope>provided</scope>
+			</dependency>
+		-->
+		<dependency>
+			<groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.shared.dependency.owlapi</artifactId>
+			<version>${kres-version}</version>
+			<scope>provided</scope>
+		</dependency>
+		<!--
+			<dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.reasoners</artifactId>
+			<version>${kres-version}</version> <scope>provided</scope>
+			</dependency> <dependency> <groupId>eu.iksproject</groupId>
+			<artifactId>eu.iksproject.kres.storage.provider</artifactId>
+			<version>${kres-version}</version> <scope>provided</scope>
+			</dependency>
+		-->
+		<dependency>
+			<groupId>com.hp.hpl.jena</groupId>
+			<artifactId>jena</artifactId>
+			<version>2.6.2</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+
+
+
+
+
+	<repositories>
+		<!-- needed for jersey -->
+		<repository>
+			<id>maven2-repository.dev.java.net</id>
+			<name>Java.net Repository for Maven</name>
+			<url>http://download.java.net/maven/2/</url>
+		</repository>
+		<repository>
+			<id>repository-codehaus</id>
+			<name>Codehaus maven repository</name>
+			<url>http://repository.codehaus.org</url>
+		</repository>
+
+		<!-- needed for clerezza SNAPSHOT only -->
+		<repository>
+			<id>apache repository - snapshot repo</id>
+			<name>apache repository</name>
+			<url>https://repository.apache.org/content/repositories/snapshots</url>
+		</repository>
+	</repositories>
+
+	<build>
+		<!-- make it an OSGi bundle -->
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Export-Package>
+							org.apache.stanbol.reasoners.web.*;version=${stanbol-version}
+            			</Export-Package>
+						<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=jersey-json|jettison|jackson-core-asl</Embed-Dependency>
+						<Embed-Transitive>true</Embed-Transitive>
+						<Import-Package>
+							org.semanticweb.owlapi.*,
+							!javax.servlet.jsp.*,
+							!org.apache.tools.*,
+							!org.mortbay.*,
+							!org.apache.xpath.*,
+							!org.jdom.*,
+							!org.jaxen.*,
+							!org.apache.xml.*,
+							!org.mozilla.javascript.*,
+							!org.python.*,
+							!org.dom4j.*,
+							!org.apache.log.*,
+							*
+            			</Import-Package>
+						<Embed-Dependency>freemarker</Embed-Dependency>
+						<_nouses>true</_nouses>
+					</instructions>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-scr-plugin</artifactId>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.0.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>
\ No newline at end of file

Added: 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/Classify.java?rev=1083484&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Classify.java Sun Mar 20 16:13:06 2011
@@ -0,0 +1,470 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.apache.stanbol.reasoners.web;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.KReSONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.ScopeRegistry;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ontology.OntologyStorage;
+import org.apache.stanbol.reasoners.base.commands.KReSCreateReasoner;
+import org.apache.stanbol.reasoners.base.commands.KReSRunReasoner;
+import org.apache.stanbol.reasoners.base.commands.KReSRunRules;
+import org.apache.stanbol.rules.base.api.KReSRule;
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.base.api.util.KReSRuleList;
+import org.apache.stanbol.rules.manager.KReSKB;
+import org.apache.stanbol.rules.manager.changes.KReSRuleStore;
+import org.apache.stanbol.rules.manager.parse.KReSRuleParser;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLDataProperty;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLLiteral;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+import org.apache.stanbol.kres.jersey.format.KReSFormat;
+
+/**
+ *
+ * @author elvio
+ */
+@Path("/classify")
+public class Classify {
+
+     private RuleStore kresRuleStore;
+     private OWLOntology inputowl;
+     private OWLOntology scopeowl;
+
+	protected KReSONManager onm;
+	protected OntologyStorage storage;
+
+	private Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * To get the KReSRuleStore where are stored the rules and the recipes
+     *
+	 * @param servletContext
+	 *            {To get the context where the REST service is running.}
+     */
+    public Classify(@Context ServletContext servletContext){
+		this.kresRuleStore = (RuleStore) servletContext
+				.getAttribute(RuleStore.class.getName());
+		this.onm = (KReSONManager) servletContext
+				.getAttribute(KReSONManager.class.getName());
+//      this.storage = (OntologyStorage) servletContext
+//      .getAttribute(OntologyStorage.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (onm == null) {
+    log
+            .warn("No KReSONManager in servlet context. Instantiating manually...");
+    onm = new ONManager(new TcManager(), null,
+            new Hashtable<String, Object>());
+}
+this.storage = onm.getOntologyStore();
+if (storage == null) {
+    log.warn("No OntologyStorage in servlet context. Instantiating manually...");
+    storage = new OntologyStorage(new TcManager(),null);
+}
+       if (kresRuleStore == null) {
+			log
+					.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+			this.kresRuleStore = new KReSRuleStore(onm,
+					new Hashtable<String, Object>(), "");
+			log
+					.debug("PATH TO OWL FILE LOADED: "
+							+ kresRuleStore.getFilePath());
+        }
+    }
+
+     /**
+     * To trasform a sequence of rules to a Jena Model
+	 * 
+	 * @param owl
+	 *            {OWLOntology object contains a single recipe}
+     * @return {A jena rdf model contains the SWRL rule.}
+     */
+	private Model fromRecipeToModel(OWLOntology owl)
+			throws NoSuchRecipeException {
+
+		// FIXME: why the heck is this method re-instantiating a rule store?!?
+		RuleStore store = new KReSRuleStore(onm,
+				new Hashtable<String, Object>(), owl);
+        Model jenamodel = ModelFactory.createDefaultModel();
+
+		OWLDataFactory factory = owl.getOWLOntologyManager()
+				.getOWLDataFactory();
+		OWLClass ontocls = factory
+				.getOWLClass(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe"));
+        Set<OWLClassAssertionAxiom> cls = owl.getClassAssertionAxioms(ontocls);
+        Iterator<OWLClassAssertionAxiom> iter = cls.iterator();
+        IRI recipeiri = IRI.create(iter.next().getIndividual().toStringID());
+
+		OWLIndividual recipeIndividual = factory
+				.getOWLNamedIndividual(recipeiri);
+
+		OWLObjectProperty objectProperty = factory
+				.getOWLObjectProperty(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
+		Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(
+				objectProperty, store.getOntology());
+        String kReSRules = "";
+        for(OWLIndividual rule : rules){
+			OWLDataProperty hasBodyAndHead = factory
+					.getOWLDataProperty(IRI
+							.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
+			Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(
+					hasBodyAndHead, store.getOntology());
+
+			for(OWLLiteral kReSRuleLiteral : kReSRuleLiterals){
+				kReSRules += kReSRuleLiteral.getLiteral()
+						+ System.getProperty("line.separator");
+			}
+		}
+
+	//"ProvaParent = <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#> . rule1[ has(ProvaParent:hasParent, ?x, ?y) . has(ProvaParent:hasBrother, ?y, ?z) -> has(ProvaParent:hasUncle, ?x, ?z) ]");
+        KReSKB kReSKB = KReSRuleParser.parse(kReSRules);
+        KReSRuleList listrules = kReSKB.getkReSRuleList();
+        Iterator<KReSRule> iterule = listrules.iterator();
+        while(iterule.hasNext()){
+            KReSRule singlerule = iterule.next();
+            Resource resource = singlerule.toSWRL(jenamodel);
+        }
+
+        return jenamodel;
+
+    }
+
+   /**
+	 * To run a classifying reasoner on a RDF input File or IRI on the base of a
+	 * Scope (or an ontology) and a recipe. Can be used either HermiT or an
+	 * owl-link server reasoner end-point
+	 * 
+	 * @param session
+	 *            {A string contains the session IRI used to classify the
+	 *            input.}
+	 * @param scope
+	 *            {A string contains either a specific scope's ontology or the
+	 *            scope IRI used to classify the input.}
+	 * @param recipe
+	 *            {A string contains the recipe IRI from the service
+	 *            http://localhost:port/kres/recipe/recipeName.}
+     * @Param file {A file in a RDF (eihter RDF/XML or owl) to be classified.}
+	 * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or
+	 *        OWL) to be classified.}
+	 * @Param owllink_endpoint {A string contains the ressoner server end-point
+	 *        URL.}
+     * @return Return: <br/>
+     *          200 The ontology is retrieved, containing only class axioms <br/>
+     *          400 To run the session is needed the scope <br/>
+     *          404 No data is retrieved <br/>
+     *          409 Too much RDF inputs <br/>
+     *          500 Some error occurred
+     */
+    @POST
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+	@Produces(value = { KReSFormat.RDF_XML, KReSFormat.TURTLE,
+			KReSFormat.OWL_XML })
+	public Response ontologyClassify(
+			@FormParam(value = "session") String session,
+			@FormParam(value = "scope") String scope,
+			@FormParam(value = "recipe") String recipe,
+			@FormParam(value = "input-graph") String input_graph,
+			@FormParam(value = "file") File file,
+			@FormParam(value = "owllink-endpoint") String owllink_endpoint) {
+       
+      try{
+      
+      if((session!=null)&&(scope==null)){
+           System.err.println("ERROR: Cannot load session without scope.");
+           return Response.status(Status.BAD_REQUEST).build();
+        }
+
+       //Check for input conflict. Only one input at once is allowed
+       if((file!=null)&&(input_graph!=null)){
+           System.err.println("ERROR: To much RDF input");
+           return Response.status(Status.CONFLICT).build();
+       }
+
+      //Load input file or graph
+      if(file!=null)
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(file);
+      if(input_graph!=null)
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(
+								IRI.create(input_graph));
+      if(inputowl==null&&(session==null||scope==null))
+        return Response.status(Status.NOT_FOUND).build();
+      if(inputowl==null){
+          if(scope!=null)
+					this.inputowl = OWLManager.createOWLOntologyManager()
+							.createOntology();
+          else{
+					this.inputowl = OWLManager.createOWLOntologyManager()
+							.createOntology();
+          }
+      }
+
+       //Create list to add ontologies as imported
+       OWLOntologyManager mgr = inputowl.getOWLOntologyManager();
+			OWLDataFactory factory = inputowl.getOWLOntologyManager()
+					.getOWLDataFactory();
+       List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+
+       boolean ok = false;
+
+      //Load ontologies from scope, RDF input and recipe
+      //Try to resolve scope IRI
+      if((scope!=null)&&(session==null))
+      try{
+          IRI iri = IRI.create(scope);
+					ScopeRegistry reg = onm.getScopeRegistry();
+          OntologyScope ontoscope = reg.getScope(iri);
+					Iterator<OWLOntology> importscope = ontoscope
+							.getCustomSpace().getOntologies().iterator();
+					Iterator<OntologySpace> importsession = ontoscope
+							.getSessionSpaces().iterator();
+
+					// Add ontology as import form scope, if it is anonymus we
+					// try to add single axioms.
+          while(importscope.hasNext()){
+            OWLOntology auxonto = importscope.next();
+            if(!auxonto.getOntologyID().isAnonymous()){
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
+            }else{
+                mgr.addAxioms(inputowl,auxonto.getAxioms());
+            }
+         }
+
+         //Add ontology form sessions
+         while(importsession.hasNext()){
+						Iterator<OWLOntology> sessionontos = importsession
+								.next().getOntologies().iterator();
+             while(sessionontos.hasNext()){
+                OWLOntology auxonto = sessionontos.next();
+                if(!auxonto.getOntologyID().isAnonymous()){
+								additions
+										.add(new AddImport(
+												inputowl,
+												factory
+														.getOWLImportsDeclaration(auxonto
+																.getOWLOntologyManager()
+																.getOntologyDocumentIRI(
+																		auxonto))));
+                }else{
+                    mgr.addAxioms(inputowl,auxonto.getAxioms());
+                }
+         }
+
+         }
+          
+      }catch(Exception e){
+          System.err.println("ERROR: Problem with scope: "+scope);
+          e.printStackTrace();
+          Response.status(Status.NOT_FOUND).build();
+      }
+
+      //Get Ontologies from session
+      if((session!=null)&&(scope!=null))
+      try{
+          IRI iri = IRI.create(scope);
+					ScopeRegistry reg = onm.getScopeRegistry();
+          OntologyScope ontoscope = reg.getScope(iri);
+					SessionOntologySpace sos = ontoscope.getSessionSpace(IRI
+							.create(session));
+          
+					Set<OWLOntology> ontos = sos.getOntologyManager()
+							.getOntologies();
+          Iterator<OWLOntology> iteronto = ontos.iterator();
+
+					// Add session ontologies as import, if it is anonymus we
+					// try to add single axioms.
+          while(iteronto.hasNext()){
+            OWLOntology auxonto = iteronto.next();
+            if(!auxonto.getOntologyID().isAnonymous()){
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
+            }else{
+                mgr.addAxioms(inputowl,auxonto.getAxioms());
+            }
+          }
+
+      }catch(Exception e){
+					System.err.println("ERROR: Problem with session: "
+							+ session);
+          e.printStackTrace();
+          Response.status(Status.NOT_FOUND).build();
+      }
+
+			// After gathered the all ontology as imported now we apply the
+			// changes
+      if(additions.size()>0)
+        mgr.applyChanges(additions);
+
+      //Run HermiT if the reasonerURL is null;
+      if(owllink_endpoint==null){
+
+       try{
+       if(recipe!=null) {
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
+            Model swrlmodel = fromRecipeToModel(recipeowl);
+
+						// Create a reasoner to run rules contained in the
+						// recipe
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl);
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
+            inputowl = rulereasoner.runRulesReasoner();
+       }
+
+            //Create the reasoner for the classification
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl);
+					// Prepare and start the reasoner to classify ontology's
+					// resources
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+
+					// Create a new OWLOntology model where to put the inferred
+					// axioms
+					OWLOntology output = OWLManager.createOWLOntologyManager()
+							.createOntology(inputowl.getOntologyID());
+            //Initial input axioms count
+            int startax = output.getAxiomCount();
+            //Run the classification
+            output = reasoner.runClassifyInference(output);
+            //End output axioms count
+            int endax = output.getAxiomCount();
+
+            if((endax-startax)>0){
+                //Some inference is retrieved
+                return Response.ok(output).build();
+            }else{
+                //No data is retrieved
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+       }catch (InconsistentOntologyException exc){
+           System.err.println("CHECK ONTOLOGY CONSISTENCE");
+           return Response.status(Status.NOT_FOUND).build();
+        }
+
+				// If there is an owl-link server end-point specified in the
+				// form
+      }else{
+
+      try{
+       if(recipe!=null) {
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
+         Model swrlmodel = fromRecipeToModel(recipeowl);
+						// Create a reasoner to run rules contained in the
+						// recipe by using the server and-point
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl, new URL(owllink_endpoint));
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
+         inputowl = rulereasoner.runRulesReasoner();
+       }
+					// Create the reasoner for the consistency check by using
+					// the server and-point
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl, new URL(owllink_endpoint));
+					// Prepare and start the reasoner to classify ontology's
+					// resources
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+
+					// Create a new OWLOntology model where to put the inferred
+					// axioms
+					OWLOntology output = OWLManager.createOWLOntologyManager()
+							.createOntology(inputowl.getOntologyID());
+         //Initial input axioms count
+         int startax = output.getAxiomCount();
+         //Run the classification
+         output = reasoner.runClassifyInference(output);
+         //End output axioms count
+         int endax = output.getAxiomCount();
+
+            if((endax-startax)>0){
+                //Some inference is retrieved
+                return Response.ok(output).build();
+            }else{
+                //No data is retrieved
+                return Response.status(Status.NOT_FOUND).build();
+            }
+
+      }catch (InconsistentOntologyException exc){
+           System.err.println("CHECK ONTOLOGY CONSISTENCE");
+            return Response.status(Status.NOT_FOUND).build();
+      }
+      }
+      }catch(Exception e){
+          throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+      }
+
+    }
+
+}

Added: 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/ConsistencyCheck.java?rev=1083484&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/ConsistencyCheck.java Sun Mar 20 16:13:06 2011
@@ -0,0 +1,520 @@
+package org.apache.stanbol.reasoners.web;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+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.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.KReSONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.OWLDuplicateSafeLoader;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.ScopeRegistry;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ontology.OntologyStorage;
+import org.apache.stanbol.reasoners.base.commands.KReSCreateReasoner;
+import org.apache.stanbol.reasoners.base.commands.KReSRunReasoner;
+import org.apache.stanbol.reasoners.base.commands.KReSRunRules;
+import org.apache.stanbol.rules.base.api.KReSRule;
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.base.api.util.KReSRuleList;
+import org.apache.stanbol.rules.manager.KReSKB;
+import org.apache.stanbol.rules.manager.changes.KReSRuleStore;
+import org.apache.stanbol.rules.manager.parse.KReSRuleParser;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLDataProperty;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLLiteral;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.model.UnloadableImportException;
+import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+
+/**
+ * This class implements the REST interface for the /check-consistency service
+ * of KReS.
+ * 
+ * @author elvio
+ */
+@Path("/check-consistency")
+public class ConsistencyCheck {
+
+	private RuleStore kresRuleStore;
+	private OWLOntology inputowl;
+	private OWLOntology scopeowl;
+
+	private final OWLDuplicateSafeLoader loader = new OWLDuplicateSafeLoader();
+	protected KReSONManager onm;
+	protected OntologyStorage storage;
+
+	private Logger log = LoggerFactory.getLogger(getClass());
+
+	/**
+	 * The constructor.
+	 * 
+	 * @param servletContext
+	 *            {To get the context where the REST service is running.}
+	 */
+	public ConsistencyCheck(@Context ServletContext servletContext) {
+
+		// Retrieve the rule store
+		this.kresRuleStore = (RuleStore) servletContext
+				.getAttribute(RuleStore.class.getName());
+		// Retrieve the ontology network manager
+		this.onm = (KReSONManager) servletContext
+				.getAttribute(KReSONManager.class.getName());
+//      this.storage = (OntologyStorage) servletContext
+//      .getAttribute(OntologyStorage.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (onm == null) {
+    log
+            .warn("No KReSONManager in servlet context. Instantiating manually...");
+    onm = new ONManager(new TcManager(), null,
+            new Hashtable<String, Object>());
+}
+this.storage = onm.getOntologyStore();
+if (storage == null) {
+    log.warn("No OntologyStorage in servlet context. Instantiating manually...");
+    storage = new OntologyStorage(new TcManager(),null);
+}
+		if (kresRuleStore == null) {
+			log
+					.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+			this.kresRuleStore = new KReSRuleStore(onm,
+					new Hashtable<String, Object>(), "");
+			log
+					.debug("PATH TO OWL FILE LOADED: "
+					+ kresRuleStore.getFilePath());
+		}
+
+	}
+
+	/**
+	 * To trasform a sequence of rules to a Jena Model
+	 * 
+	 * @param owl
+	 *            {OWLOntology object contains a single recipe}
+	 * @return {A jena rdf model contains the SWRL rule.}
+	 */
+	private Model fromRecipeToModel(OWLOntology owl)
+			throws NoSuchRecipeException, OWLOntologyCreationException {
+
+		// FIXME: why the heck is this method re-instantiating a rule store?!?
+		RuleStore store = new KReSRuleStore(onm,
+				new Hashtable<String, Object>(), owl);
+		Model jenamodel = ModelFactory.createDefaultModel();
+
+		OWLDataFactory factory = owl.getOWLOntologyManager()
+				.getOWLDataFactory();
+		OWLClass ontocls = factory
+				.getOWLClass(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe"));
+		Set<OWLClassAssertionAxiom> cls = owl.getClassAssertionAxioms(ontocls);
+		Iterator<OWLClassAssertionAxiom> iter = cls.iterator();
+		IRI recipeiri = IRI.create(iter.next().getIndividual().toStringID());
+
+		OWLIndividual recipeIndividual = factory
+				.getOWLNamedIndividual(recipeiri);
+
+		OWLObjectProperty objectProperty = factory
+				.getOWLObjectProperty(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
+		Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(
+				objectProperty, store.getOntology());
+		String kReSRules = "";
+		for (OWLIndividual rule : rules) {
+			OWLDataProperty hasBodyAndHead = factory
+					.getOWLDataProperty(IRI
+							.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
+			Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(
+					hasBodyAndHead, store.getOntology());
+			for (OWLLiteral kReSRuleLiteral : kReSRuleLiterals) {
+				kReSRules += kReSRuleLiteral.getLiteral()
+						+ System.getProperty("line.separator");
+			}
+		}
+
+		// kReSRules =
+		// "ProvaParent = <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#> . rule1[ has(ProvaParent:hasParent, ?x, ?y) . has(ProvaParent:hasBrother, ?y, ?z) -> has(ProvaParent:hasUncle, ?x, ?z) ]";
+		KReSKB kReSKB = KReSRuleParser.parse(kReSRules);
+		KReSRuleList listrules = kReSKB.getkReSRuleList();
+		Iterator<KReSRule> iterule = listrules.iterator();
+		while (iterule.hasNext()) {
+			KReSRule singlerule = iterule.next();
+			Resource resource = singlerule.toSWRL(jenamodel);
+		}
+
+		return jenamodel;
+
+	}
+
+	/**
+	 * To check the consistency of an Ontology or a Scope (as top ontology)
+	 * using the default reasoner
+	 * 
+	 * @param uri
+	 *            {A string contains the IRI of RDF (either RDF/XML or owl or
+	 *            scope) to be checked.}
+	 * @return Return: <br/>
+	 *         200 No data is retrieved, the graph IS consistent <br/>
+	 *         204 No data is retrieved, the graph IS NOT consistent <br/>
+	 *         404 File not found. The ontology cannot be retrieved. <br/>
+	 *         412 Precondition failed. The ontology cannot be checked. This
+	 *         happens, for example, if the ontology includes missing imports. <br/>
+	 *         500 Some error occurred.
+	 */
+	@GET
+	@Path("/{uri:.+}")
+	public Response GetSimpleConsistencyCheck(
+			@PathParam(value = "uri") String uri) {
+		log.debug("Start simple consistency check with input: "+uri, this);
+		try {
+			boolean ok = false;
+			OWLOntology owl;
+			try {
+				// First create a manager
+				OWLOntologyManager mng = OWLManager.createOWLOntologyManager();
+
+				/**
+				 * We use the loader to support duplicate owl:imports
+				 */
+				log.debug("Loading "+uri, this);
+				owl = loader.load(mng, uri);
+				// owl = mng.loadOntologyFromOntologyDocument(IRI.create(uri));
+			} catch (UnloadableImportException uu) {
+				log.debug("Some ontology import failed. Cannot continue.", uu);
+				return Response.status(Status.PRECONDITION_FAILED).build();
+			} catch (Exception ee) {
+				log
+						.error(
+								"Cannot fetch the ontology. Some error occurred. Cannot continue.",
+								ee);
+				return Response.status(Status.NOT_FOUND).build();
+			}
+			KReSCreateReasoner newreasoner = new KReSCreateReasoner(owl);
+			// KReSReasonerImpl reasoner = new KReSReasonerImpl();
+			try {
+				KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+						.getReasoner());
+				ok = reasoner.isConsistent();
+			} catch (InconsistentOntologyException exc) {
+				ok = false;
+			}
+
+			if (ok) {
+				log.debug("The give graph is consistent.",this);
+				// No data is retrieved, the graph IS consistent
+				return Response.status(Status.OK).build();
+			} else {
+				log.debug("The give graph is NOT consistent.",this);
+				// No data is retrieved, the graph IS NOT consistent
+				return Response.status(Status.NO_CONTENT).build();
+			}
+
+		} catch (Exception e) {
+			// Some error occurred
+			throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+		}
+
+	}
+
+	/**
+	 * To check the consistency of a RDF input File or IRI on the base of a
+	 * Scope (or an ontology) and a recipe. Can be used either HermiT or an
+	 * owl-link server reasoner end-point
+	 * 
+	 * @param session
+	 *            {A string contains the session IRI used to check the
+	 *            consistency.}
+	 * @param scope
+	 *            {A string contains either a specific scope's ontology or the
+	 *            scope IRI used to check the consistency.}
+	 * @param recipe
+	 *            {A string contains the recipe IRI from the service
+	 *            http://localhost:port/kres/recipe/recipeName.}
+	 * @Param file {A file in a RDF (eihter RDF/XML or owl) to be checked.}
+	 * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or
+	 *        OWL) to be checked.}
+	 * @Param owllink_endpoint {A string contains the reasoner server end-point
+	 *        URL.}
+	 * @return Return: <br/>
+	 *         200 No data is retrieved, the graph IS consistent <br/>
+	 *         204 No data is retrieved, the graph IS NOT consistent <br/>
+	 *         400 To run the session is needed the scope <br/>
+	 *         404 Scope either Ontology or recipe or RDF input not found <br/>
+	 *         409 Too much RDF input <br/>
+	 *         500 Some error occurred
+	 */
+	@POST
+	@Consumes(MediaType.MULTIPART_FORM_DATA)
+	public Response getConsistencyCheck(
+			@FormParam(value = "session") String session,
+			@FormParam(value = "scope") String scope,
+			@FormParam(value = "recipe") String recipe,
+			@FormParam(value = "input-graph") String input_graph,
+			@FormParam(value = "file") File file,
+			@FormParam(value = "owllink-endpoint") String owllink_endpoint) {
+
+		try {
+
+			if ((session != null) && (scope == null)) {
+				log.error("Cannot load session without scope.", this);
+				return Response.status(Status.BAD_REQUEST).build();
+			}
+
+			// Check for input conflict. Only one input at once is allowed
+			if ((file != null) && (input_graph != null)) {
+				log.error("To much RDF input", this);
+				return Response.status(Status.CONFLICT).build();
+			}
+
+			// Load input file or graph
+			if (file != null)
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(file);
+			if (input_graph != null)
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(
+								IRI.create(input_graph));
+			if (inputowl == null && (session == null || scope == null))
+				return Response.status(Status.NOT_FOUND).build();
+			if (inputowl == null) {
+				if (scope != null)
+					this.inputowl = OWLManager.createOWLOntologyManager()
+							.createOntology();
+				else {
+					this.inputowl = OWLManager.createOWLOntologyManager()
+							.createOntology();
+				}
+			}
+
+			// Create list to add ontologies as imported
+			OWLOntologyManager mgr = inputowl.getOWLOntologyManager();
+			OWLDataFactory factory = inputowl.getOWLOntologyManager()
+					.getOWLDataFactory();
+			List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+
+			boolean ok = false;
+
+			// Load ontologies from scope, RDF input and recipe
+			// Try to resolve scope IRI
+			if ((scope != null) && (session == null))
+				try {
+					IRI iri = IRI.create(scope);
+					ScopeRegistry reg = onm.getScopeRegistry();
+					OntologyScope ontoscope = reg.getScope(iri);
+					Iterator<OWLOntology> importscope = ontoscope
+							.getCustomSpace().getOntologies().iterator();
+					Iterator<OntologySpace> importsession = ontoscope
+							.getSessionSpaces().iterator();
+
+					// Add ontology as import form scope, if it is anonymus we
+					// try to add single axioms.
+					while (importscope.hasNext()) {
+						OWLOntology auxonto = importscope.next();
+						if (!auxonto.getOntologyID().isAnonymous()) {
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
+						} else {
+							mgr.addAxioms(inputowl, auxonto.getAxioms());
+						}
+					}
+
+					// Add ontology form sessions
+					while (importsession.hasNext()) {
+						Iterator<OWLOntology> sessionontos = importsession
+								.next().getOntologies().iterator();
+						while (sessionontos.hasNext()) {
+							OWLOntology auxonto = sessionontos.next();
+							if (!auxonto.getOntologyID().isAnonymous()) {
+								additions
+										.add(new AddImport(
+												inputowl,
+												factory
+														.getOWLImportsDeclaration(auxonto
+																.getOWLOntologyManager()
+																.getOntologyDocumentIRI(
+																		auxonto))));
+							} else {
+								mgr.addAxioms(inputowl, auxonto.getAxioms());
+							}
+						}
+
+					}
+
+				} catch (Exception e) {
+					log.error("Problem with scope: " + scope, this);
+					log.debug("Exception is ", e);
+					Response.status(Status.NOT_FOUND).build();
+				}
+
+			// Get Ontologies from session
+			if ((session != null) && (scope != null))
+				try {
+					IRI iri = IRI.create(scope);
+					ScopeRegistry reg = onm.getScopeRegistry();
+					OntologyScope ontoscope = reg.getScope(iri);
+					SessionOntologySpace sos = ontoscope.getSessionSpace(IRI
+							.create(session));
+
+					Set<OWLOntology> ontos = sos.getOntologyManager()
+							.getOntologies();
+					Iterator<OWLOntology> iteronto = ontos.iterator();
+
+					// Add session ontologies as import, if it is anonymus we
+					// try to add single axioms.
+					while (iteronto.hasNext()) {
+						OWLOntology auxonto = iteronto.next();
+						if (!auxonto.getOntologyID().isAnonymous()) {
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
+						} else {
+							mgr.addAxioms(inputowl, auxonto.getAxioms());
+						}
+					}
+
+				} catch (Exception e) {
+					log.error("Problem with session: " + session, this);
+					log.debug("Exception is", e);
+					Response.status(Status.NOT_FOUND).build();
+				}
+
+			// After gathered the all ontology as imported now we apply the
+			// changes
+			if (additions.size() > 0)
+				mgr.applyChanges(additions);
+
+			// Run HermiT if the reasonerURL is null;
+			if (owllink_endpoint == null) {
+
+				// Create the reasoner for the consistency check
+				try {
+
+					if (recipe != null) {
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
+						Model swrlmodel = fromRecipeToModel(recipeowl);
+						// Create a reasoner to run rules contained in the
+						// recipe
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl);
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
+						inputowl = rulereasoner.runRulesReasoner();
+					}
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl);
+					// Prepare and start the reasoner to check the consistence
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+					ok = reasoner.isConsistent();
+				} catch (InconsistentOntologyException exc) {
+					ok = false;
+				}
+
+				if (ok) {
+					// No data is retrieved, the graph IS consistent
+					return Response.status(Status.OK).build();
+				} else {
+					// No data is retrieved, the graph IS NOT consistent
+					return Response.status(Status.NO_CONTENT).build();
+				}
+
+				// If there is an owl-link server end-point specified in the
+				// form
+			} else {
+
+				// Create the reasoner for the consistency check by using the
+				// server and-point
+				try {
+					if (recipe != null) {
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
+						Model swrlmodel = fromRecipeToModel(recipeowl);
+
+						// Create a reasoner to run rules contained in the
+						// recipe by using the server and-point
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl, new URL(owllink_endpoint));
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
+						inputowl = rulereasoner.runRulesReasoner();
+					}
+
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl, new URL(owllink_endpoint));
+					// Prepare and start the reasoner to check the consistence
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+					ok = reasoner.isConsistent();
+				} catch (InconsistentOntologyException exc) {
+					ok = false;
+				}
+
+				if (ok) {
+					// No data is retrieved, the graph IS consistent
+					return Response.status(Status.OK).build();
+				} else {
+					// No data is retrieved, the graph IS NOT consistent
+					return Response.status(Status.NO_CONTENT).build();
+				}
+			}
+
+		} catch (Exception e) {
+			throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+		}
+
+	}
+
+}

Added: 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/Enrichment.java?rev=1083484&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/Enrichment.java Sun Mar 20 16:13:06 2011
@@ -0,0 +1,460 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.apache.stanbol.reasoners.web;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.KReSONManager;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.ScopeRegistry;
+import org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ONManager;
+import org.apache.stanbol.ontologymanager.ontonet.impl.ontology.OntologyStorage;
+import org.apache.stanbol.reasoners.base.commands.KReSCreateReasoner;
+import org.apache.stanbol.reasoners.base.commands.KReSRunReasoner;
+import org.apache.stanbol.reasoners.base.commands.KReSRunRules;
+import org.apache.stanbol.rules.base.api.KReSRule;
+import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.base.api.util.KReSRuleList;
+import org.apache.stanbol.rules.manager.KReSKB;
+import org.apache.stanbol.rules.manager.changes.KReSRuleStore;
+import org.apache.stanbol.rules.manager.parse.KReSRuleParser;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.AddImport;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLDataProperty;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLLiteral;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+
+/**
+ *
+ * 
+ */
+@Path("/enrichment")
+public class Enrichment {
+
+    private RuleStore kresRuleStore;
+    private OWLOntology inputowl;
+    private OWLOntology scopeowl;
+
+	protected KReSONManager onm;
+	protected OntologyStorage storage;
+
+	private Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * To get the KReSRuleStore where are stored the rules and the recipes
+     *
+	 * @param servletContext
+	 *            {To get the context where the REST service is running.}
+     */
+    public Enrichment(@Context ServletContext servletContext){
+		// Retrieve the rule store
+		this.kresRuleStore = (RuleStore) servletContext
+				.getAttribute(RuleStore.class.getName());
+		// Retrieve the ontology network manager
+		this.onm = (KReSONManager) servletContext
+				.getAttribute(KReSONManager.class.getName());
+//      this.storage = (OntologyStorage) servletContext
+//      .getAttribute(OntologyStorage.class.getName());
+// Contingency code for missing components follows.
+/*
+ * FIXME! The following code is required only for the tests. This should
+ * be removed and the test should work without this code.
+ */
+if (onm == null) {
+    log
+            .warn("No KReSONManager in servlet context. Instantiating manually...");
+    onm = new ONManager(new TcManager(), null,
+            new Hashtable<String, Object>());
+}
+this.storage = onm.getOntologyStore();
+if (storage == null) {
+    log.warn("No OntologyStorage in servlet context. Instantiating manually...");
+    storage = new OntologyStorage(new TcManager(),null);
+}
+       if (kresRuleStore == null) {
+			log
+					.warn("No KReSRuleStore with stored rules and recipes found in servlet context. Instantiating manually with default values...");
+			this.kresRuleStore = new KReSRuleStore(onm,
+					new Hashtable<String, Object>(), "");
+			log
+					.debug("PATH TO OWL FILE LOADED: "
+							+ kresRuleStore.getFilePath());
+        }
+    }
+
+   /**
+     * To trasform a sequence of rules to a Jena Model
+	 * 
+	 * @param owl
+	 *            {OWLOntology object contains a single recipe}
+     * @return {A jena rdf model contains the SWRL rule.}
+     */
+	private Model fromRecipeToModel(OWLOntology owl)
+			throws NoSuchRecipeException {
+
+		// FIXME: why the heck is this method re-instantiating a rule store?!?
+		RuleStore store = new KReSRuleStore(onm,
+				new Hashtable<String, Object>(), owl);
+        Model jenamodel = ModelFactory.createDefaultModel();
+
+		OWLDataFactory factory = owl.getOWLOntologyManager()
+				.getOWLDataFactory();
+		OWLClass ontocls = factory
+				.getOWLClass(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#Recipe"));
+        Set<OWLClassAssertionAxiom> cls = owl.getClassAssertionAxioms(ontocls);
+        Iterator<OWLClassAssertionAxiom> iter = cls.iterator();
+        IRI recipeiri = IRI.create(iter.next().getIndividual().toStringID());
+
+		OWLIndividual recipeIndividual = factory
+				.getOWLNamedIndividual(recipeiri);
+
+		OWLObjectProperty objectProperty = factory
+				.getOWLObjectProperty(IRI
+						.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasRule"));
+		Set<OWLIndividual> rules = recipeIndividual.getObjectPropertyValues(
+				objectProperty, store.getOntology());
+        String kReSRules = "";
+        for(OWLIndividual rule : rules){
+			OWLDataProperty hasBodyAndHead = factory
+					.getOWLDataProperty(IRI
+							.create("http://kres.iks-project.eu/ontology/meta/rmi.owl#hasBodyAndHead"));
+			Set<OWLLiteral> kReSRuleLiterals = rule.getDataPropertyValues(
+					hasBodyAndHead, store.getOntology());
+
+			for(OWLLiteral kReSRuleLiteral : kReSRuleLiterals){
+				kReSRules += kReSRuleLiteral.getLiteral()
+						+ System.getProperty("line.separator");
+			}
+		}
+
+	//"ProvaParent = <http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#> . rule1[ has(ProvaParent:hasParent, ?x, ?y) . has(ProvaParent:hasBrother, ?y, ?z) -> has(ProvaParent:hasUncle, ?x, ?z) ]");
+        KReSKB kReSKB = KReSRuleParser.parse(kReSRules);
+        KReSRuleList listrules = kReSKB.getkReSRuleList();
+        Iterator<KReSRule> iterule = listrules.iterator();
+        while(iterule.hasNext()){
+            KReSRule singlerule = iterule.next();
+            Resource resource = singlerule.toSWRL(jenamodel);
+        }
+
+        return jenamodel;
+
+    }
+
+   /**
+	 * To perform a rule based reasoning with a given recipe and scope (or an
+	 * ontology) to a RDF input specify via its IRI.
+	 * 
+	 * @param session
+	 *            {A string contains the session IRI used to inference the
+	 *            input.}
+	 * @param scope
+	 *            {A string contains either ontology or the scope IRI used to
+	 *            inference the input.}
+	 * @param recipe
+	 *            {A string contains the recipe IRI from the service
+	 *            http://localhost:port/kres/recipe/recipeName.}
+     * @Param file {A file in a RDF (eihter RDF/XML or owl) to inference.}
+	 * @Param input_graph {A string contains the IRI of RDF (either RDF/XML or
+	 *        OWL) to inference.}
+	 * @Param owllink_endpoint {A string contains the reasoner server end-point
+	 *        URL.}
+     * @return Return: <br/>
+     *          200 Returns a graph with the enrichments <br/>
+     *          204 No enrichments have been produced from the given graph <br/>
+     *          400 To run the session is needed the scope <br/>
+     *          404 The recipe/ontology/scope/input doesn't exist in the network <br/>
+     *          409 Too much RDF inputs <br/>
+     *          500 Some error occurred
+     */
+    @POST
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Produces("application/rdf+xml")
+	public Response ontologyEnrichment(
+			@FormParam(value = "session") String session,
+			@FormParam(value = "scope") String scope,
+			@FormParam(value = "recipe") String recipe,
+			@FormParam(value = "input-graph") String input_graph,
+			@FormParam(value = "file") File file,
+			@FormParam(value = "owllink-endpoint") String owllink_endpoint) {
+
+      try{
+
+      if((session!=null)&&(scope==null)){
+           System.err.println("ERROR: Cannot load session without scope.");
+           return Response.status(Status.BAD_REQUEST).build();
+        }
+
+       //Check for input conflict. Only one input at once is allowed
+       if((file!=null)&&(input_graph!=null)){
+           System.err.println("ERROR: To much RDF input");
+           return Response.status(Status.CONFLICT).build();
+       }
+
+      //Load input file or graph
+      if(file!=null)
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(file);
+      if(input_graph!=null)
+				this.inputowl = OWLManager.createOWLOntologyManager()
+						.loadOntologyFromOntologyDocument(
+								IRI.create(input_graph));
+
+      if(inputowl==null)
+        return Response.status(Status.NOT_FOUND).build();
+
+       //Create list to add ontologies as imported
+       OWLOntologyManager mgr = inputowl.getOWLOntologyManager();
+			OWLDataFactory factory = inputowl.getOWLOntologyManager()
+					.getOWLDataFactory();
+       List<OWLOntologyChange> additions = new LinkedList<OWLOntologyChange>();
+
+       boolean ok = false;
+
+       //Load ontologies from scope, RDF input and recipe
+      //Try to resolve scope IRI
+      if((scope!=null)&&(session==null))
+      try{
+          IRI iri = IRI.create(scope);
+					ScopeRegistry reg = onm.getScopeRegistry();
+          OntologyScope ontoscope = reg.getScope(iri);
+					Iterator<OWLOntology> importscope = ontoscope
+							.getCustomSpace().getOntologies().iterator();
+					Iterator<OntologySpace> importsession = ontoscope
+							.getSessionSpaces().iterator();
+
+					// Add ontology as import form scope, if it is anonymus we
+					// try to add single axioms.
+          while(importscope.hasNext()){
+            OWLOntology auxonto = importscope.next();
+            if(!auxonto.getOntologyID().isAnonymous()){
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
+            }else{
+                mgr.addAxioms(inputowl,auxonto.getAxioms());
+            }
+         }
+
+         //Add ontology form sessions
+         while(importsession.hasNext()){
+						Iterator<OWLOntology> sessionontos = importsession
+								.next().getOntologies().iterator();
+             while(sessionontos.hasNext()){
+                OWLOntology auxonto = sessionontos.next();
+                if(!auxonto.getOntologyID().isAnonymous()){
+								additions
+										.add(new AddImport(
+												inputowl,
+												factory
+														.getOWLImportsDeclaration(auxonto
+																.getOWLOntologyManager()
+																.getOntologyDocumentIRI(
+																		auxonto))));
+                }else{
+                    mgr.addAxioms(inputowl,auxonto.getAxioms());
+                }
+         }
+
+         }
+
+      }catch(Exception e){
+          System.err.println("ERROR: Problem with scope: "+scope);
+          e.printStackTrace();
+          Response.status(Status.NOT_FOUND).build();
+      }
+
+      //Get Ontologies from session
+      if((session!=null)&&(scope!=null))
+      try{
+          IRI iri = IRI.create(scope);
+					ScopeRegistry reg = onm.getScopeRegistry();
+          OntologyScope ontoscope = reg.getScope(iri);
+					SessionOntologySpace sos = ontoscope.getSessionSpace(IRI
+							.create(session));
+
+					Set<OWLOntology> ontos = sos.getOntologyManager()
+							.getOntologies();
+          Iterator<OWLOntology> iteronto = ontos.iterator();
+
+					// Add session ontologies as import, if it is anonymus we
+					// try to add single axioms.
+          while(iteronto.hasNext()){
+            OWLOntology auxonto = iteronto.next();
+            if(!auxonto.getOntologyID().isAnonymous()){
+							additions.add(new AddImport(inputowl, factory
+									.getOWLImportsDeclaration(auxonto
+											.getOWLOntologyManager()
+											.getOntologyDocumentIRI(auxonto))));
+            }else{
+                mgr.addAxioms(inputowl,auxonto.getAxioms());
+            }
+          }
+
+      }catch(Exception e){
+					System.err.println("ERROR: Problem with session: "
+							+ session);
+          e.printStackTrace();
+          Response.status(Status.NOT_FOUND).build();
+      }
+
+			// After gathered the all ontology as imported now we apply the
+			// changes
+      if(additions.size()>0)
+        mgr.applyChanges(additions);
+
+      //Run HermiT if the reasonerURL is null;
+      if(owllink_endpoint==null){
+
+       try{
+       if(recipe!=null) {
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
+            Model swrlmodel = fromRecipeToModel(recipeowl);
+
+						// Create a reasoner to run rules contained in the
+						// recipe
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl);
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
+            inputowl = rulereasoner.runRulesReasoner();
+       }    
+       
+            //Create the reasoner for the enrichment
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl);
+					// Prepare and start the reasoner to enrich ontology's
+					// resources
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+
+					// Create a new OWLOntology model where to put the inferred
+					// axioms
+					OWLOntology output = OWLManager.createOWLOntologyManager()
+							.createOntology(inputowl.getOntologyID());
+            //Initial input axioms count
+            int startax = output.getAxiomCount();
+            //Run the classification
+            output = reasoner.runGeneralInference(output);
+            //End output axioms count
+            int endax = output.getAxiomCount();
+
+            if((endax-startax)>0){
+                //Some inference is retrieved
+                return Response.ok(output).build();
+            }else{
+                //No data is retrieved
+                return Response.status(Status.NOT_FOUND).build();
+            }
+       }catch (InconsistentOntologyException exc){
+           System.err.println("CHECK ONTOLOGY CONSISTENCE");
+            return Response.status(Status.NOT_FOUND).build();
+        }
+				// If there is an owl-link server end-point specified in the
+				// form
+      }else{
+
+      try{
+       if(recipe!=null) {
+						OWLOntology recipeowl = OWLManager
+								.createOWLOntologyManager()
+								.loadOntologyFromOntologyDocument(
+										IRI.create(recipe));
+						// Get Jea RDF model of SWRL rule contained in the
+						// recipe
+         Model swrlmodel = fromRecipeToModel(recipeowl);
+						// Create a reasoner to run rules contained in the
+						// recipe by using the server and-point
+						KReSRunRules rulereasoner = new KReSRunRules(swrlmodel,
+								inputowl, new URL(owllink_endpoint));
+						// Run the rule reasoner to the input RDF with the added
+						// top-ontology
+         inputowl = rulereasoner.runRulesReasoner();
+       }
+
+					// Create a new OWLOntology model where to put the inferred
+					// axioms
+					OWLOntology output = OWLManager.createOWLOntologyManager()
+							.createOntology(inputowl.getOntologyID());
+
+         //Create the reasoner for the enrichment
+					KReSCreateReasoner newreasoner = new KReSCreateReasoner(
+							inputowl, new URL(owllink_endpoint));
+					// Prepare and start the reasoner to enrich ontology's
+					// resources
+					KReSRunReasoner reasoner = new KReSRunReasoner(newreasoner
+							.getReasoner());
+
+         //Initial input axioms count
+         int startax = output.getAxiomCount();
+         //Run the rule reasoner
+         output = reasoner.runGeneralInference(output);
+         //End output axioms count
+         int endax = output.getAxiomCount();
+
+        if((endax-startax)>0){
+          //No data is retrieved, the graph IS consistent
+          return Response.ok(output).build();
+        }else{
+          //No data is retrieved, the graph IS NOT consistent
+          return Response.status(Status.NO_CONTENT).build();
+        }
+         }catch (InconsistentOntologyException exc){
+           System.err.println("CHECK ONTOLOGY CONSISTENCE");
+            return Response.status(Status.NOT_FOUND).build();
+        }
+      }
+      }catch(Exception e){
+          throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
+      }
+
+    }
+    
+}

Added: 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=1083484&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpoint.java Sun Mar 20 16:13:06 2011
@@ -0,0 +1,125 @@
+package org.apache.stanbol.reasoners.web;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.ServletContext;
+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.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+
+import org.apache.stanbol.kres.jersey.processors.KReSViewProcessor;
+
+/**
+ * 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.
+ * 
+ * @author andrea.nuzzolese
+ */
+
+@Component(immediate = true, metatype = true)
+public class JerseyEndpoint {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Property(value = "/kres/reasoners")
+    public static final String ALIAS_PROPERTY = "org.apache.stanbol.reasoners.web.jersey.alias";
+
+    @Property(value = "/kres/reasoners/static")
+    public static final String STATIC_RESOURCES_URL_ROOT_PROPERTY = "org.apache.stanbol.reasoners.web.jersey.static.url";
+
+    @Property(value = "/META-INF/static")
+    public static final String STATIC_RESOURCES_CLASSPATH_PROPERTY = "org.apache.stanbol.reasoners.web.jersey.static.classpath";
+
+    @Property(value = "/META-INF/templates")
+    public static final String FREEMARKER_TEMPLATE_CLASSPATH_PROPERTY = "org.apache.stanbol.reasoners.web.jersey.templates.classpath";
+
+    @Reference
+    HttpService httpService;
+
+    protected ServletContext servletContext;
+
+    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());
+
+        // make jersey automatically turn resources into Viewable models and
+        // hence lookup matching freemarker templates
+        initParams.put("com.sun.jersey.config.feature.ImplicitViewables",
+                "true");
+        return initParams;
+    }
+
+    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);
+
+        log.info("Registering servlets with HTTP service "
+                + httpService.toString());
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(
+                getClass().getClassLoader());
+        try {
+            httpService.registerServlet(alias, container, getInitParams(), null);
+            httpService.registerResources(staticUrlRoot, staticClasspath, null);
+        } finally {
+            Thread.currentThread().setContextClassLoader(classLoader);
+        }
+
+        // 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(
+                KReSViewProcessor.FREEMARKER_TEMPLATE_PATH_INIT_PARAM,
+                freemakerTemplates);
+
+        log.info("Jersey servlet registered at {}", alias);
+    }
+
+    protected void deactivate(ComponentContext ctx) {
+        log.info("Deactivating jersey bundle");
+        String alias = (String) ctx.getProperties().get(ALIAS_PROPERTY);
+        httpService.unregister(alias);
+        servletContext = null;
+    }
+
+    
+    protected void bindHttpService(HttpService httpService) {
+        this.httpService = httpService;
+    }
+
+    protected void unbindHttpService(HttpService httpService) {
+        this.httpService = null;
+    }
+
+}

Added: 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=1083484&view=auto
==============================================================================
--- incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java (added)
+++ incubator/stanbol/trunk/kres/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/JerseyEndpointApplication.java Sun Mar 20 16:13:06 2011
@@ -0,0 +1,52 @@
+package org.apache.stanbol.reasoners.web;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+import org.apache.stanbol.kres.jersey.processors.KReSViewProcessor;
+import org.apache.stanbol.kres.jersey.writers.GraphWriter;
+import org.apache.stanbol.kres.jersey.writers.OWLOntologyWriter;
+import org.apache.stanbol.kres.jersey.writers.ResultSetWriter;
+
+/**
+ * Statically define the list of available resources and providers to be used by the KReS JAX-RS Endpoint.
+ * 
+ * The jersey auto-scan mechanism does not seem to work when deployed through OSGi's HttpService
+ * initialization.
+ * 
+ * In the future this class might get refactored as an OSGi service to allow for dynamic configuration and
+ * deployment of additional JAX-RS resources and providers.
+ * 
+ * @author andrea.nuzzolese
+ */
+
+public class JerseyEndpointApplication extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+
+        // Reasoner
+        classes.add(ConsistencyCheck.class);
+        classes.add(Classify.class);
+        classes.add(Enrichment.class);
+
+        // message body writers
+        classes.add(GraphWriter.class);
+        classes.add(ResultSetWriter.class);
+        // classes.add(OwlModelWriter.class);
+        classes.add(OWLOntologyWriter.class);
+        return classes;
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        Set<Object> singletons = new HashSet<Object>();
+        // view processors
+        singletons.add(new KReSViewProcessor());
+        return singletons;
+    }
+
+}