You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by an...@apache.org on 2011/04/22 11:06:00 UTC

svn commit: r1095896 - /incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java

Author: anuzzolese
Date: Fri Apr 22 09:05:59 2011
New Revision: 1095896

URL: http://svn.apache.org/viewvc?rev=1095896&view=rev
Log:
STANBOL-181 Added a new sercice in the REST interface of the Refactor.
The service is reachable in POST at the path http://%STANBOL-HOME%/rules/refactor/apply and apply "on the fly" a recipe passed as a string argument containing rules to the second argument which is the InputStream of the RDF graph to transform.

Modified:
    incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java

Modified: incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java?rev=1095896&r1=1095895&r2=1095896&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java (original)
+++ incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/resources/RefactorerResource.java Fri Apr 22 09:05:59 2011
@@ -19,6 +19,11 @@ import org.apache.stanbol.commons.web.ba
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
 import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
 import org.apache.stanbol.rules.base.api.NoSuchRecipeException;
+import org.apache.stanbol.rules.base.api.Recipe;
+import org.apache.stanbol.rules.base.api.util.RuleList;
+import org.apache.stanbol.rules.manager.KB;
+import org.apache.stanbol.rules.manager.changes.RecipeImpl;
+import org.apache.stanbol.rules.manager.parse.RuleParserImpl;
 import org.apache.stanbol.rules.refactor.api.Refactorer;
 import org.apache.stanbol.rules.refactor.api.RefactoringException;
 import org.semanticweb.owlapi.apibinding.OWLManager;
@@ -93,9 +98,74 @@ public class RefactorerResource extends 
         }
 
     }
+    
+    
+    /**
+     * The apply mode allows the client to compose a recipe, by mean of string containg the rules, and
+     * apply it "on the fly" to the graph in input.
+     * 
+     * @param recipe String
+     * @param input InputStream
+     * @return a Response containing the transformed graph
+     */
+    @POST
+    @Path("/apply")
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Produces(value = {KRFormat.TURTLE, KRFormat.FUNCTIONAL_OWL, KRFormat.MANCHESTER_OWL, KRFormat.RDF_XML,
+                       KRFormat.OWL_XML, KRFormat.RDF_JSON})
+    public Response applyRefactoring(@FormParam("recipe") String recipe,
+                                       @FormParam("input") InputStream input) {
+
+        // Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
+
+
+    	KB kb = RuleParserImpl.parse(recipe);
+    	
+    	if(kb != null){
+    		
+    		RuleList ruleList = kb.getkReSRuleList();
+    		if(ruleList != null){
+		    	Recipe actualRecipe = new RecipeImpl(null, null, ruleList);
+		    	
+		    	
+		        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
+		        OWLOntology inputOntology;
+		        try {
+		            inputOntology = manager.loadOntologyFromOntologyDocument(input);
+		
+		            OWLOntology outputOntology;
+		            try {
+		                outputOntology = semionRefactorer.ontologyRefactoring(inputOntology, actualRecipe);
+		            } catch (RefactoringException e) {
+		                e.printStackTrace();
+		                return Response.status(500).build();
+		            } catch (NoSuchRecipeException e) {
+		                return Response.status(204).build();
+		            }
+		
+		            return Response.ok(outputOntology).build();
+		        } catch (OWLOntologyCreationException e) {
+		            e.printStackTrace();
+		            return Response.status(404).build();
+		        }
+    		}
+    		else{
+    			/**
+    			 * TODO
+    			 * ADD A RESPONSE FOR THIS CASE
+    			 */
+    		}
+    	}
+    	else{
+			/**
+			 * TODO
+			 * ADD A RESPONSE FOR THIS CASE
+			 */
+		}
+
+    }
 
     @GET
-    @Path("/lazy")
     public Response performRefactoringLazyCreateGraph(@QueryParam("recipe") String recipe,
                                                       @QueryParam("input-graph") String inputGraph,
                                                       @QueryParam("output-graph") String outputGraph) {