incubator-stanbol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enrid...@apache.org
Subject svn commit: r1160609 - in /incubator/stanbol/branches/jena-reasoners/reasoners: hermit/ hermit/src/main/java/org/apache/stanbol/reasoners/hermit/ owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/ servicesapi/src/main/java/org/apache/stanbol/rea...
Date Tue, 23 Aug 2011 10:40:30 GMT
Author: enridaga
Date: Tue Aug 23 10:40:29 2011
New Revision: 1160609

URL: http://svn.apache.org/viewvc?rev=1160609&view=rev
Log:
STANBOL-185
* The OWLApiReasoningService interface have been defined
* POM file for Hermit have been fixed (some resources needed to work with datatypes were not
deployed in the bundle!)
* Implemented the GET?url= web method with an OWLApiReasoningService
* Changed the default path of the HermiT service to 'owl2'
* A fake resource ReasoningPrettyResultResource have been created, to display results in a
nice template wrapped way (not sure this is the best way).
* Added a README file, now containing only some curl example calls

Added:
    incubator/stanbol/branches/jena-reasoners/reasoners/web/README
    incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningPrettyResultResource.java
    incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl
      - copied, changed from r1160332, incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
Removed:
    incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
Modified:
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml
    incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
    incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java
    incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/OWLApiReasoningService.java
    incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/InconsistentInputException.java
    incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
    incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml (original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/pom.xml Tue Aug 23 10:40:29
2011
@@ -120,6 +120,7 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
+            <Embed-Dependency>hermit;scope=compile|runtime;inline=true</Embed-Dependency>
             <Bundle-ClassPath>.</Bundle-ClassPath>
             <Export-Package>
               com.clarkparsia.owlapi.explanation.*,
@@ -148,6 +149,8 @@
               org.coode.owlapi.turtle,
               org.coode.string,org.coode.xml,
               org.semanticweb.HermiT.*;version=1.3.4,
+              org.semanticweb.HermiT.datatypes.*;version=1.3.4,
+              org.semanticweb.HermiT.datatypes.rdfplainliteral.*,
               org.semanticweb.owlapi.*,
               rationals.*,
               uk.ac.manchester.cs.bhig.util,
@@ -175,6 +178,8 @@
               !org.protege.editor.owl.model.*,
               !org.w3c.dom.*,
               org.apache.stanbol.reasoners.servicesapi.*,
+              org.semanticweb.HermiT.datatypes.*;version=1.3.4,
+              org.semanticweb.HermiT.datatypes.rdfplainliteral.*,
               *
             </Import-Package>
             <_nouses>true</_nouses>

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/hermit/src/main/java/org/apache/stanbol/reasoners/hermit/HermitReasoningService.java
Tue Aug 23 10:40:29 2011
@@ -21,7 +21,8 @@ import org.semanticweb.owlapi.reasoner.O
 @Service
 public class HermitReasoningService extends AbstractOWLApiReasoningService
 		implements OWLApiReasoningService, ReasoningService {
-	public static final String _DEFAULT_PATH = "hermit";
+
+	public static final String _DEFAULT_PATH = "owl2";
 
 	@Property(name = ReasoningService.SERVICE_PATH, value = _DEFAULT_PATH)
 	private String path;
@@ -38,8 +39,10 @@ public class HermitReasoningService exte
 	public String getPath() {
 		return path;
 	}
+
 	@Activate
-	public void activate(ComponentContext context){
-		this.path = (String) context.getProperties().get(ReasoningService.SERVICE_PATH);
+	public void activate(ComponentContext context) {
+		this.path = (String) context.getProperties().get(
+				ReasoningService.SERVICE_PATH);
 	}
 }

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/AbstractOWLApiReasoningService.java
Tue Aug 23 10:40:29 2011
@@ -74,6 +74,7 @@ public abstract class AbstractOWLApiReas
 	 * @param generators
 	 * @return
 	 */
+	@Override
 	public Set<OWLAxiom> run(OWLOntology input,
 			List<InferredAxiomGenerator<? extends OWLAxiom>> generators)
 			throws ReasoningServiceException, InconsistentInputException {
@@ -91,8 +92,7 @@ public abstract class AbstractOWLApiReas
 					reasoner, generators);
 
 			// We fill an anonymous ontology with the result, the return the
-			// axiom
-			// set
+			// axiom set
 			Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
 			try {
 				OWLOntology output = manager.createOntology();
@@ -104,6 +104,7 @@ public abstract class AbstractOWLApiReas
 				manager.removeOntology(output);
 			} catch (OWLOntologyCreationException e) {
 				log.error("An exception have been thrown when instantiating the ontology");
+				throw new ReasoningServiceException();
 			}
 
 			return axioms;
@@ -127,6 +128,7 @@ public abstract class AbstractOWLApiReas
 	 * @param generators
 	 * @return
 	 */
+	@Override
 	public Set<OWLAxiom> run(OWLOntology ontology, List<SWRLRule> rules,
 			List<InferredAxiomGenerator<? extends OWLAxiom>> generators)
 			throws ReasoningServiceException, InconsistentInputException {
@@ -203,6 +205,7 @@ public abstract class AbstractOWLApiReas
 	 * @param ontology
 	 * @return
 	 */
+	@Override
 	public Set<OWLAxiom> classify(OWLOntology ontology)
 			throws ReasoningServiceException, InconsistentInputException {
 		return run(ontology, getClassifyAxiomGenerators());
@@ -217,6 +220,7 @@ public abstract class AbstractOWLApiReas
 	 * @throws InconsistentInputException
 	 * @throws ReasoningServiceException
 	 */
+	@Override
 	public Set<OWLAxiom> classify(OWLOntology ontology, List<SWRLRule> rules)
 			throws ReasoningServiceException, InconsistentInputException {
 		log.debug("Calling classify(OWLOntology ontology, List<SWRLRule> rules) ");
@@ -231,6 +235,7 @@ public abstract class AbstractOWLApiReas
 	 * @throws ReasoningServiceException
 	 * @throws InconsistentInputException
 	 */
+	@Override
 	public Set<OWLAxiom> enrich(OWLOntology ontology)
 			throws ReasoningServiceException, InconsistentInputException {
 		return run(ontology, getEnrichAxiomGenerators());
@@ -245,6 +250,7 @@ public abstract class AbstractOWLApiReas
 	 * @throws ReasoningServiceException
 	 * @throws InconsistentInputException
 	 */
+	@Override
 	public Set<OWLAxiom> enrich(OWLOntology ontology, List<SWRLRule> rules)
 			throws ReasoningServiceException, InconsistentInputException {
 		log.debug("Calling enrich(OWLOntology ontology, List<SWRLRule> rules) ");
@@ -258,6 +264,7 @@ public abstract class AbstractOWLApiReas
 	 * @return
 	 * @throws ReasoningServiceException 
 	 */
+	@Override
 	public boolean isConsistent(OWLOntology ontology) throws ReasoningServiceException {
 		try{
 		return getReasoner(ontology).isConsistent();
@@ -278,6 +285,7 @@ public abstract class AbstractOWLApiReas
 	 * @return
 	 * @throws ReasoningServiceException 
 	 */
+	@Override
 	public boolean isConsistent(OWLOntology ontology, List<SWRLRule> rules) throws ReasoningServiceException
{
 		log.debug("Create a input ontology to merge rules in.");
 		OWLOntology input;

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/OWLApiReasoningService.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/OWLApiReasoningService.java?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/OWLApiReasoningService.java
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/owlapi/src/main/java/org/apache/stanbol/reasoners/owlapi/OWLApiReasoningService.java
Tue Aug 23 10:40:29 2011
@@ -1,5 +1,39 @@
 package org.apache.stanbol.reasoners.owlapi;
 
+import java.util.List;
+import java.util.Set;
+
+import org.apache.stanbol.reasoners.servicesapi.InconsistentInputException;
+import org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException;
+import org.semanticweb.owlapi.model.OWLAxiom;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.SWRLRule;
+import org.semanticweb.owlapi.util.InferredAxiomGenerator;
+
 public interface OWLApiReasoningService {
 
+	public abstract boolean isConsistent(OWLOntology ontology, List<SWRLRule> rules)
+			throws ReasoningServiceException;
+
+	public abstract boolean isConsistent(OWLOntology ontology)
+			throws ReasoningServiceException;
+
+	public abstract Set<OWLAxiom> enrich(OWLOntology ontology, List<SWRLRule> rules)
+			throws ReasoningServiceException, InconsistentInputException;
+
+	public abstract Set<OWLAxiom> enrich(OWLOntology ontology)
+			throws ReasoningServiceException, InconsistentInputException;
+
+	public abstract Set<OWLAxiom> classify(OWLOntology ontology, List<SWRLRule>
rules)
+			throws ReasoningServiceException, InconsistentInputException;
+
+	public abstract Set<OWLAxiom> classify(OWLOntology ontology)
+			throws ReasoningServiceException, InconsistentInputException;
+
+	public abstract Set<OWLAxiom> run(OWLOntology ontology, List<SWRLRule> rules,
List<InferredAxiomGenerator<? extends OWLAxiom>> generators)
+			throws ReasoningServiceException, InconsistentInputException;
+
+	public abstract Set<OWLAxiom> run(OWLOntology input, List<InferredAxiomGenerator<?
extends OWLAxiom>> generators)
+			throws ReasoningServiceException, InconsistentInputException;
+
 }

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/InconsistentInputException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/InconsistentInputException.java?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/InconsistentInputException.java
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/servicesapi/src/main/java/org/apache/stanbol/reasoners/servicesapi/InconsistentInputException.java
Tue Aug 23 10:40:29 2011
@@ -1,5 +1,10 @@
 package org.apache.stanbol.reasoners.servicesapi;
 
+/**
+ * The process cannot be completed because the input is inconsistent. This
+ * Exception must be used by reasoning services which must stop the inference
+ * process if any inconsistency is found.
+ */
 public class InconsistentInputException extends Exception {
 
 	/**

Added: incubator/stanbol/branches/jena-reasoners/reasoners/web/README
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/README?rev=1160609&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/README (added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/README Tue Aug 23 10:40:29 2011
@@ -0,0 +1,22 @@
+
+Examples:
+
+# Classify the FOAF ontology, getting it from the web using the Jena OWL reasoner, result
in turtle
+curl -v -H "Accept: application/turtle" "http://localhost:8080/reasoners/services/owl/classify?url=http://xmlns.com/foaf/0.1/"
+
+# Classify the FOAF ontology, getting it from the web using the Jena OWL reasoner, result
in n3
+curl -v -H "Accept: text/n3" "http://localhost:8080/reasoners/services/owl/classify?url=http://xmlns.com/foaf/0.1/"
+
+# Enrich the FOAF ontology, getting it from the web using the Jena RDFS reasoner, result
in rdf/xml
+curl -v -H "Accept: application/rdf+xml" "http://localhost:8080/reasoners/services/owl/classify?url=http://xmlns.com/foaf/0.1/"
+
+# Check consistency of the FOAF ontology, getting it from the web using the Jena OWL reasoner,
result in turtle
+curl -v "http://localhost:8080/reasoners/services/owl/check?url=http://xmlns.com/foaf/0.1/"
+
+# Check consistency of the FOAF ontology, getting it from the web using the Hermit OWL2 reasoner,
result in turtle
+curl -v "http://localhost:8080/reasoners/services/hermit/check?url=http://xmlns.com/foaf/0.1/"
+
+# Trying with an ontology network (large ontology composed by a set of little ontologies
connected through owl:import statements)
+curl -v "http://localhost:8080/reasoners/services/hermit/check?url=http://www.cnr.it/ontology/cnr/cnr.owl"
+or
+curl -v "http://localhost:8080/reasoners/services/hermit/enrich?url=http://www.cnr.it/ontology/cnr/cnr.owl"

Added: incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningPrettyResultResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningPrettyResultResource.java?rev=1160609&view=auto
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningPrettyResultResource.java
(added)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningPrettyResultResource.java
Tue Aug 23 10:40:29 2011
@@ -0,0 +1,20 @@
+package org.apache.stanbol.reasoners.web.resources;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+
+public class ReasoningPrettyResultResource extends BaseStanbolResource {
+	private Object result;
+
+	public ReasoningPrettyResultResource(ServletContext context,UriInfo uriInfo, Object result)
{
+		this.result = result;
+		this.servletContext = context;
+		this.uriInfo = uriInfo;
+	}
+
+	public Object getResult() {
+		return this.result;
+	}
+}

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
Tue Aug 23 10:40:29 2011
@@ -3,7 +3,11 @@ package org.apache.stanbol.reasoners.web
 import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
 import static javax.ws.rs.core.MediaType.TEXT_HTML;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -28,12 +32,26 @@ import javax.ws.rs.core.Response.Status;
 import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.format.KRFormat;
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.owl.web.OWLOntologyWriter;
 import org.apache.stanbol.reasoners.jena.JenaReasoningService;
 import org.apache.stanbol.reasoners.owlapi.OWLApiReasoningService;
+import org.apache.stanbol.reasoners.servicesapi.InconsistentInputException;
 import org.apache.stanbol.reasoners.servicesapi.ReasoningService;
+import org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException;
 import org.apache.stanbol.reasoners.servicesapi.ReasoningServicesManager;
 import org.apache.stanbol.reasoners.servicesapi.UnboundReasoningServiceException;
 import org.apache.stanbol.reasoners.web.writers.JenaModelWriter;
+import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.io.OWLOntologyCreationIOException;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.MissingImportEvent;
+import org.semanticweb.owlapi.model.MissingImportListener;
+import org.semanticweb.owlapi.model.OWLAxiom;
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -104,11 +122,41 @@ public class ReasoningServiceTaskResourc
 		return Response.ok(new Viewable("index", this), TEXT_HTML).build();
 	}
 
+	private boolean isHTML(HttpHeaders headers) {
+		// We only want to state if HTML format is the preferred format
+		// requested
+		Set<String> htmlformats = new HashSet<String>();
+		htmlformats.add(TEXT_HTML);
+		Set<String> rdfformats = new HashSet<String>();
+		String[] formats = { TEXT_HTML, "text/plain", KRFormat.RDF_XML,
+				KRFormat.TURTLE, "text/turtle", "text/n3" };
+		rdfformats.addAll(Arrays.asList(formats));
+		List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
+		for (MediaType t : mediaTypes) {
+			String strty = t.toString();
+			log.info("Acceptable is {}", t);
+			if (htmlformats.contains(strty)) {
+				log.debug("Requested format is HTML {}", t);
+				return true;
+			} else if (rdfformats.contains(strty)) {
+				log.debug("Requested format is RDF {}", t);
+				return false;
+			}
+		}
+		// Default behavior? Should never happen!
+		return true;
+	}
+
 	@GET
 	@Produces({ TEXT_HTML, "text/plain", KRFormat.RDF_XML, KRFormat.TURTLE,
 			"text/turtle", "text/n3" })
 	public Response get(@QueryParam("url") String url,
 			@Context HttpHeaders headers) {
+
+		// If url param is missing, we produce the service welcome page
+		if (url == null) {
+			return Response.ok(new Viewable("index", this)).build();
+		}
 		log.info("Called GET on service {} to perform task {}", service, taskID);
 		log.info("on input url: {}", url);
 		//
@@ -116,25 +164,26 @@ public class ReasoningServiceTaskResourc
 			JenaReasoningService s = (JenaReasoningService) getCurrentService();
 
 			if (getCurrentTask().equals("check")) {
-				log.info("Task is 'check'");
+				log.debug("Task is 'check'");
 				boolean isConsistent;
 				isConsistent = s.isConsistent(ModelFactory.createDefaultModel()
 						.read(url));
 				if (isConsistent) {
-					log.info("Is consistent");
+					log.debug("The input is consistent");
 					return Response.ok().build();
 				} else {
-					log.info("Is not consistent");
+					log.debug("The input is not consistent");
 					return Response.status(Status.NO_CONTENT).build();
 				}
 			}
 
 			Set<Statement> result = null;
 			if (getCurrentTask().equals("classify")) {
+				log.debug("Task is 'classify'");
 				result = s
 						.classify(ModelFactory.createDefaultModel().read(url));
 			} else if (getCurrentTask().equals("enrich")) {
-				log.info("Task is: 'enrich'");
+				log.debug("Task is: 'enrich'");
 				result = s.enrich(ModelFactory.createDefaultModel().read(url));
 			}
 			if (result == null) {
@@ -144,35 +193,92 @@ public class ReasoningServiceTaskResourc
 			log.info("Returning {} statements", result.size());
 			Model outputModel = ModelFactory.createDefaultModel();
 			outputModel.add(result.toArray(new Statement[result.size()]));
-			
-			// We only want to state if HTML format is the preferred format
-			// requested
-			Set<String> htmlformats = new HashSet<String>();
-			htmlformats.add(TEXT_HTML);
-			Set<String> rdfformats = new HashSet<String>();
-			String[] formats = { TEXT_HTML, "text/plain", KRFormat.RDF_XML, KRFormat.TURTLE,
-					"text/turtle", "text/n3" };
-			rdfformats.addAll(Arrays.asList(formats));
-			List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
-			for (MediaType t : mediaTypes) {
-				String strty = t.toString();
-				log.info("Acceptable is {}", t);
-				if (htmlformats.contains(strty)) {
-					log.info("EQUAL!!! is {}", t);
-					return Response.ok(
-							new Viewable("jena-model",
-									new JenaModelWriter().toStream(outputModel,
-											"text/n3")), TEXT_HTML).build();
-				}else if(rdfformats.contains(strty)){
-					return Response.ok(outputModel).build();					
-				}
+
+			if (isHTML(headers)) {
+
+				ByteArrayOutputStream out = new ByteArrayOutputStream();
+				outputModel.write(out, "TURTLE");
+				return Response.ok(
+						new Viewable("result",
+								new ReasoningPrettyResultResource(context,
+										uriInfo, out)), TEXT_HTML).build();
+			} else {
+				return Response.ok(outputModel).build();
 			}
 
 		} else if (getCurrentService() instanceof OWLApiReasoningService) {
-			// TODO
-			throw new WebApplicationException(new Exception(
-					"Unsupported implementation"),
-					Response.Status.INTERNAL_SERVER_ERROR);
+			OWLApiReasoningService s = (OWLApiReasoningService) getCurrentService();
+			OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
+			// Listening for missing imports
+			manager.addMissingImportListener(new MissingImportListener() {
+				@Override
+				public void importMissing(MissingImportEvent arg0) {
+					log.warn("Missing import: {}",
+							arg0.getImportedOntologyURI());
+				}
+			});
+			OWLOntology input = null;
+			try {
+				input = manager.loadOntologyFromOntologyDocument(IRI
+						.create(url));
+			} catch (OWLOntologyCreationIOException e) {
+				throw new WebApplicationException(e,
+						Response.Status.NOT_FOUND);
+			} catch (OWLOntologyCreationException e) {
+				throw new WebApplicationException(e,
+						Response.Status.INTERNAL_SERVER_ERROR);
+			}
+			if (getCurrentTask().equals("check")) {
+				log.debug("Task is 'check'");
+				boolean isConsistent;
+
+				try {
+					isConsistent = s.isConsistent(input);
+					if (isConsistent) {
+						log.debug("The input is consistent");
+						return Response.ok().build();
+					} else {
+						log.debug("The input is not consistent");
+						return Response.status(Status.NO_CONTENT).build();
+					}
+				} catch (ReasoningServiceException e) {
+					throw new WebApplicationException(e,
+							Response.Status.INTERNAL_SERVER_ERROR);
+				}
+			}
+			try {
+				OWLOntology output = manager.createOntology();
+				if (getCurrentTask().equals("classify")) {
+					log.debug("Task is 'classify'");
+					manager.addAxioms(output, s.classify(input));
+				} else if (getCurrentTask().equals("enrich")) {
+					log.debug("Task is 'enrich'");
+					manager.addAxioms(output, s.enrich(input));
+				}
+				if (isHTML(headers)) {
+					ByteArrayOutputStream out = new ByteArrayOutputStream();
+					manager.saveOntology(output,
+							new ManchesterOWLSyntaxOntologyFormat(), out);
+					return Response.ok(
+							new Viewable("result",
+									new ReasoningPrettyResultResource(context,
+											uriInfo, out)), TEXT_HTML).build();
+				} else {
+					return Response.ok(output).build();
+				}
+			} catch (ReasoningServiceException e) {
+				throw new WebApplicationException(e,
+						Response.Status.INTERNAL_SERVER_ERROR);
+			} catch (InconsistentInputException e) {
+				log.debug("The input is not consistent");
+				return Response.status(Status.NO_CONTENT).build();
+			} catch (OWLOntologyCreationException e) {
+				throw new WebApplicationException(e,
+						Response.Status.INTERNAL_SERVER_ERROR);
+			} catch (OWLOntologyStorageException e) {
+				throw new WebApplicationException(e,
+						Response.Status.INTERNAL_SERVER_ERROR);
+			}
 		}
 		throw new WebApplicationException(new Exception(
 				"Unsupported implementation"),

Modified: incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl?rev=1160609&r1=1160608&r2=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/index.ftl
Tue Aug 23 10:40:29 2011
@@ -19,17 +19,14 @@
 <@common.page title="Apache Stanbol Reasoners: Service /${it.currentService.path}/${it.currentTask}"
hasrestapi=false> 
 		
  <div class="panel" id="webview">
-	<p><em>Service type:</em> ${it.currentService.class.name}</p>
-	<p><em>Path:</em> ${it.currentService.path}</p>
-	<p><em>Task:</em> ${it.currentTask}</p>
+	<p><b>Service type:</b> ${it.currentService.class.name}</p>
+	<p><b>Path:</b> ${it.currentService.path}</p>
+	<p><b>Task:</b> ${it.currentTask}</p>
+	
+	<p><em>To test the service, you can send a URL</em></p>
+	<form method="GET">
+	<p><b>URL:</b> <input type="text" name="url" size="80"/> <input
type="submit" value="Send"/></p>
+	</form>
  </div>
-
-    <#-- We disable this at the moment -->
-    <!--
-    <div class="panel" id="restapi" style="display: none;">
-          
-    </div>
-    -->
-
   </@common.page>
 </#escape>
\ No newline at end of file

Copied: incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl
(from r1160332, incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl?p2=incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl&p1=incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl&r1=1160332&r2=1160609&rev=1160609&view=diff
==============================================================================
--- incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/jena-model.ftl
(original)
+++ incubator/stanbol/branches/jena-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource/result.ftl
Tue Aug 23 10:40:29 2011
@@ -14,13 +14,15 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
+<#import "/imports/common.ftl" as common>
 <#escape x as x?html>
-<html>
-<head></head>
-<body>
+<@common.page title="Apache Stanbol Reasoners: Result" hasrestapi=false> 
+		
+ <div class="panel">
 <pre>
-${it}
+${it.result}
 </pre>
-</body>
-</html>
+ </div>
+
+  </@common.page>
 </#escape>
\ No newline at end of file



Mime
View raw message