Strabon

changeset 836:c20732e3fc22 temporals

added cases which are not covered by the jtemporal libary
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Fri Jan 04 14:54:53 2013 +0200 (2013-01-04)
parents c4989f4024a6
children 8ffcde5a3127
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/spatial/StrabonTemporalElement.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonInstant.java	Fri Jan 04 13:12:18 2013 +0200
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonInstant.java	Fri Jan 04 14:54:53 2013 +0200
     1.3 @@ -35,8 +35,9 @@
     1.4  	public GregorianCalendar getValue() {
     1.5  		return value;
     1.6  	}
     1.7 +	
     1.8  
     1.9 -	public String stringValue(){
    1.10 +	public String toString(){
    1.11  		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss");
    1.12  		return sdf.format(this.value.getTime()).toString();
    1.13  	}
    1.14 @@ -44,10 +45,13 @@
    1.15  		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss");
    1.16  		GregorianCalendar cal = new GregorianCalendar();
    1.17  		cal.setTime(sdf.parse(instant.substring(instant.indexOf('"')+1,instant.lastIndexOf('"') )));
    1.18 -		return new StrabonInstant(cal);
    1.19 +		StrabonInstant inst = new StrabonInstant(cal);
    1.20 +		inst.datatype = new URIImpl(TemporalConstants.INSTANT);
    1.21 +		return inst;
    1.22  	}
    1.23  
    1.24  	public StrabonInstant(GregorianCalendar value) throws ParseException{
    1.25 +		this.datatype = new URIImpl(TemporalConstants.INSTANT);
    1.26  		this.value = value;
    1.27  	}
    1.28  	@Override
    1.29 @@ -82,7 +86,17 @@
    1.30  	@Override
    1.31  	public void setDatatype(URI datatype) {
    1.32  		
    1.33 -		this.setDatatype(new URIImpl(TemporalConstants.INSTANT));
    1.34 +		this.setDatatype(datatype);
    1.35 +	}
    1.36 +
    1.37 +
    1.38 +	/* (non-Javadoc)
    1.39 +	 * @see org.openrdf.query.algebra.evaluation.function.spatial.StrabonTemporalElement#stringValue()
    1.40 +	 */
    1.41 +	@Override
    1.42 +	public String stringValue() {
    1.43 +		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss");
    1.44 +		return sdf.format(this.value.getTime()).toString();
    1.45  	}
    1.46  
    1.47  }
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java	Fri Jan 04 13:12:18 2013 +0200
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPeriod.java	Fri Jan 04 14:54:53 2013 +0200
     2.3 @@ -27,7 +27,7 @@
     2.4  
     2.5  
     2.6  /**
     2.7 - * This class provides a java implementation of a set of temporal functinos using the JTemporal library. 
     2.8 + * This class provides a java implementation of a set of temporal functions using the JTemporal library. 
     2.9   * This implementation is respective to the Postgresql Temporal implementation of these functions
    2.10   * 
    2.11   * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
    2.12 @@ -40,6 +40,7 @@
    2.13  	public StrabonPeriod()
    2.14  	{
    2.15  		this.period = null;
    2.16 +		this.datatype = new URIImpl(TemporalConstants.PERIOD);
    2.17  	}
    2.18  	public StrabonPeriod(String period) throws ParseException
    2.19  	{
    2.20 @@ -52,6 +53,7 @@
    2.21  			endCal.setTime(sdf.parse(period.substring(period.indexOf(',')+1,period.indexOf(')') )));
    2.22  			StrabonInstant start = new StrabonInstant(startCal);
    2.23  			StrabonInstant end = new StrabonInstant(endCal);
    2.24 +			this.datatype = new URIImpl(TemporalConstants.PERIOD);
    2.25  			this.period = new Period(start, end);
    2.26  
    2.27  		}
    2.28 @@ -69,12 +71,13 @@
    2.29  			StrabonInstant start = new StrabonInstant(startCal);
    2.30  			StrabonInstant end = new StrabonInstant(endCal);
    2.31  			this.period = new Period(start, end);
    2.32 +			this.datatype = new URIImpl(TemporalConstants.PERIOD);
    2.33  
    2.34  	}
    2.35  	
    2.36  	public void setDatatype(URI datatype) {
    2.37  		
    2.38 -		this.setDatatype(new URIImpl(TemporalConstants.PERIOD));
    2.39 +		this.setDatatype(datatype);
    2.40  	}
    2.41  	
    2.42  	
    2.43 @@ -100,17 +103,91 @@
    2.44  		return period.toString().replace("Period:(","[");
    2.45  	}
    2.46  
    2.47 -	public static StrabonPeriod union(StrabonPeriod A, StrabonPeriod B)
    2.48 +	public static StrabonPeriod union(StrabonTemporalElement A, StrabonTemporalElement B)
    2.49  	{
    2.50 -		StrabonPeriod period = new StrabonPeriod();
    2.51 -		period.setPeriod( A.getPeriod().union(B.getPeriod()));
    2.52 -		return period;
    2.53 +		if(A instanceof StrabonPeriod && B instanceof StrabonPeriod)
    2.54 +		{
    2.55 +			if(((StrabonPeriod)A).getPeriod().toString().equals(((StrabonPeriod)B).getPeriod().toString()))
    2.56 +			{
    2.57 +				return (StrabonPeriod)A;
    2.58 +			}
    2.59 +			if(((StrabonPeriod)A).getPeriod().contains(((StrabonPeriod)B).getPeriod()))
    2.60 +			{
    2.61 +				return (StrabonPeriod)A;
    2.62 +			}
    2.63 +			if(((StrabonPeriod)B).getPeriod().contains(((StrabonPeriod)A).getPeriod()))
    2.64 +			{
    2.65 +				return (StrabonPeriod)B;
    2.66 +			}
    2.67 +			StrabonPeriod period = new StrabonPeriod();
    2.68 +			period.setPeriod( ((StrabonPeriod)A).getPeriod().union(((StrabonPeriod)B).getPeriod()));
    2.69 +			return period;
    2.70 +			
    2.71 +		}
    2.72 +		else if(A instanceof StrabonPeriod && B instanceof StrabonInstant)
    2.73 +		{
    2.74 +		if(((StrabonPeriod) A).contains((StrabonPeriod)A ,B ))
    2.75 +		{
    2.76 +			return (StrabonPeriod) A;
    2.77 +		}
    2.78 +		else
    2.79 +			return null;
    2.80 +		}
    2.81 +		
    2.82 +		else if(B instanceof StrabonPeriod && A instanceof StrabonInstant)
    2.83 +		{
    2.84 +			if(((StrabonPeriod) B).contains((StrabonPeriod)B ,A ))
    2.85 +			{
    2.86 +				return (StrabonPeriod) B;
    2.87 +			}
    2.88 +				else
    2.89 +					return null;
    2.90 +		}
    2.91 +		else
    2.92 +			return null;
    2.93  	}
    2.94 -	public static StrabonPeriod intersection(StrabonPeriod A, StrabonPeriod B)
    2.95 +	public static StrabonTemporalElement intersection(StrabonTemporalElement A, StrabonTemporalElement B)
    2.96  	{
    2.97 -		StrabonPeriod period = new StrabonPeriod();
    2.98 -		period.setPeriod( A.getPeriod().intersect(B.getPeriod()));
    2.99 -		return period;
   2.100 +		if(A instanceof StrabonPeriod && B instanceof StrabonPeriod)
   2.101 +		{
   2.102 +			if(((StrabonPeriod)A).getPeriod().equals(((StrabonPeriod)B).getPeriod()))
   2.103 +			{
   2.104 +				return (StrabonPeriod)A;
   2.105 +			}
   2.106 +			if(((StrabonPeriod)A).getPeriod().contains(((StrabonPeriod)B).getPeriod()))
   2.107 +			{
   2.108 +				return (StrabonPeriod)B;
   2.109 +			}
   2.110 +			if(((StrabonPeriod)B).getPeriod().contains(((StrabonPeriod)A).getPeriod()))
   2.111 +			{
   2.112 +				return (StrabonPeriod)A;
   2.113 +			}
   2.114 +			StrabonPeriod period = new StrabonPeriod();
   2.115 +			period.setPeriod( ((StrabonPeriod)A).getPeriod().intersect(((StrabonPeriod)B).getPeriod()));
   2.116 +			return period;
   2.117 +			
   2.118 +		}
   2.119 +		else if(A instanceof StrabonPeriod && B instanceof StrabonInstant)
   2.120 +		{
   2.121 +		if(((StrabonPeriod) A).contains((StrabonPeriod)A ,B ))
   2.122 +		{
   2.123 +			return (StrabonInstant) B;
   2.124 +		}
   2.125 +		else
   2.126 +			return null;
   2.127 +		}
   2.128 +		
   2.129 +		else if(B instanceof StrabonPeriod && A instanceof StrabonInstant)
   2.130 +		{
   2.131 +			if(((StrabonPeriod) B).contains((StrabonPeriod)B ,A ))
   2.132 +			{
   2.133 +				return (StrabonInstant)A;
   2.134 +			}
   2.135 +				else
   2.136 +					return null;
   2.137 +		}
   2.138 +		else
   2.139 +			return null;
   2.140  	}
   2.141  	public static StrabonPeriod except(StrabonPeriod A, StrabonPeriod B)
   2.142  	{
   2.143 @@ -134,13 +211,12 @@
   2.144  	{
   2.145  		return A.getPeriod().compareTo(B.getPeriod());
   2.146  	}
   2.147 -	public static boolean contains(StrabonPeriod A, StrabonInstant B)
   2.148 +	public static boolean contains(StrabonPeriod A, StrabonTemporalElement B)
   2.149  	{
   2.150 -		return A.getPeriod().contains(B);
   2.151 -	}
   2.152 -	public static boolean contains(StrabonPeriod A, StrabonPeriod B)
   2.153 -	{
   2.154 -		return A.getPeriod().contains(B.getPeriod());
   2.155 +		if(B instanceof StrabonInstant)
   2.156 +			return A.getPeriod().contains((StrabonInstant)B);
   2.157 +		else 
   2.158 +			return A.getPeriod().contains(((StrabonPeriod)B).getPeriod());
   2.159  	}
   2.160  	public static boolean equals(StrabonPeriod A, StrabonPeriod B)
   2.161  	{
   2.162 @@ -162,17 +238,19 @@
   2.163  	{
   2.164  		return A.getPeriod().overlaps(B.getPeriod());
   2.165  	}
   2.166 -	public static boolean precedes(StrabonPeriod A, StrabonInstant B)
   2.167 +	public static boolean precedes(StrabonPeriod A, StrabonTemporalElement B)
   2.168  	{
   2.169 -		return A.getPeriod().precedes(B);
   2.170 +		if(B instanceof StrabonInstant)
   2.171 +			return A.getPeriod().precedes((StrabonInstant)B);
   2.172 +		else
   2.173 +			return A.getPeriod().precedes(((StrabonPeriod)B).getPeriod());
   2.174  	}
   2.175 -	public static boolean precedes(StrabonPeriod A, StrabonPeriod B)
   2.176 +	public static boolean succedes(StrabonPeriod A, StrabonTemporalElement B)
   2.177  	{
   2.178 -		return A.getPeriod().precedes(B.getPeriod());
   2.179 -	}
   2.180 -	public static boolean succedes(StrabonPeriod A, StrabonPeriod B)
   2.181 -	{
   2.182 -		return A.getPeriod().succeeds(B.getPeriod());
   2.183 +		if(B instanceof StrabonPeriod)
   2.184 +			return A.getPeriod().succeeds(((StrabonPeriod)B).getPeriod());
   2.185 +		else
   2.186 +			return A.getPeriod().succeeds((StrabonInstant)B);
   2.187  	}
   2.188  	
   2.189  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonTemporalElement.java	Fri Jan 04 14:54:53 2013 +0200
     3.3 @@ -0,0 +1,35 @@
     3.4 +/**
     3.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     3.8 + *
     3.9 + * Copyright (C) 2013, Pyravlos Team
    3.10 + *
    3.11 + * http://www.strabon.di.uoa.gr/
    3.12 + */
    3.13 +package org.openrdf.query.algebra.evaluation.function.spatial;
    3.14 +
    3.15 +import org.openrdf.model.URI;
    3.16 +import org.openrdf.model.Value;
    3.17 +import org.openrdf.model.impl.URIImpl;
    3.18 +import org.openrdf.query.algebra.evaluation.function.temporal.stsparql.relation.TemporalConstants;
    3.19 +
    3.20 +/**
    3.21 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
    3.22 + *
    3.23 + */
    3.24 +public abstract class StrabonTemporalElement implements Value{
    3.25 +	
    3.26 +	protected URI datatype;
    3.27 +
    3.28 +	public URI getDatatype() {
    3.29 +		return datatype;
    3.30 +	}
    3.31 +
    3.32 +	
    3.33 +	abstract public String stringValue();
    3.34 +	abstract public void setDatatype(URI datatype);
    3.35 +	
    3.36 +	
    3.37 +
    3.38 +}
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Jan 04 13:12:18 2013 +0200
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Jan 04 14:54:53 2013 +0200
     4.3 @@ -45,6 +45,7 @@
     4.4  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonInstant;
     4.5  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPeriod;
     4.6  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     4.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonTemporalElement;
     4.8  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AboveFunc;
     4.9  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AnyInteractFunc;
    4.10  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.BelowFunc;
    4.11 @@ -264,7 +265,6 @@
    4.12  		
    4.13  		// get the first argument of the function call
    4.14  		ValueExpr left = fc.getArgs().get(0);
    4.15 -System.out.println("Function RI= "+fc.getURI());
    4.16  		// evaluated first argument of function
    4.17  		Value leftResult = null;
    4.18  		
    4.19 @@ -519,48 +519,59 @@
    4.20  
    4.21  	}
    4.22  
    4.23 -	public StrabonPeriod temporalConstructPicker(Function function, Value left, Value right) throws ParseException
    4.24 +	public StrabonTemporalElement temporalConstructPicker(Function function, Value left, Value right) throws ParseException
    4.25  	{
    4.26  		if(function.getURI().equals(TemporalConstants.periodUnion))
    4.27  		{
    4.28 -			System.out.println("left= "+left.toString());
    4.29 -			System.out.println("right= "+right.toString());
    4.30 -			if(!left.toString().contains(",") && right.toString().contains(","))
    4.31 +
    4.32 +			StrabonTemporalElement rightArg= null;
    4.33 +			StrabonTemporalElement leftArg= null;
    4.34 +			
    4.35 +			if(left.toString().contains(","))
    4.36  			{
    4.37 -				StrabonInstant leftArg = StrabonInstant.read(left.toString());
    4.38 -				StrabonPeriod rightArg= new StrabonPeriod(right.toString());
    4.39 -				if(rightArg.contains(rightArg, leftArg))
    4.40 -				{
    4.41 -					return rightArg;
    4.42 -				}
    4.43 -				else
    4.44 -					return null;
    4.45 +				 leftArg= new StrabonPeriod(left.toString());
    4.46  			}
    4.47 -			else if(left.toString().contains(",") && !right.toString().contains(","))
    4.48 +			else
    4.49  			{
    4.50 -				StrabonInstant rightArg = StrabonInstant.read(right.toString());
    4.51 -				StrabonPeriod leftArg= new StrabonPeriod(left.toString());
    4.52 -				if(leftArg.contains(leftArg, rightArg))
    4.53 -				{
    4.54 -					return leftArg;
    4.55 -				}
    4.56 -				else
    4.57 -					return null;
    4.58 +				 leftArg = StrabonInstant.read(left.toString());
    4.59  			}
    4.60 -			else if(!left.toString().contains(",") && !right.toString().contains(","))
    4.61 +			if(right.toString().contains(","))
    4.62  			{
    4.63 -				return null;
    4.64 +				 rightArg= new StrabonPeriod(right.toString());
    4.65  			}
    4.66 -			else if(left.equals(right))
    4.67 +			else
    4.68  			{
    4.69 -				return new StrabonPeriod(right.toString());
    4.70 +				 rightArg = StrabonInstant.read(right.toString());
    4.71  			}
    4.72  			
    4.73 -			return StrabonPeriod.union(new StrabonPeriod(left.toString()), new StrabonPeriod(right.toString()));
    4.74 +			return StrabonPeriod.union(rightArg, leftArg);
    4.75 +			
    4.76  		}
    4.77  		else if(function.getURI().equals(TemporalConstants.periodIntersection))
    4.78  		{			
    4.79 -			return StrabonPeriod.intersection(new StrabonPeriod(left.toString()), new StrabonPeriod(right.toString()));
    4.80 +			System.out.println("left= "+left.toString());
    4.81 +			System.out.println("right= "+right.toString());
    4.82 +			StrabonTemporalElement rightArg= null;
    4.83 +			StrabonTemporalElement leftArg= null;
    4.84 +			
    4.85 +			if(left.toString().contains(","))
    4.86 +			{
    4.87 +				 leftArg= new StrabonPeriod(left.toString());
    4.88 +			}
    4.89 +			else
    4.90 +			{
    4.91 +				 leftArg = StrabonInstant.read(left.toString());
    4.92 +			}
    4.93 +			if(right.toString().contains(","))
    4.94 +			{
    4.95 +				 rightArg= new StrabonPeriod(right.toString());
    4.96 +			}
    4.97 +			else
    4.98 +			{
    4.99 +				 rightArg = StrabonInstant.read(right.toString());
   4.100 +			}
   4.101 +			
   4.102 +			return StrabonPeriod.intersection(rightArg, leftArg);
   4.103  		}
   4.104  		else if(function.getURI().equals(TemporalConstants.minusPeriod))
   4.105  		{
     5.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java	Fri Jan 04 13:12:18 2013 +0200
     5.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java	Fri Jan 04 14:54:53 2013 +0200
     5.3 @@ -24,7 +24,7 @@
     5.4  
     5.5  /**
     5.6   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
     5.7 - * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> (extended for the temporal case)
     5.8 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> (extensions for the temporal case)
     5.9   * 
    5.10   */
    5.11  public class stSPARQLResultsTSVWriter extends SPARQLResultsTSVWriter {
    5.12 @@ -44,7 +44,6 @@
    5.13  		else if(val instanceof StrabonTemporalElement){
    5.14  			val = new LiteralImpl(((StrabonTemporalElement)val).stringValue(), ((StrabonTemporalElement) val).getDatatype());
    5.15  		}
    5.16 -
    5.17  		
    5.18  		// write value
    5.19  		super.writeValue(val);