Strabon
changeset 1173:9ffcfac4b38a
started adding diffTime function. This function performs the difference between two literals of the xsd:time datatype. Currently works in the select clause of the query
author | Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> |
---|---|
date | Wed May 15 13:14:45 2013 +0300 (2013-05-15) |
parents | db7c1e492a84 |
children | 7bf0f0cfc745 |
files | endpoint/WebContent/WEB-INF/connection.properties evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffTime.java evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function runtime/src/main/resources/log4j.properties vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java |
line diff
1.1 --- a/endpoint/WebContent/WEB-INF/connection.properties Mon May 13 14:55:44 2013 +0300 1.2 +++ b/endpoint/WebContent/WEB-INF/connection.properties Wed May 15 13:14:45 2013 +0300 1.3 @@ -1,6 +1,6 @@ 1.4 hostname=localhost 1.5 port=5432 1.6 dbengine=postgis 1.7 -password=postgres 1.8 +password=p1r3as 1.9 dbname=endpoint 1.10 username=postgres
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/datetime/stsparql/metric/DiffTime.java Wed May 15 13:14:45 2013 +0300 2.3 @@ -0,0 +1,79 @@ 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 +package org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric; 2.14 + 2.15 +import java.text.SimpleDateFormat; 2.16 +import java.util.Calendar; 2.17 +import java.util.GregorianCalendar; 2.18 + 2.19 +import org.openrdf.model.URI; 2.20 +import org.openrdf.model.Value; 2.21 +import org.openrdf.model.ValueFactory; 2.22 +import org.openrdf.model.impl.URIImpl; 2.23 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; 2.24 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc; 2.25 + 2.26 +import eu.earthobservatory.constants.GeoConstants; 2.27 + 2.28 +/** * 2.29 + * 2.30 + * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> 2.31 + * 2.32 + */ 2.33 +public class DiffTime extends DateTimeMetricFunc { 2.34 + 2.35 + // This functions returns the difference in msecs of two xsd:dateTimes 2.36 + 2.37 + @Override 2.38 + public String getURI() { 2.39 + return GeoConstants.diffTime; 2.40 + } 2.41 + 2.42 + @Override 2.43 + public Value evaluate(ValueFactory valueFactory, Value... args) 2.44 + throws ValueExprEvaluationException { 2.45 + if (args.length != 2) { 2.46 + throw new ValueExprEvaluationException(this.getURI() 2.47 + + " requires exactly 2 arguments, got " + args.length); 2.48 + } 2.49 + String datatype = "<http://www.w3.org/2001/XMLSchema#time>"; 2.50 + String timeFormat = "hh:mm:ss"; 2.51 + SimpleDateFormat sdf = new SimpleDateFormat(timeFormat); //the format of xsd:Datetime 2.52 + String newTime=null; 2.53 + 2.54 + long diff = 0; 2.55 + try { 2.56 + 2.57 + String date1 = args[0].toString(); 2.58 + date1 = date1.replace("^^"+datatype, ""); 2.59 + date1 = date1.replace("\"", ""); 2.60 + Calendar cal1 = new GregorianCalendar(); 2.61 + cal1.setTime(sdf.parse(date1)); 2.62 + 2.63 + String date2 = args[1].toString(); 2.64 + date2 = date2.replace("^^"+datatype, ""); 2.65 + date2 = date2.replace("\"", ""); 2.66 + Calendar cal2 = new GregorianCalendar(); 2.67 + cal2.setTime(sdf.parse(date2)); 2.68 + 2.69 + diff = cal2.getTimeInMillis() - cal1.getTimeInMillis(); 2.70 + 2.71 + newTime = sdf.format(diff).toString(); 2.72 + 2.73 + 2.74 + } catch (java.text.ParseException e) { 2.75 + 2.76 + e.printStackTrace(); 2.77 + } 2.78 + 2.79 + return valueFactory.createLiteral(newTime, new URIImpl(datatype)); 2.80 + } 2.81 + 2.82 +}
3.1 --- a/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function Mon May 13 14:55:44 2013 +0300 3.2 +++ b/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function Wed May 15 13:14:45 2013 +0300 3.3 @@ -44,6 +44,7 @@ 3.4 org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.IsSimpleFunc 3.5 org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc 3.6 org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.DateTimeDiff 3.7 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.DateTimeDiff 3.8 org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlBoundaryFunc 3.9 org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlBufferFunc 3.10 org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlConvexHullFunc 3.11 @@ -81,6 +82,7 @@ 3.12 org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeatureTouchesFunc 3.13 3.14 org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric.DiffDateTime 3.15 +org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric.DiffTime 3.16 3.17 org.openrdf.query.algebra.evaluation.function.spatial.postgis.construct.MakeLine 3.18 org.openrdf.query.algebra.evaluation.function.spatial.postgis.construct.Centroid 3.19 \ No newline at end of file
4.1 --- a/runtime/src/main/resources/log4j.properties Mon May 13 14:55:44 2013 +0300 4.2 +++ b/runtime/src/main/resources/log4j.properties Wed May 15 13:14:45 2013 +0300 4.3 @@ -1,5 +1,5 @@ 4.4 # logger level values: OFF, ERROR, WARN, INFO, DEBUG, ALL 4.5 -log4j.rootLogger=INFO, CA 4.6 +log4j.rootLogger=ALL, CA 4.7 #log4j.rootLogger=DEBUG, CA 4.8 #log4j.rootLogger=INFO, CA, FA 4.9
5.1 --- a/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java Mon May 13 14:55:44 2013 +0300 5.2 +++ b/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java Wed May 15 13:14:45 2013 +0300 5.3 @@ -249,6 +249,10 @@ 5.4 /** 5.5 * List of stSPARQL spatial extension functions 5.6 */ 5.7 + 5.8 + 5.9 + public static final String diffTime = "http://strdf.di.uoa.gr/extensions/ontology#diffTime"; 5.10 + 5.11 public static final List<String> STSPARQLSpatialExtFunc = new ArrayList<String>(); 5.12 5.13 /**