Strabon

changeset 694:db4d98ff0273 temporals

merge (the wrong way :D)
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Wed Nov 07 19:00:40 2012 +0200 (2012-11-07)
parents de41d6c00d3b 5850eff37208
children cdd58b62bc61
files
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Nov 06 19:35:33 2012 +0200
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Nov 07 19:00:40 2012 +0200
     1.3 @@ -276,38 +276,51 @@
     1.4  		return status;
     1.5  	}
     1.6  
     1.7 -	private String queryRewriting(String oldQueryString) 
     1.8 +	private String queryRewriting(String queryString) 
     1.9  	{	
    1.10  		//TODO
    1.11  		String newQueryString="";
    1.12  		int numOfQuadruples=0;
    1.13  		int startIndex=0;
    1.14  		
    1.15 +		//remove comments from query
    1.16 +		String REGEX = "((^(\\s)*#)|((\\s)+#)).*$";
    1.17 +		Pattern pattern = Pattern.compile(REGEX, Pattern.MULTILINE);							
    1.18 +		Matcher matcher = pattern.matcher(queryString);
    1.19 +		String oldQueryString=matcher.replaceAll("");
    1.20 +
    1.21 +		
    1.22  		// check whether the query contains quadruples
    1.23  		String URI = "[\\w?/<>^#]+";
    1.24 -		String REGEX = "("+URI+"(\\s)+){3}"+URI+"(\\s)*[.}]{1}";
    1.25 -		Pattern pattern = Pattern.compile(REGEX, Pattern.DOTALL);							
    1.26 -		Matcher matcher = pattern.matcher(oldQueryString);
    1.27 +		REGEX = "("+URI+"(\\s)+){3}"+URI+"(\\s)*[.}]{1}";
    1.28 +		pattern = Pattern.compile(REGEX, Pattern.MULTILINE);							
    1.29 +		matcher = pattern.matcher(oldQueryString);
    1.30  		
    1.31  		while(matcher.find())		
    1.32  		{
    1.33 +			String quadruple=oldQueryString.substring(matcher.start(), matcher.end());
    1.34  			numOfQuadruples++;
    1.35 +			
    1.36  			newQueryString+=oldQueryString.substring(startIndex, matcher.start());
    1.37  			startIndex=matcher.end();
    1.38 +
    1.39 +			//tokenize quadruples and convert them to triples:
    1.40 +			//s p o c  --becomes--> GRAPH ?g(numOfQuadruples) {s p o}
    1.41 +			//                      ?g(numOfQuadruples) strdf:hasValidTime c
    1.42 +			String[] token = quadruple.split("(\\s)+");
    1.43 +			newQueryString+="\n GRAPH ?g"+numOfQuadruples+" { " +token[0]+" "+token[1]+" "+token[2]+" .}\n";
    1.44 +			newQueryString+="?g"+numOfQuadruples+" strdf:hasValidTime "+ token[3];
    1.45  			
    1.46 -			String quadruple=oldQueryString.substring(matcher.start(), matcher.end());
    1.47  
    1.48 -
    1.49 -			String[] token = quadruple.split("(\\s)+");
    1.50 -			
    1.51 -			newQueryString+="\n GRAPH ?g"+numOfQuadruples+" {" +token[0]+" "+token[1]+" "+token[2]+" .}\n";
    1.52 -			newQueryString+="?g"+numOfQuadruples+" strdf:hasValidTime "+ token[3];
    1.53 +			//case that the '.' or '}' has a '//s' character before.
    1.54 +			if(token.length==5)
    1.55 +				newQueryString+=token[4];
    1.56  		}
    1.57  		
    1.58  		if(numOfQuadruples==0)
    1.59  		{
    1.60  			logger.info("\n\nQuadruple not found\n\n");
    1.61 -			return oldQueryString;
    1.62 +			return queryString;
    1.63  		}
    1.64  		else
    1.65  		{