Strabon

changeset 818:63cfdc8ef2d8 temporals

Now the starting and the ending time points of a period will follow the xsd:DateTime format. Modified the query engine accordingly.
Similar modifications in the storage engine will follow
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Wed Dec 19 19:18:07 2012 +0200 (2012-12-19)
parents 2151e610123d
children d6578cb9fcb7
files postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsParser.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java	Wed Dec 19 17:43:33 2012 +0200
     1.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java	Wed Dec 19 19:18:07 2012 +0200
     1.3 @@ -9,6 +9,10 @@
     1.4  import java.sql.PreparedStatement;
     1.5  import java.sql.ResultSet;
     1.6  import java.sql.SQLException;
     1.7 +import java.text.ParseException;
     1.8 +import java.text.SimpleDateFormat;
     1.9 +import java.util.Calendar;
    1.10 +import java.util.GregorianCalendar;
    1.11  
    1.12  import org.openrdf.model.URI;
    1.13  import org.openrdf.query.BindingSet;
    1.14 @@ -65,8 +69,26 @@
    1.15  	{
    1.16  		Number id = ids.idOf(rs.getLong(index));
    1.17  		if (ids.isLiteral(id))
    1.18 -		{
    1.19 -			String label = rs.getObject(index+1).toString();
    1.20 +		{	String temp = rs.getString(index + 1);
    1.21 +		int i = temp.indexOf("[");
    1.22 +		int j = temp.indexOf(")"); //postgres always returns periods in the following format: [start, end)
    1.23 +		String label = null;
    1.24 +		String[] periods = temp.substring(++i, j).split(",");
    1.25 +
    1.26 +		SimpleDateFormat postgres = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
    1.27 +		SimpleDateFormat xsd = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss");
    1.28 +		try {
    1.29 +			
    1.30 +			String newStart = xsd.format(postgres.parse(periods[0])).toString();
    1.31 +			String newEnd = xsd.format(postgres.parse(periods[1])).toString();
    1.32 +			label = temp.replace(periods[0], newStart).replace(periods[1], newEnd);
    1.33 +			
    1.34 +		} catch (ParseException e) {
    1.35 +			// TODO Auto-generated catch block
    1.36 +			e.printStackTrace();
    1.37 +		}
    1.38 +		// label=temp.replace(" ", "T");
    1.39 +			//String label = rs.getObject(index+1).toString();
    1.40  		    URI datatype = vf.createURI(TemporalConstants.PERIOD);
    1.41  		    return vf.createLiteral(label, datatype);
    1.42  		    
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsParser.java	Wed Dec 19 17:43:33 2012 +0200
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsParser.java	Wed Dec 19 19:18:07 2012 +0200
     2.3 @@ -207,8 +207,8 @@
     2.4      	validTimeLiteral=sb;
     2.5      	int i2=0; 
     2.6      	
     2.7 -    	if(sb.toString().contains("^^"+TemporalConstants.PERIOD)||
     2.8 -    			sb.toString().contains("^^<http://strdf.di.uoa.gr/ontology#period>"))
     2.9 +    	if(sb.toString().contains("^^<"+TemporalConstants.PERIOD)||
    2.10 +    			sb.toString().contains("^^http://strdf.di.uoa.gr/ontology#period>"))
    2.11       	{	
    2.12      	
    2.13       	String[] splits = sb.toString().split(",");
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java	Wed Dec 19 17:43:33 2012 +0200
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java	Wed Dec 19 19:18:07 2012 +0200
     3.3 @@ -49,7 +49,7 @@
     3.4  	        
     3.5  	        @Override
     3.6  	        public void handleStatement(Statement st) {
     3.7 -	            if(st.getContext().toString().contains("^^"+TemporalConstants.PERIOD)||
     3.8 +	            if(st.getContext().toString().contains("^^<"+TemporalConstants.PERIOD)||
     3.9  	        			st.toString().contains("^^<http://strdf.di.uoa.gr/ontology#period>"))
    3.10  	         	{	
    3.11  	         	    NQuadsParser parser = new NQuadsParser();
    3.12 @@ -60,7 +60,7 @@
    3.13  						 {
    3.14  							 int i = context.indexOf('"')+1;
    3.15  							 int j = context.lastIndexOf('"');
    3.16 -							 validPeriod = "\"[" + context.substring(i,j)+","+context.substring(i,j) + "]\"^^"+TemporalConstants.PERIOD; 
    3.17 +							 validPeriod = "\"[" + context.substring(i,j)+","+context.substring(i,j) + "]\"^^<"+TemporalConstants.PERIOD+">"; 
    3.18  
    3.19  						 }
    3.20  					 Resource graph = parser.createValidTimeURI(validPeriod);
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Dec 19 17:43:33 2012 +0200
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Dec 19 19:18:07 2012 +0200
     4.3 @@ -490,6 +490,7 @@
     4.4  			System.out.println("Translated NQUADS to NTRIPLES!");
     4.5  			Iterator iterator = statements.iterator();
     4.6  			StringReader quadGraphReader = new StringReader(translator.getHandledTriples().toString());
     4.7 +			System.out.println("handled triples"+ translator.getHandledTriples().toString());
     4.8  			con1.add(quadGraphReader, "", RDFFormat.NTRIPLES);
     4.9  			for(Statement st: statements)
    4.10  			{
    4.11 @@ -501,7 +502,7 @@
    4.12  					 {
    4.13  						 int i = cont.indexOf('"')+1;
    4.14  						 int j = cont.lastIndexOf('"');
    4.15 -						 validPeriod = "\"[" + cont.substring(i,j) + "," + cont.substring(i,j) + "]\"^^"+TemporalConstants.PERIOD; 
    4.16 +						 validPeriod = "\"[" + cont.substring(i,j) + "," + cont.substring(i,j) + "]\"^^<"+TemporalConstants.PERIOD; 
    4.17  						 //validPeriod = cont.replace("]",","+cont.substring(i, j)+"]");
    4.18  						 
    4.19  					 }
    4.20 @@ -571,7 +572,7 @@
    4.21  				 {
    4.22  					 int i = cont.indexOf('"')+1;
    4.23  					 int j = cont.lastIndexOf('"');
    4.24 -					 validPeriod = "\"[" + cont.substring(i,j) + "," + cont.substring(i,j) + "]\"^^"+TemporalConstants.PERIOD; 
    4.25 +					 validPeriod = "\"[" + cont.substring(i,j) + "," + cont.substring(i,j) + "]\"^^<"+TemporalConstants.PERIOD; 
    4.26  					 //validPeriod = cont.replace("]",","+cont.substring(i, j)+"]");
    4.27  					 
    4.28  				 }