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/03/04 16:50:51 UTC

svn commit: r1078019 - /incubator/stanbol/trunk/kres/eu.iksproject.kres.semion.refactorer/src/main/java/eu/iksproject/kres/semion/refactorer/SemionRefactorerImpl.java

Author: anuzzolese
Date: Fri Mar  4 15:50:50 2011
New Revision: 1078019

URL: http://svn.apache.org/viewvc?rev=1078019&view=rev
Log:
STANBOL-108 Modified Semion Refactorer in order to use the new rule language for graph refactoring.

Modified:
    incubator/stanbol/trunk/kres/eu.iksproject.kres.semion.refactorer/src/main/java/eu/iksproject/kres/semion/refactorer/SemionRefactorerImpl.java

Modified: incubator/stanbol/trunk/kres/eu.iksproject.kres.semion.refactorer/src/main/java/eu/iksproject/kres/semion/refactorer/SemionRefactorerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/kres/eu.iksproject.kres.semion.refactorer/src/main/java/eu/iksproject/kres/semion/refactorer/SemionRefactorerImpl.java?rev=1078019&r1=1078018&r2=1078019&view=diff
==============================================================================
--- incubator/stanbol/trunk/kres/eu.iksproject.kres.semion.refactorer/src/main/java/eu/iksproject/kres/semion/refactorer/SemionRefactorerImpl.java (original)
+++ incubator/stanbol/trunk/kres/eu.iksproject.kres.semion.refactorer/src/main/java/eu/iksproject/kres/semion/refactorer/SemionRefactorerImpl.java Fri Mar  4 15:50:50 2011
@@ -12,6 +12,7 @@ import org.apache.clerezza.rdf.core.acce
 import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
 import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
 import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.core.sparql.NoQueryEngineException;
 import org.apache.clerezza.rdf.core.sparql.ParseException;
 import org.apache.clerezza.rdf.core.sparql.QueryParser;
 import org.apache.clerezza.rdf.core.sparql.query.ConstructQuery;
@@ -38,7 +39,12 @@ import com.hp.hpl.jena.query.Query;
 import com.hp.hpl.jena.query.QueryExecution;
 import com.hp.hpl.jena.query.QueryExecutionFactory;
 import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.query.Syntax;
 import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.sparql.function.FunctionRegistry;
+import com.hp.hpl.jena.sparql.pfunction.PropertyFunctionRegistry;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import com.hp.hpl.jena.update.UpdateAction;
 
 import eu.iksproject.kres.api.manager.DuplicateIDException;
 import eu.iksproject.kres.api.manager.KReSONManager;
@@ -61,6 +67,10 @@ import eu.iksproject.kres.api.semion.Sem
 import eu.iksproject.kres.api.semion.SemionRefactoringException;
 import eu.iksproject.kres.api.semion.util.URIGenerator;
 import eu.iksproject.kres.api.storage.OntologyStorage;
+import eu.iksproject.kres.rules.arqextention.CreatePropertyURIStringFromLabel;
+import eu.iksproject.kres.rules.arqextention.CreateStandardLabel;
+import eu.iksproject.kres.rules.arqextention.CreateURI;
+import eu.iksproject.kres.shared.transformation.JenaToClerezzaConverter;
 import eu.iksproject.kres.shared.transformation.JenaToOwlConvert;
 import eu.iksproject.kres.shared.transformation.OWLAPIToClerezzaConverter;
 
@@ -340,6 +350,12 @@ public class SemionRefactorerImpl implem
 			
 		semionManager.registerRefactorer(this);
 		
+		
+		PropertyFunctionRegistry.get().put("http://www.stlab.istc.cnr.it/semion/function#createURI", CreateURI.class);
+		FunctionRegistry.get().put("http://www.stlab.istc.cnr.it/semion/function#createLabel", CreateStandardLabel.class);
+		FunctionRegistry.get().put("http://www.stlab.istc.cnr.it/semion/function#propString", CreatePropertyURIStringFromLabel.class);
+		
+		
 		log.info("Activated KReS Semion Refactorer");
 	}
 	
