Strabon

changeset 687:13e41acf4964 temporals

strabon now supports query rewriting. (test-queries needed)
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Mon Nov 05 21:33:07 2012 +0200 (2012-11-05)
parents 68f4e9215b28
children 516dec652431 1abb80cb2a9a
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Nov 02 18:25:39 2012 +0200
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Mon Nov 05 21:33:07 2012 +0200
     1.3 @@ -230,7 +230,7 @@
     1.4  		
     1.5  		TupleQuery tupleQuery = null;
     1.6  		try {
     1.7 -			queryString = convertQueryToSparql(queryString);
     1.8 +			queryString = queryRewriting(queryString);
     1.9  			tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    1.10  			
    1.11  		} catch (RepositoryException e) {
    1.12 @@ -276,26 +276,45 @@
    1.13  		return status;
    1.14  	}
    1.15  
    1.16 -	private String convertQueryToSparql(String queryString) {
    1.17 -		
    1.18 +	private String queryRewriting(String oldQueryString) 
    1.19 +	{	
    1.20  		//TODO
    1.21  		String newQueryString="";
    1.22 +		int numOfQuadruples=0;
    1.23 +		int startIndex=0;
    1.24  		
    1.25 -		// check whether the query contains quadtruples
    1.26 -		String REGEX = ".*\\{.*([[a-z][A-Z][?/<>^#]]+(\\s)+){3}(\\s)*[.}(.})]?.*\\}.*";
    1.27 -		Pattern limitPattern = Pattern.compile(REGEX, Pattern.DOTALL);							
    1.28 -		Matcher limitMatcher = limitPattern.matcher(queryString);
    1.29 +		// check whether the query contains quadruples
    1.30 +		String URI = "[\\w?/<>^#]+";
    1.31 +		String REGEX = "("+URI+"(\\s)+){3}"+URI+"(\\s)*[.}]{1}";
    1.32 +		Pattern pattern = Pattern.compile(REGEX, Pattern.DOTALL);							
    1.33 +		Matcher matcher = pattern.matcher(oldQueryString);
    1.34  		
    1.35 -		if(limitMatcher.matches())		
    1.36 +		while(matcher.find())		
    1.37  		{
    1.38 -			logger.info("\n\nQUADRUPLE SPOTTED\n\n");
    1.39 +			numOfQuadruples++;
    1.40 +			newQueryString+=oldQueryString.substring(startIndex, matcher.start());
    1.41 +			startIndex=matcher.end();
    1.42 +			
    1.43 +			String quadruple=oldQueryString.substring(matcher.start(), matcher.end());
    1.44 +
    1.45 +
    1.46 +			String[] token = quadruple.split("(\\s)+");
    1.47 +			
    1.48 +			newQueryString+="\n GRAPH ?g"+numOfQuadruples+" {" +token[0]+" "+token[1]+" "+token[2]+" .}\n";
    1.49 +			newQueryString+="?g"+numOfQuadruples+" strdf:hasValidTime "+ token[3];
    1.50 +		}
    1.51 +		
    1.52 +		if(numOfQuadruples==0)
    1.53 +		{
    1.54 +			logger.info("\n\nQuadruple not found\n\n");
    1.55 +			return oldQueryString;
    1.56  		}
    1.57  		else
    1.58  		{
    1.59 -			logger.info("\n\nQUADRUPLE NOT SPOTTED\n\n");
    1.60 -			newQueryString=queryString;
    1.61 +			newQueryString+=oldQueryString.substring(startIndex);
    1.62 +			logger.info("\n\nNew QueryString:\n {}\n\n", newQueryString);		
    1.63 +			return newQueryString;
    1.64  		}
    1.65 -		return newQueryString;
    1.66  	}
    1.67  
    1.68