Strabon

changeset 779:bcf56f3e9988 DiffDateTime

NOT WORKING: trying to implement diffDateTime for postgres
author George Garbis <ggarbis@di.uoa.gr>
date Fri Nov 30 20:09:20 2012 +0200 (2012-11-30)
parents 8df99e93a35d
children 530257d4896e
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffDateTime.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/DateTimeMetricFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/DiffDateTime.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffDateTime.java	Fri Nov 30 20:09:20 2012 +0200
     1.3 @@ -0,0 +1,25 @@
     1.4 +/**
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 + *
     1.9 + * Copyright (C) 2012, Pyravlos Team
    1.10 + *
    1.11 + * http://www.strabon.di.uoa.gr/
    1.12 + */
    1.13 +package org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric;
    1.14 +
    1.15 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
    1.16 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
    1.17 +
    1.18 +/**
    1.19 + * @author Garmpis Georgios <ggarbis@di.uoa.gr>
    1.20 + *
    1.21 + */
    1.22 +public class DiffDateTime extends DateTimeMetricFunc {
    1.23 +
    1.24 +	@Override
    1.25 +	public String getURI() {
    1.26 +		return GeoConstants.diffDateTime;
    1.27 +	}
    1.28 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/DateTimeMetricFunc.java	Fri Nov 30 20:09:20 2012 +0200
     2.3 @@ -0,0 +1,35 @@
     2.4 +/**
     2.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     2.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     2.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.8 + * 
     2.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team
    2.10 + * 
    2.11 + * http://www.strabon.di.uoa.gr/
    2.12 + */
    2.13 +package org.openrdf.query.algebra.evaluation.function.spatial;
    2.14 +
    2.15 +import org.openrdf.model.Value;
    2.16 +import org.openrdf.model.ValueFactory;
    2.17 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    2.18 +import org.openrdf.query.algebra.evaluation.function.Function;
    2.19 +
    2.20 +/**
    2.21 + * This class represents a function doing a metric computation on xsd:dateTime values
    2.22 + * (e.g., calculating the difference between two xsd:dateTime values).
    2.23 + * 
    2.24 + * @see package {@link org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric}
    2.25 + * 
    2.26 + * @author George Garbis <ggarbis@di.uoa.gr>
    2.27 + */
    2.28 +public abstract class DateTimeMetricFunc implements Function {
    2.29 +
    2.30 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
    2.31 +	public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
    2.32 +
    2.33 +		return null;
    2.34 +	}
    2.35 +
    2.36 +	// charnik: made method (and hence the class) abstract
    2.37 +	public abstract String getURI();
    2.38 +}
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java	Fri Nov 30 15:07:35 2012 +0200
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java	Fri Nov 30 20:09:20 2012 +0200
     3.3 @@ -172,5 +172,13 @@
     3.4  	public static final String rccNonTangentialProperPart 		 = geof + "rcc8-ntpp";
     3.5  	public static final String rccNonTangentialProperPartInverse = geof + "rcc8-ntppi";
     3.6  	public static final String geoSparqlRelate 					 = geof + "relate";
     3.7 -	
     3.8 +
     3.9 +	/**
    3.10 +	 * Addition for datetime metric functions
    3.11 +	 * 
    3.12 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    3.13 +	 * 
    3.14 +	 */
    3.15 +	public static final String diffDateTime = "http://strdf.di.uoa.gr/extensions/ontology#diffDateTime";
    3.16 +	/** End of addition **/
    3.17  }
     4.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/DiffDateTime.java	Fri Nov 30 15:07:35 2012 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,65 +0,0 @@
     4.4 -/**
     4.5 - * This Source Code Form is subject to the terms of the Mozilla Public
     4.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this
     4.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4.8 - *
     4.9 - * Copyright (C) 2012, Pyravlos Team
    4.10 - *
    4.11 - * http://www.strabon.di.uoa.gr/
    4.12 - */
    4.13 -package org.openrdf.query.algebra.evaluation.util;
    4.14 -
    4.15 -import java.text.SimpleDateFormat;
    4.16 -import java.util.Calendar;
    4.17 -import java.util.GregorianCalendar;
    4.18 -
    4.19 -import org.openrdf.model.Value;
    4.20 -import org.openrdf.model.ValueFactory;
    4.21 -import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    4.22 -import org.openrdf.query.algebra.evaluation.function.Function;
    4.23 -
    4.24 -/**
    4.25 - * @author Garmpis Georgios <ggarbis@di.uoa.gr>
    4.26 - *
    4.27 - */
    4.28 -public class DiffDateTime implements Function {
    4.29 -
    4.30 -	@Override
    4.31 -	public String getURI() {
    4.32 -		return "http://strdf.di.uoa.gr/extensions/ontology#diffDateTime";
    4.33 -	}
    4.34 -	
    4.35 -	@Override
    4.36 -	public Value evaluate(ValueFactory valueFactory, Value... args)
    4.37 -            throws ValueExprEvaluationException {
    4.38 -        if (args.length != 2) {
    4.39 -            throw new ValueExprEvaluationException(this.getURI()
    4.40 -                    + " requires exactly 2 arguments, got " + args.length);
    4.41 -        }
    4.42 -        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'hh:mm:ss"); //the format of xsd:Datetime
    4.43 -		
    4.44 -		long diff = 0;
    4.45 -    	try {
    4.46 -    	    String date1 = args[0].toString();
    4.47 -    	    date1 = date1.replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "");
    4.48 -    	    date1 = date1.replace("\"", "");
    4.49 -    	    Calendar cal1 = new GregorianCalendar();
    4.50 -    		cal1.setTime(sdf.parse(date1));
    4.51 -    		
    4.52 -    		String date2 = args[1].toString();
    4.53 -    		date2 = date2.replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "");
    4.54 -    	    date2 = date2.replace("\"", "");
    4.55 -    	    Calendar cal2 = new GregorianCalendar();
    4.56 -    		cal2.setTime(sdf.parse(date2));
    4.57 -    		
    4.58 -    		diff = cal2.getTimeInMillis() - cal1.getTimeInMillis();
    4.59 -    		
    4.60 -    	} catch (java.text.ParseException e) {
    4.61 -			// TODO Auto-generated catch block
    4.62 -			e.printStackTrace();
    4.63 -		}
    4.64 -		
    4.65 -		
    4.66 -        return valueFactory.createLiteral(diff);
    4.67 -    }
    4.68 -}
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Fri Nov 30 15:07:35 2012 +0200
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Fri Nov 30 20:09:20 2012 +0200
     5.3 @@ -29,6 +29,7 @@
     5.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
     5.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
     5.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
     5.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlExtDiffDateTime;
     5.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
     5.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML;
    5.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
    5.11 @@ -397,6 +398,17 @@
    5.12  		return new GeneralDBSqlGeoSymDifference(left, right);
    5.13  	}
    5.14  	
    5.15 +	/** Addition for datetime metric functions
    5.16 +	 * 
    5.17 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    5.18 +	 * 
    5.19 +	 */
    5.20 +	public static GeneralDBSqlExpr extDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    5.21 +
    5.22 +		return new GeneralDBSqlExtDiffDateTime(left, right);
    5.23 +	}
    5.24 +	/***/
    5.25 +	
    5.26  	//XXX Spatial Metric Functions
    5.27  	public static GeneralDBSqlExpr geoArea(GeneralDBSqlExpr expr) {
    5.28  
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java	Fri Nov 30 15:07:35 2012 +0200
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java	Fri Nov 30 20:09:20 2012 +0200
     6.3 @@ -25,19 +25,13 @@
     6.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery;
     6.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAbs;
     6.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnd;
     6.7 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnyInteract;
     6.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase;
     6.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCast;
    6.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCompare;
    6.11  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlConcat;
    6.12 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
    6.13 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
    6.14 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
    6.15 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
    6.16 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDateTimeMetricBinary;
    6.17  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
    6.18 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
    6.19  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSpatial;
    6.20 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlInside;
    6.21  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull;
    6.22  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlLike;
    6.23  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlLowerCase;
    6.24 @@ -45,7 +39,6 @@
    6.25  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot;
    6.26  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull;
    6.27  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOr;
    6.28 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOverlap;
    6.29  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRegex;
    6.30  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlShift;
    6.31  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
    6.32 @@ -53,7 +46,6 @@
    6.33  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
    6.34  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
    6.35  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
    6.36 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouch;
    6.37  import org.openrdf.sail.generaldb.algebra.GeneralDBStringValue;
    6.38  import org.openrdf.sail.generaldb.algebra.GeneralDBTrueValue;
    6.39  import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn;
    6.40 @@ -373,6 +365,17 @@
    6.41  		 meetNode(node);
    6.42  	 }
    6.43  
    6.44 +	 /** Addition for datetime metric functions
    6.45 +	  * 
    6.46 +	  * @author George Garbis <ggarbis@di.uoa.gr>
    6.47 +	  * 
    6.48 +	  */ 
    6.49 +	public void meet(GeneralDBSqlDateTimeMetricBinary node) 
    6.50 +	throws X {
    6.51 +		meetBinarySqlOperator(node);
    6.52 +	}
    6.53 +	/***/
    6.54 +	
    6.55  	 //	public void meet(GeneralDBSqlAnyInteract node) throws X
    6.56  	 //	{
    6.57  	 //		meetBinarySqlOperator(node);
     7.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Fri Nov 30 15:07:35 2012 +0200
     7.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Fri Nov 30 20:09:20 2012 +0200
     7.3 @@ -12,6 +12,7 @@
     7.4  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoBuffer;
     7.5  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoConvexHull;
     7.6  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoDifference;
     7.7 +import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.extDiffDateTime;
     7.8  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoDistance;
     7.9  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoEnvelope;
    7.10  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoIntersection;
    7.11 @@ -458,6 +459,24 @@
    7.12  		return null;
    7.13  	}
    7.14  
    7.15 +	/**
    7.16 +	 * Addition for datetime metric functions
    7.17 +	 * 
    7.18 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    7.19 +	 * 
    7.20 +	 */
    7.21 +	GeneralDBSqlExpr dateTimeMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    7.22 +	{
    7.23 +		if(function.getURI().equals(GeoConstants.diffDateTime))
    7.24 +		{
    7.25 +			return extDiffDateTime(leftArg, rightArg);
    7.26 +		}
    7.27 +
    7.28 +		//Should never reach this place
    7.29 +		return null;
    7.30 +	}
    7.31 +	/***/
    7.32 +	
    7.33  	//TODO more to be added here probably
    7.34  	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    7.35  	{