From 7959dd0fb7c86af2fc213c372379a2af0309554d Mon Sep 17 00:00:00 2001
From: Thinh Dong <dnnthinh@gmail.com>
Date: Fri, 14 Sep 2012 11:16:27 +0000
Subject: [PATCH] - modified Construct queries

---
 .../renderer/GraphPatternRendererVisitor.java | 24 +++++++++++++++----
 .../SPARQLConstructRendererVisitor.java       | 20 ++++++++++++----
 .../renderer/SPARQLSelectRendererVisitor.java |  4 ++--
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java
index 79c26bc4..a4ae50d6 100644
--- a/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java
+++ b/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java
@@ -60,6 +60,7 @@ import fr.inrialpes.exmo.align.impl.edoal.RelationDomainRestriction;
 import fr.inrialpes.exmo.align.impl.edoal.RelationId;
 import fr.inrialpes.exmo.align.impl.edoal.Transformation;
 import fr.inrialpes.exmo.align.impl.edoal.Value;
+import fr.inrialpes.exmo.align.impl.edoal.ValueExpression;
 import fr.inrialpes.exmo.align.parser.SyntaxElement.Constructor;
 
 /**
@@ -294,6 +295,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
     public void visit( final ClassTypeRestriction c ) throws AlignmentException {	
     	String str = "";
     	datatype = "";
+    	inClassRestriction = true;
     	flagRestriction = 1;
     	c.getRestrictionPath().accept( this );
     	flagRestriction = 0;
@@ -316,9 +318,11 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
 			strBGP_Weaken += str;
 		}
 		objectsRestriction.clear();
+		inClassRestriction = false;
     }
 
     public void visit( final ClassDomainRestriction c ) throws AlignmentException {					
+    	inClassRestriction = true;
     	flagRestriction = 1;
     	c.getRestrictionPath().accept( this );
     	flagRestriction = 0;
@@ -328,6 +332,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
 		}
     	c.getDomain().accept( this );    	
     	objectsRestriction.clear();
+    	inClassRestriction = false;
     }
 
     public void visit( final ClassOccurenceRestriction c ) throws AlignmentException {
@@ -463,6 +468,10 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
 			    if( size != 0 && valueRestriction == null ){
 			    	obj = "?o" + ++count;			    			    	
 			    }
+			    if ( !strBGP_Weaken.equals("") && !inClassRestriction ) {
+			    	listBGP.add(strBGP_Weaken);
+			    	strBGP_Weaken = "";
+			    }
 			}		
 		}
 		obj = "?o" + ++count;    	
@@ -475,10 +484,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
     	flagRestriction = 1;
 		c.getValue().accept( this );
 		flagRestriction = 0;
-		if ( uriType != null && uriType.equals("") ) {
-			uriType = "string";
-		}
-    	if ( c.getComparator().getURI().equals( Comparator.EQUAL.getURI() ) ) {    		
+  		if ( c.getComparator().getURI().equals( Comparator.EQUAL.getURI() ) ) {    		
     		str = "FILTER (xsd:" + uriType + "(" + obj + ") = ";    		
     	}
     	else if ( c.getComparator().getURI().equals( Comparator.GREATER.getURI() ) ) {    		
@@ -544,7 +550,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
 		    }
 		    if( valueRestriction != null && !inClassRestriction && op != Constructor.COMP && flagRestriction == 1 )			    
 					obj = valueRestriction.toString();
-		    if ( flagRestriction == 1 && inClassRestriction )
+		    if ( flagRestriction == 1 && inClassRestriction && op != Constructor.COMP )
 					objectsRestriction.add(obj);
 	    	
 		    strBGP += " " + obj + " ." + NL;
@@ -663,6 +669,10 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
 			    if ( size != 0 && valueRestriction == null ) {
 			    	obj = "?o" + ++count;			    			    	
 			    }
+			    if ( !strBGP_Weaken.equals("") && !inClassRestriction ) {
+			    	listBGP.add(strBGP_Weaken);
+			    	strBGP_Weaken = "";
+			    }
 			}		
 		}
 		obj = "?o" + ++count;    	
@@ -711,6 +721,10 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito
 	    	uriType = str.substring( index+1 );
     	}
     	value = e.getValue();
+    	if ( uriType != null && uriType.equals("") ) {
+    		uriType = "string";
+    	}
+    	
     }
 	
     public void visit( final Apply e ) throws AlignmentException {}
diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java
index b203bf84..cfe2acb3 100644
--- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java
+++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java
@@ -37,6 +37,7 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
 
 public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor implements AlignmentVisitor{
 
@@ -124,7 +125,7 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor
     		listGP2 = new ArrayList<String>(getBGP());
     		    		
     		if( !GP1.contains("UNION") && !GP1.contains("FILTER") ){
-    			for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) {
+    			for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) {
         			String k = (String)e.nextElement();
         			query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL;
         		}
@@ -196,10 +197,12 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor
 				}			   	
 			}
 			query="";
+			query_weaken = "";
+			query_IgnoreErrors = "";
     		tmp = "";
-		/*
+		
     	if( !GP2.contains("UNION") && !GP2.contains("FILTER") ){
-    			for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) {
+    			for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) {
         			String k = (String)e.nextElement();
         			query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL;
         		}
@@ -210,6 +213,13 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor
 			    query += GP1;    	    		
 			    query += "}"+NL;
 			    query_weaken = query;
+			    content_Corese += "<rule>" + NL;
+			    content_Corese += "<body>" + NL;
+			    content_Corese += "<![CDATA[" + NL;
+			    content_Corese += query;
+			    content_Corese += "]]>" + NL;
+			    content_Corese += "</body>" + NL;
+			    content_Corese += "</rule>" + NL + NL;
     		} else {    			
     			Iterator<String> list = listGP2.iterator();
     			while ( list.hasNext() ) {
@@ -241,7 +251,7 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor
 		    query_IgnoreErrors += "WHERE {"+NL;
 		    query_IgnoreErrors += GP1;    	    		
 		    query_IgnoreErrors += "}"+NL;		    
-		
+		    if ( corese ) return;
 			if( split ) {
 				if ( ignoreerrors ) {
 					createQueryFile( splitdir, query_IgnoreErrors );
@@ -263,7 +273,7 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor
 					writer.println( query );
 				}			   	
 			}
-			*/	       		    	
+			    		    	
     	}
 	}
 
diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java
index ab2cbe74..899d91fe 100644
--- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java
+++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java
@@ -88,7 +88,7 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp
 	 	resetVariables("s", "o");
 		((Expression)(cell.getObject2())).accept( this );
 	 	GP2 = getGP();
-		for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) {
+		for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) {
    		    String k = (String)e.nextElement();
 	   		query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL;
 		}
@@ -101,7 +101,7 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp
 			writer.println(query);
 		}	    		
 	    query="";
-	    for ( Enumeration e = prefixList.keys() ; e.hasMoreElements(); ) {
+	    for ( Enumeration<String> e = prefixList.keys() ; e.hasMoreElements(); ) {
     	    String k = (String)e.nextElement();
     	    query += "PREFIX "+prefixList.get(k)+":<"+k+">"+NL;
 	    }
-- 
GitLab