Strabon

changeset 1534:972615e500b7 temporals

fixed bug #83
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Tue Mar 28 18:17:53 2017 +0300 (20 months ago)
parents a6383a84d195
children ce70b9286f2c
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/utils.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/utils.java	Thu Sep 22 16:53:28 2016 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/utils.java	Tue Mar 28 18:17:53 2017 +0300
     1.3 @@ -14,10 +14,12 @@
     1.4  
     1.5  package eu.earthobservatory.runtime.generaldb;
     1.6  
     1.7 +import java.util.ArrayList;
     1.8  import java.util.Hashtable;
     1.9  import java.util.regex.Matcher;
    1.10  import java.util.regex.Pattern;
    1.11  
    1.12 +import org.eclipse.emf.ecore.EValidator.PatternMatcher;
    1.13  import org.openrdf.model.Resource;
    1.14  import org.slf4j.Logger;
    1.15  import org.slf4j.LoggerFactory;
    1.16 @@ -29,7 +31,7 @@
    1.17  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.generaldb.Strabon.class);
    1.18  	
    1.19  	public static String queryRewriting(String queryString) 
    1.20 -	{
    1.21 +	{	
    1.22  		String newQueryString="";
    1.23  		int numOfQuadruples=0;
    1.24  		int startIndex=0;
    1.25 @@ -39,6 +41,20 @@
    1.26  		StringBuffer whereClauses = new StringBuffer(2048);
    1.27  		NQuadsParser parser = new NQuadsParser();
    1.28  		
    1.29 +		String Prefix = "(Prefix[\\s]*)(.*)(:[\\s]*)(<>)";
    1.30 +		String prefix = "([\\s]*(Prefix)\\s*(.*):\\s(<http://strdf.di.uoa.gr/[^>]*)>)";
    1.31 +		
    1.32 +		Pattern prefixpattern = Pattern.compile(prefix, Pattern.CASE_INSENSITIVE);
    1.33 +		
    1.34 +		Matcher prefixmatcher = prefixpattern.matcher(queryString);
    1.35 +		String strdfprefix = null, strdf = null;
    1.36 +		
    1.37 +		while(prefixmatcher.find()){
    1.38 +			strdfprefix = prefixmatcher.group(3);
    1.39 +			strdf = prefixmatcher.group(4);
    1.40 +
    1.41 +        }
    1.42 +		
    1.43  		try
    1.44  		{
    1.45  			String graphVariable="?g"+(int)(Math.random()*10000);
    1.46 @@ -60,7 +76,8 @@
    1.47  			//check whether the query contains quadruples	
    1.48  			String Word="((\\w)|(\\p{InGreek})|-)+";
    1.49  			String URI="(<([\\S-])*>)|("+Word+":"+Word+")";
    1.50 -			String Literal="\".*\"(\\^\\^"+URI+")?";
    1.51 +			String Literal="\"[^\"]*\"(\\^{2}("+URI+"))?";
    1.52 +			String Malakia = "\"[^\"]*\"(\\^{2}(" + URI + "))?";
    1.53  			String Variable="\\?"+Word;
    1.54  			
    1.55  			String SPOT="(("+URI+")|("+Literal+")|("+Variable+"))";
    1.56 @@ -70,6 +87,8 @@
    1.57  			pattern = Pattern.compile(REGEX, Pattern.DOTALL);							
    1.58  			matcher = pattern.matcher(oldQueryString);
    1.59  			
    1.60 +
    1.61 +			
    1.62  			Pattern updatePattern = Pattern.compile(updateREGEX, Pattern.DOTALL);
    1.63  			Matcher updateMatcher =  updatePattern.matcher(oldQueryString);
    1.64  			
    1.65 @@ -108,13 +127,35 @@
    1.66  				 * insert data {graph <g> {s p o} }
    1.67  				 * 
    1.68  				 */
    1.69 -				String[] token = quadruple.split("(\\s)+");
    1.70 -	
    1.71 +				//String[] token = quadruple.split("(\\s)+");
    1.72 +				String regy = "(\"){1}[^\"]*(\"){1}";
    1.73 +			    Pattern pat = Pattern.compile(SPOT); 
    1.74 +		        Matcher mat = pat.matcher(quadruple);
    1.75 +		        
    1.76 +		        String[] token = new String[4];
    1.77 +		        
    1.78 +		        int i=0;
    1.79 +		        
    1.80 +		        while(mat.find()){
    1.81 +		        	token[i] = mat.group(0);
    1.82 +		        	i++;
    1.83 +		        }
    1.84 +		      
    1.85 +		        
    1.86  				
    1.87 -				int i=3;
    1.88 +				i=3;
    1.89  				if(!isVar(token[3]) && inWhere==false) //the forth element is a literal representation of valid time
    1.90  				{
    1.91 -					String tgraph =  "<"+parser.createValidTimeURI(token[3]).toString()+">";
    1.92 +					String temporaltoken = null, tgraph = null;
    1.93 +					
    1.94 +					if(strdfprefix != null){
    1.95 +						temporaltoken= token[3].replace(strdfprefix + ":", strdf) + ">";
    1.96 +						tgraph = parser.createValidTimeURI(temporaltoken+">")+">";
    1.97 +					}
    1.98 +					else{
    1.99 +						temporaltoken = token[3].toString();
   1.100 +					}
   1.101 +					tgraph =  "<"+parser.createValidTimeURI(temporaltoken)+">";
   1.102  					newQueryString+="\n GRAPH "+tgraph+" { " +token[0]+" "+token[1]+" "+token[2]+" .}\n";
   1.103  					newQueryString+= tgraph+" "+ TemporalConstants.VALID_TIME_PROPERTY;
   1.104  					i=3;
   1.105 @@ -123,7 +164,6 @@
   1.106  				else
   1.107  				{
   1.108  					String tgraph=null;
   1.109 -					//String addedPattern = graphVariable+numOfQuadruples+ " TemporalConstants.VALID_TIME_PROPERTY"+ token[3];
   1.110  					if(periodsAndGraphs.containsKey(token[3]))
   1.111  					{
   1.112  						tgraph = periodsAndGraphs.get(token[3]);