@@ -699,57 +715,38 @@ public class SemionRefactorerImpl implem
 			for(KReSRule kReSRule : kReSRuleList){
 				String sparql = kReSRule.toSPARQL();
 				log.info("SPARQL : "+sparql);
-				//Query sparqlQuery = QueryFactory.create(sparql);
 				
-				// QueryExecution qexec =
-				// QueryExecutionFactory.create(sparqlQuery, ontModel) ;
-				//Model refactoredModel = qexec.execConstruct();
-			
-				ConstructQuery constructQuery;
-				try {
-					constructQuery = (ConstructQuery) QueryParser.getInstance()
-							.parse(sparql);
-					Graph constructedGraph = tcManager.executeSparqlQuery(
-							constructQuery, mGraph);
-					unionMGraph.addAll(constructedGraph);
-				} catch (ParseException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
+				Graph constructedGraph = null;
+				
+				switch (kReSRule.getExpressiveness()) {
+				case KReSCore:
+					constructedGraph = kReSCoreOperation(sparql, mGraph);
+					break;
+				case ForwardChaining:
+					constructedGraph = forwardChainingOperation(sparql, mGraph);
+					break;
+				case Reflexive:
+					constructedGraph = kReSCoreOperation(sparql, unionMGraph);
+					break;
+				case SPARQLConstruct:
+					constructedGraph = kReSCoreOperation(sparql, mGraph);
+					break;
+				case SPARQLDelete:
+					constructedGraph = sparqlUpdateOperation(sparql, unionMGraph);
+					break;
+				case SPARQLDeleteData:
+					constructedGraph = sparqlUpdateOperation(sparql, unionMGraph);
+					break;
+				default:
+					break;
 				}
 				
-				/*
-				 * OWLOntology refactoredDataSet =
-				 * jenaToOwlConvert.ModelJenaToOwlConvert(refactoredModel,
-				 * "RDF/XML");
-				 * 
-				 * ByteArrayOutputStream out = new ByteArrayOutputStream(); try
-				 * { ontologyManager.saveOntology(refactoredDataSet, new
-				 * RDFXMLOntologyFormat(), out); } catch
-				 * (OWLOntologyStorageException e) { // TODO Auto-generated
-				 * catch block e.printStackTrace(); }
-				 * 
-				 * ByteArrayInputStream in = new
-				 * ByteArrayInputStream(out.toByteArray());
-				 * 
-				 * try { ontologyManager2.loadOntologyFromOntologyDocument(in);
-				 * } catch (OWLOntologyCreationException e) { // TODO
-				 * Auto-generated catch block e.printStackTrace(); }
-				*/
+				
+				if(constructedGraph != null){
+					unionMGraph.addAll(constructedGraph);
+				}
 				
 			}
-			
-			/*
-			 * OWLOntologyMerger merger = new
-			 * OWLOntologyMerger(ontologyManager2);
-			 * 
-			 * try { IRI defaultOntologyIRI =
-			 * IRI.create("http://kres.iksproject.eu/semion/autoGeneratedOntology"
-			 * ); refactoredOntology =
-			 * merger.createMergedOntology(ontologyManager, defaultOntologyIRI);
-			 * 
-			 * } catch (OWLOntologyCreationException e) { // TODO Auto-generated
-			 * catch block e.printStackTrace(); }
-			 */
 				
 			refactoredOntology = OWLAPIToClerezzaConverter
 					.clerezzaMGraphToOWLOntology(unionMGraph);
@@ -768,5 +765,54 @@ public class SemionRefactorerImpl implem
 			return refactoredOntology;
 		}
 	}
+	
+	
+	
+	private Graph kReSCoreOperation(String query, MGraph mGraph){
+		
+		/*
+		
+		Graph constructedGraph = null;
+		try {
+			ConstructQuery constructQuery = (ConstructQuery) QueryParser.getInstance()
+			.parse(query);
+			constructedGraph = tcManager.executeSparqlQuery(
+					constructQuery, mGraph);
+			
+		} catch (ParseException e) {
+			log.error(e.getMessage());
+		} catch (NoQueryEngineException e) {
+			log.error(e.getMessage());
+		}
+		
+		return constructedGraph;
+		*/
+		
+		
+		Model model = JenaToClerezzaConverter.clerezzaMGraphToJenaModel(mGraph);
+		
+		Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ);
+		QueryExecution qexec = QueryExecutionFactory.create(sparqlQuery, model) ;
+		
+		return JenaToClerezzaConverter.jenaModelToClerezzaMGraph(qexec.execConstruct()).getGraph();
+		
+		
+	}
+	
+	
+	private Graph forwardChainingOperation(String query, MGraph mGraph){
+		
+		Graph graph = kReSCoreOperation(query, mGraph);
+		
+		mGraph.addAll(graph);
+		
+		return graph;
+	}
+	
+	private Graph sparqlUpdateOperation(String query, MGraph mGraph){
+		Model model = JenaToClerezzaConverter.clerezzaMGraphToJenaModel(mGraph);
+		UpdateAction.parseExecute(query, model);
+		return JenaToClerezzaConverter.jenaModelToClerezzaMGraph(model).getGraph();
+	}
 
 }