Strabon

changeset 1160:e6f71db0955e temporals

merged queryWriting and updateRewriting methods. Now the queryRewriting method exists only, which is for temporal updates and queries. It is now placed in under the "utils" class and not in the runtime.generaldb.Strabon class
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Wed May 08 20:51:29 2013 +0300 (2013-05-08)
parents 48fc6fd46980
children 1d3afe469324
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/utils.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/QueryRewritingTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalConstructTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalRelationTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalSelectionTests.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed May 08 20:26:55 2013 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed May 08 20:51:29 2013 +0300
     1.3 @@ -260,7 +260,8 @@
     1.4  		
     1.5  		TupleQuery tupleQuery = null;
     1.6  		try {
     1.7 -			queryString = queryRewriting(queryString);
     1.8 +			queryString = utils.queryRewriting(queryString);
     1.9 +			//queryString = queryRewriting(queryString);
    1.10  			tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    1.11  			
    1.12  		} catch (RepositoryException e) {
    1.13 @@ -308,7 +309,7 @@
    1.14  		return status;
    1.15  	}
    1.16  
    1.17 -	public String queryRewriting(String queryString) 
    1.18 +	/*public String queryRewriting(String queryString) 
    1.19  	{
    1.20  		String newQueryString="";
    1.21  		int numOfQuadruples=0;
    1.22 @@ -359,7 +360,7 @@
    1.23  				String[] token = quadruple.split("(\\s)+");
    1.24  	
    1.25  				newQueryString+="\n GRAPH "+graphVariable+numOfQuadruples+" { " +token[0]+" "+token[1]+" "+token[2]+" .}\n";
    1.26 -				newQueryString+=graphVariable+numOfQuadruples+" TemporalConstants.VALID_TIME_PROPERTY";
    1.27 +				newQueryString+=graphVariable+numOfQuadruples+TemporalConstants.VALID_TIME_PROPERTY;
    1.28  				
    1.29  				//add the rest tokens
    1.30  				for( int i=3; i<token.length; i++)
    1.31 @@ -409,14 +410,14 @@
    1.32  		
    1.33  	}
    1.34  
    1.35 -
    1.36 +*/
    1.37  	public void update(String updateString, SailRepositoryConnection con) throws MalformedQueryException 
    1.38  	{
    1.39  		Update update = null;
    1.40  
    1.41  		try {
    1.42  			
    1.43 -			String reWrittenUpdate = utils.updateRewriting(updateString);
    1.44 +			String reWrittenUpdate = utils.queryRewriting(updateString);
    1.45  			System.out.println("REWRITTEN UPDATE= "+ reWrittenUpdate);
    1.46  			
    1.47  			update = con.prepareUpdate(QueryLanguage.SPARQL, reWrittenUpdate);
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/utils.java	Wed May 08 20:26:55 2013 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/utils.java	Wed May 08 20:51:29 2013 +0300
     2.3 @@ -7,9 +7,9 @@
     2.4   *
     2.5   * http://www.strabon.di.uoa.gr/
     2.6   * 
     2.7 + * 
     2.8 + *  @author Panayiotis Smeros <psmeros@di.uoa.gr>
     2.9   *  @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
    2.10 - *
    2.11 - *
    2.12   */
    2.13  
    2.14  package eu.earthobservatory.runtime.generaldb;
    2.15 @@ -28,7 +28,7 @@
    2.16  	
    2.17  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.generaldb.Strabon.class);
    2.18  	
    2.19 -	public static String updateRewriting(String queryString) 
    2.20 +	public static String queryRewriting(String queryString) 
    2.21  	{
    2.22  		String newQueryString="";
    2.23  		int numOfQuadruples=0;
    2.24 @@ -55,7 +55,7 @@
    2.25  			Matcher matcher = pattern.matcher(queryString);
    2.26  			String oldQueryString=matcher.replaceAll("");
    2.27  			
    2.28 -			String updateREGEX= "(where([\\s])*\\{(.)*\\})";
    2.29 +			String updateREGEX= "((where([\\s])*\\{(.)*\\})|(WHERE([\\s])*\\{(.)*\\}))";
    2.30  	
    2.31  			//check whether the query contains quadruples	
    2.32  			String Word="((\\w)|(\\p{InGreek}))+";
     3.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/QueryRewritingTests.java	Wed May 08 20:26:55 2013 +0300
     3.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/QueryRewritingTests.java	Wed May 08 20:51:29 2013 +0300
     3.3 @@ -75,7 +75,7 @@
     3.4  				"FILTER(strdf:intersects(?geo1, ?geo2))."+
     3.5  				"}";
     3.6  		
     3.7 -		String [] querySplit=strabon.queryRewriting(query).split("GRAPH");		
     3.8 +		String [] querySplit=utils.queryRewriting(query).split("GRAPH");		
     3.9  		assertEquals(1, querySplit.length);
    3.10  	}
    3.11  	
    3.12 @@ -95,7 +95,7 @@
    3.13  			"FILTER(strdf:intersects(?geo1,?geo2))." +
    3.14  			"   FILTER(strdf:afterPeriod(?t1,?t2))}";	
    3.15  		
    3.16 -		String [] querySplit=strabon.queryRewriting(query).split("GRAPH");		
    3.17 +		String [] querySplit=utils.queryRewriting(query).split("GRAPH");		
    3.18  		assertEquals(3, querySplit.length);
    3.19  	}
    3.20  
    3.21 @@ -115,7 +115,7 @@
    3.22  			"FILTER(strdf:disjoint(?geo1,?geo2))" +
    3.23  			"FILTER(strdf:afterPeriod(?t1, ?t2)).";
    3.24  		
    3.25 -		String [] querySplit=strabon.queryRewriting(query).split("GRAPH");		
    3.26 +		String [] querySplit=utils.queryRewriting(query).split("GRAPH");		
    3.27  		assertEquals(3, querySplit.length);
    3.28  	}
    3.29  	
    3.30 @@ -132,7 +132,7 @@
    3.31  			"FILTER(strdf:PeriodOverlaps(?o1, \"[2012-11-19 12:41:00+02, 2012-11-19 13:41:00.000001+02]\"^^<http://strdf.di.uoa.gr/ontology#validTime> ))" +
    3.32  			"}";
    3.33  		
    3.34 -		String [] querySplit=strabon.queryRewriting(query).split("GRAPH");
    3.35 +		String [] querySplit=utils.queryRewriting(query).split("GRAPH");
    3.36  		assertEquals(2, querySplit.length);
    3.37  	}
    3.38  	
    3.39 @@ -150,7 +150,7 @@
    3.40  			"#FILTER(strdf:PeriodOverlaps(?o1, \"Now\"^^<http://strdf.di.uoa.gr/ontology#validTime> )) \n " +
    3.41  			"}";
    3.42  		
    3.43 -		String [] querySplit=strabon.queryRewriting(query).split("GRAPH");
    3.44 +		String [] querySplit=utils.queryRewriting(query).split("GRAPH");
    3.45  		assertEquals(2, querySplit.length);
    3.46  	}
    3.47  }
     4.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalConstructTests.java	Wed May 08 20:26:55 2013 +0300
     4.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalConstructTests.java	Wed May 08 20:51:29 2013 +0300
     4.3 @@ -91,7 +91,7 @@
     4.4  				"FILTER(strdf:PeriodOverlaps(?t1, ?t2) && str(?x1) != str(?x2))."+
     4.5  				"}";
     4.6  		
     4.7 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
     4.8 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
     4.9  		
    4.10  		for(String result: bindings)
    4.11  		{
    4.12 @@ -119,7 +119,7 @@
    4.13  				"FILTER(strdf:PeriodOverlaps(?t1, ?t2) && str(?x1) != str(?x2))."+
    4.14  				"}";
    4.15  		
    4.16 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    4.17 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    4.18  		
    4.19  		for(String result: bindings)
    4.20  		{
    4.21 @@ -145,7 +145,7 @@
    4.22  				"FILTER(strdf:during(?t1, ?t2) && str(?x1) != str(?x2))."+
    4.23  				"}";
    4.24  		
    4.25 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    4.26 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    4.27  		
    4.28  		for(String result: bindings)
    4.29  		{
    4.30 @@ -171,7 +171,7 @@
    4.31  				//"FILTER(strdf:during(?t1, ?t2) && str(?x1) != str(?x2))."+
    4.32  				"}";
    4.33  		
    4.34 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    4.35 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    4.36  		
    4.37  		for(String result: bindings)
    4.38  		{
    4.39 @@ -200,7 +200,7 @@
    4.40  				//"FILTER(strdf:during(?t1, ?t2) && str(?x1) != str(?x2))."+
    4.41  				"}";
    4.42  		
    4.43 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    4.44 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    4.45  		
    4.46  		for(String result: bindings)
    4.47  		{
     5.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalRelationTests.java	Wed May 08 20:26:55 2013 +0300
     5.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalRelationTests.java	Wed May 08 20:51:29 2013 +0300
     5.3 @@ -87,7 +87,7 @@
     5.4  				"FILTER(strdf:after(?t1, ?t2) && str(?x1) != str(?x2))."+
     5.5  				"}";
     5.6  		
     5.7 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
     5.8 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
     5.9  		
    5.10  		/*for(String result: bindings)
    5.11  		{
    5.12 @@ -139,8 +139,8 @@
    5.13  				"FILTER(strdf:before(?t1, ?t2) && ?x2!=?x1)."+
    5.14  				"}";
    5.15  		
    5.16 -		//TupleQueryResult result = (TupleQueryResult) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.17 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.18 +		//TupleQueryResult result = (TupleQueryResult) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.19 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.20  		//System.out.println(bindings.toString());
    5.21  		
    5.22  		/*for(String result: bindings)
    5.23 @@ -191,7 +191,7 @@
    5.24  				"FILTER(strdf:overright(?t1, ?t2) && ?x1 != ?x2)."+
    5.25  				"}";
    5.26  		
    5.27 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.28 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.29  		assertEquals(31, bindings.size());
    5.30  		//assertTrue(-1 < bindings.indexOf(""));
    5.31  		/*for(String result: bindings)
    5.32 @@ -263,7 +263,7 @@
    5.33  				"FILTER(strdf:overleft(?t1, ?t2) && ?x1 != ?x2)."+
    5.34  				"}";
    5.35  		
    5.36 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.37 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.38  		assertEquals(14, bindings.size());
    5.39  		//assertTrue(-1 < bindings.indexOf(""));
    5.40  		/*for(String result: bindings)
    5.41 @@ -301,7 +301,7 @@
    5.42  				"FILTER(strdf:PeriodOverlaps(?t1, ?t2) && str(?x1) != str(?x2))."+
    5.43  				"}";
    5.44  		
    5.45 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.46 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.47  	
    5.48  		assertEquals(6, bindings.size());
    5.49  		//assertTrue(-1 < bindings.indexOf(""));
    5.50 @@ -332,7 +332,7 @@
    5.51  				"FILTER(strdf:PeriodIntersects(?t1, ?t2) && str(?x1) < str(?x2))."+
    5.52  				"}";
    5.53  		
    5.54 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.55 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.56  	
    5.57  		assertEquals(7, bindings.size());
    5.58  		//assertTrue(-1 < bindings.indexOf(""));
    5.59 @@ -364,7 +364,7 @@
    5.60  				"FILTER(strdf:during(?t1, ?t2) && ?x1 != ?x2)."+
    5.61  				"}";
    5.62  		
    5.63 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.64 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.65  	
    5.66  		assertEquals(8, bindings.size());
    5.67  		//assertTrue(-1 < bindings.indexOf(""));
    5.68 @@ -396,7 +396,7 @@
    5.69  				"FILTER(strdf:adjacent(?t1, ?t2) && str(?x1) < str(?x2))."+
    5.70  				"}";
    5.71  		
    5.72 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.73 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.74  		/*for(String result: bindings)
    5.75  		{
    5.76  			System.out.println(result.toString());
    5.77 @@ -419,7 +419,7 @@
    5.78  				"FILTER(strdf:meets(?t1, ?t2) && ?x1 != ?x2)."+
    5.79  				"}";
    5.80  		
    5.81 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.82 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.83  		/*for(String result: bindings)
    5.84  		{
    5.85  			System.out.println(result.toString());
    5.86 @@ -444,7 +444,7 @@
    5.87  				"FILTER(strdf:starts(?t1, ?t2) && str(?x1) != str(?x2))."+
    5.88  				"}";
    5.89  		
    5.90 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    5.91 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    5.92  
    5.93  		assertEquals(1, bindings.size());
    5.94  		//assertTrue(-1 < bindings.indexOf(""));
    5.95 @@ -470,7 +470,7 @@
    5.96  				"FILTER(strdf:finishes(?t1, ?t2) && str(?x1) > str(?x2))."+
    5.97  				"}";
    5.98  		
    5.99 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
   5.100 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
   5.101  		
   5.102  		assertEquals(1, bindings.size());
   5.103  		//assertTrue(-1 < bindings.indexOf(""));
   5.104 @@ -496,7 +496,7 @@
   5.105  				"FILTER(strdf:equalsPeriod(?t1, ?t2) && str(?x1) < str(?x2))."+
   5.106  				"}";
   5.107  		
   5.108 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
   5.109 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
   5.110  		//assertEquals(3, bindings.size());
   5.111  		//assertTrue(-1 < bindings.indexOf(""));
   5.112  		/*for(String result: bindings)
   5.113 @@ -522,7 +522,7 @@
   5.114  				"FILTER(strdf:nequalsPeriod(?t1, ?t2) && str(?x1) < str(?x2))."+
   5.115  				"}";
   5.116  		
   5.117 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
   5.118 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
   5.119  		
   5.120  		assertEquals(28, bindings.size());
   5.121  		//assertTrue(-1 < bindings.indexOf(""));
     6.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalSelectionTests.java	Wed May 08 20:26:55 2013 +0300
     6.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/TemporalSelectionTests.java	Wed May 08 20:51:29 2013 +0300
     6.3 @@ -75,7 +75,7 @@
     6.4  				"?s ?p ?o ?t. "+
     6.5  			"}";
     6.6  		
     6.7 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
     6.8 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
     6.9  		assertEquals(8, bindings.size());
    6.10  	}
    6.11  
    6.12 @@ -91,7 +91,7 @@
    6.13  				"?s ?p ?o. "+
    6.14  			"}";
    6.15  		
    6.16 -		ArrayList<String> bindings = (ArrayList<String>) strabon.query(strabon.queryRewriting(query),strabon.getSailRepoConnection());
    6.17 +		ArrayList<String> bindings = (ArrayList<String>) strabon.query(utils.queryRewriting(query),strabon.getSailRepoConnection());
    6.18  		assertEquals(9, bindings.size());
    6.19  	}
    6.20  }