Strabon

changeset 831:734773ad75bb temporals

Added strabonInstant class. This implements the instant interface of jtemporal. The instant is currently implemented as a GregorianCalendar instance in java,
but its datatype can change in the future because of the transparency offered by jtemporal. The java implementation of the instant is correspondent to the timestampz implementation of postgesql temporal. Partially tested.
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Wed Jan 02 19:45:28 2013 +0200 (2013-01-02)
parents b3748ac1ad80
children c4989f4024a6
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonInstant.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/temporal/stsparql/relation/TemporalConstants.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.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/spatial/StrabonInstant.java	Wed Jan 02 19:45:28 2013 +0200
     1.3 @@ -0,0 +1,62 @@
     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) 2013, Pyravlos Team
    1.10 + *
    1.11 + * http://www.strabon.di.uoa.gr/
    1.12 + */
    1.13 +package org.openrdf.query.algebra.evaluation.function.spatial;
    1.14 +
    1.15 +import java.text.ParseException;
    1.16 +import java.text.SimpleDateFormat;
    1.17 +import java.util.GregorianCalendar;
    1.18 +
    1.19 +import net.sf.jtemporal.Instant;
    1.20 +
    1.21 +/**
    1.22 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
    1.23 + *
    1.24 + */
    1.25 +public class StrabonInstant implements Instant{
    1.26 +
    1.27 +	/* (non-Javadoc)
    1.28 +	 * @see net.sf.jtemporal.Instant#compareTo(java.lang.Object)
    1.29 +	 */
    1.30 +	
    1.31 +	private final GregorianCalendar value;
    1.32 +
    1.33 +	public GregorianCalendar getValue() {
    1.34 +		return value;
    1.35 +	}
    1.36 +
    1.37 +
    1.38 +
    1.39 +	public StrabonInstant(GregorianCalendar value) throws ParseException{
    1.40 +		this.value = value;
    1.41 +	}
    1.42 +	@Override
    1.43 +	public int compareTo(Object arg0) {
    1.44 +		return this.value.compareTo((GregorianCalendar)arg0);
    1.45 +	}
    1.46 +
    1.47 +	/* (non-Javadoc)
    1.48 +	 * @see net.sf.jtemporal.Instant#isNegativeInfinity()
    1.49 +	 */
    1.50 +	@Override
    1.51 +	public boolean isNegativeInfinity() {		
    1.52 +		// TODO Fix NegativeInfinity
    1.53 +		return false;
    1.54 +	}
    1.55 +
    1.56 +	/* (non-Javadoc)
    1.57 +	 * @see net.sf.jtemporal.Instant#isPositiveInfinity()
    1.58 +	 */
    1.59 +	@Override
    1.60 +	public boolean isPositiveInfinity() {
    1.61 +		// TODO FIXME PositiveInfinity
    1.62 +		return false;
    1.63 +	}
    1.64 +
    1.65 +}
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java	Wed Jan 02 13:52:03 2013 +0200
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java	Wed Jan 02 19:45:28 2013 +0200
     2.3 @@ -1,6 +1,21 @@
     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) 2013, Pyravlos Team
    2.10 + *
    2.11 + * http://www.strabon.di.uoa.gr/
    2.12 + */
    2.13 +
    2.14  package org.openrdf.query.algebra.evaluation.function.spatial;
    2.15  
    2.16  
    2.17 +import java.text.ParseException;
    2.18 +import java.text.SimpleDateFormat;
    2.19 +import java.util.Calendar;
    2.20 +import java.util.GregorianCalendar;
    2.21 +
    2.22  import net.sf.jtemporal.Instant;
    2.23  import net.sf.jtemporal.Period;
    2.24  
    2.25 @@ -11,7 +26,7 @@
    2.26   * This class provides a java implementation of a set of temporal functinos using the JTemporal library. 
    2.27   * This implementation is respective to the Postgresql Temporal implementation of these functions
    2.28   * 
    2.29 - * @author Konstantina Bereta <Konstantina.Brereta@di.uoa.gr>
    2.30 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
    2.31   *
    2.32   */
    2.33  public class StrabonPeriod implements Value {
    2.34 @@ -22,8 +37,17 @@
    2.35  	{
    2.36  		this.period = null;
    2.37  	}
    2.38 -	public StrabonPeriod(Instant start, Instant end)
    2.39 +	public StrabonPeriod(String period) throws ParseException
    2.40  	{
    2.41 +		int i = period.indexOf('[');
    2.42 +		int j = period.indexOf(')');
    2.43 +		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
    2.44 +		GregorianCalendar startCal = new GregorianCalendar();
    2.45 +		GregorianCalendar endCal = new GregorianCalendar();
    2.46 +		startCal.setTime(sdf.parse(period.substring(period.indexOf('[')+1,period.indexOf(',') )));
    2.47 +		endCal.setTime(sdf.parse(period.substring(period.indexOf(',')+1,period.indexOf(')') )));
    2.48 +		Instant start = new StrabonInstant(startCal);
    2.49 +		Instant end = new StrabonInstant(endCal);
    2.50  		this.period = new Period(start, end);
    2.51  	}
    2.52  	public Period getPeriod() {
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/temporal/stsparql/relation/TemporalConstants.java	Wed Jan 02 13:52:03 2013 +0200
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/temporal/stsparql/relation/TemporalConstants.java	Wed Jan 02 19:45:28 2013 +0200
     3.3 @@ -41,6 +41,9 @@
     3.4  	public static final String overleft=stRDF+ "overleft";
     3.5  
     3.6  	public static final String overright=stRDF+ "overright";
     3.7 +	
     3.8 +	public static final String meetsBefore=stRDF+ "meetsBefore";
     3.9 +	public static final String meetsAfter=stRDF+ "meetsAfter";
    3.10  
    3.11  	public static final String meets=stRDF+ "meets";
    3.12  	public static final String starts= stRDF+ "starts";
    3.13 @@ -50,5 +53,6 @@
    3.14  	public static final String periodIntersection=stRDF+ "periodIntersection";
    3.15  	public static final String periodUnion=stRDF+ "periodUnion";
    3.16  	public static final String minusPeriod=stRDF+ "minusPeriod";
    3.17 -
    3.18 +	public static final String precedingPeriod=stRDF+ "precedingPeriod";
    3.19 +	public static final String succedingPeriod=stRDF+ "succedingPeriod";
    3.20  }
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Wed Jan 02 13:52:03 2013 +0200
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Wed Jan 02 19:45:28 2013 +0200
     4.3 @@ -41,6 +41,7 @@
     4.4  import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
     4.5  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
     4.6  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
     4.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPeriod;
     4.8  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     4.9  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AboveFunc;
    4.10  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AnyInteractFunc;
    4.11 @@ -60,6 +61,9 @@
    4.12  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbEqualsFunc;
    4.13  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbInsideFunc;
    4.14  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbIntersectsFunc;
    4.15 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.construct.TemporalConstructFunc;
    4.16 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalConstants;
    4.17 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalRelationFunc;
    4.18  import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl;
    4.19  import org.openrdf.query.algebra.evaluation.iterator.OrderIterator;
    4.20  import org.openrdf.query.algebra.evaluation.iterator.StSPARQLGroupIterator;
    4.21 @@ -487,6 +491,13 @@
    4.22  
    4.23  				return funcResult ? BooleanLiteralImpl.TRUE : BooleanLiteralImpl.FALSE;
    4.24  			}
    4.25 +			else if(function instanceof TemporalConstructFunc) {
    4.26 +				return temporalConstructPicker(function, leftResult, rightResult);
    4.27 +			}
    4.28 +			else if(function instanceof TemporalRelationFunc){
    4.29 +				Boolean temporalFuncResult =  temporalRelationshipPicker(function, leftResult, rightResult);
    4.30 +				return temporalFuncResult ? BooleanLiteralImpl.TRUE : BooleanLiteralImpl.FALSE;
    4.31 +			}
    4.32  			else {
    4.33  				//Default Sesame Behavior
    4.34  				List<ValueExpr> args = fc.getArgs();
    4.35 @@ -506,6 +517,59 @@
    4.36  
    4.37  	}
    4.38  
    4.39 +	public StrabonPeriod temporalConstructPicker(Function function, Value left, Value right)
    4.40 +	{
    4.41 +		if(function.getURI().equals(TemporalConstants.periodUnion))
    4.42 +		{
    4.43 +			return StrabonPeriod.union((StrabonPeriod) left, (StrabonPeriod) right);
    4.44 +		}
    4.45 +		else if(function.getURI().equals(TemporalConstants.periodIntersection))
    4.46 +		{
    4.47 +			System.out.println("left= "+left.toString());
    4.48 +			System.out.println("right= "+right.toString());
    4.49 +			return StrabonPeriod.intersection((StrabonPeriod) left, (StrabonPeriod) right);
    4.50 +		}
    4.51 +		else if(function.getURI().equals(TemporalConstants.minusPeriod))
    4.52 +		{
    4.53 +			return StrabonPeriod.union((StrabonPeriod) left, (StrabonPeriod) right);
    4.54 +		}
    4.55 +		else if(function.getURI().equals(TemporalConstants.precedingPeriod))
    4.56 +		{
    4.57 +			return StrabonPeriod.precedingPeriod((StrabonPeriod) left, (StrabonPeriod) right);
    4.58 +		}
    4.59 +		else if(function.getURI().equals(TemporalConstants.succedingPeriod))
    4.60 +		{
    4.61 +			return StrabonPeriod.succedingPeriod((StrabonPeriod) left, (StrabonPeriod) right);
    4.62 +		}
    4.63 +		else
    4.64 +		{
    4.65 +			return null;			
    4.66 +		}
    4.67 +	}
    4.68 +	
    4.69 +	public boolean temporalRelationshipPicker (Function function, Value left, Value right)
    4.70 +	{
    4.71 +		if(function.getURI().equals(TemporalConstants.adjacent))
    4.72 +		{
    4.73 +			return StrabonPeriod.meets((StrabonPeriod) left, (StrabonPeriod) right);
    4.74 +		}
    4.75 +		else if(function.getURI().equals(TemporalConstants.after))
    4.76 +		{
    4.77 +			return StrabonPeriod.succedes((StrabonPeriod) left, (StrabonPeriod) right);
    4.78 +		}
    4.79 +		else if(function.getURI().equals(TemporalConstants.meetsBefore))
    4.80 +		{
    4.81 +			return StrabonPeriod.meetsBefore((StrabonPeriod) left, (StrabonPeriod) right);
    4.82 +		}
    4.83 +		else if(function.getURI().equals(TemporalConstants.meetsAfter))
    4.84 +		{
    4.85 +			return StrabonPeriod.meetsAfter((StrabonPeriod) left, (StrabonPeriod) right);
    4.86 +		}
    4.87 +		else
    4.88 +		{
    4.89 +			return false;
    4.90 +		}
    4.91 +	}
    4.92  	public StrabonPolyhedron spatialConstructPicker(Function function, Value left, Value right) throws Exception
    4.93  	{
    4.94  		StrabonPolyhedron leftArg = ((GeneralDBPolyhedron) left).getPolyhedron();