Strabon

changeset 719:81eb9705a751 temporals

fixed minor store error that caused problems in temporal selection
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Tue Nov 20 19:48:47 2012 +0200 (2012-11-20)
parents ac60d571e184
children 4ce80f842ff1
files generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsParser.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsTranslator.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/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java	Tue Nov 20 13:49:44 2012 +0200
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java	Tue Nov 20 19:48:47 2012 +0200
     1.3 @@ -234,7 +234,6 @@
     1.4          if (value instanceof StrabonPolyhedron)
     1.5              return asRdbmsLiteral((StrabonPolyhedron)value);
     1.6          /****************************************/
     1.7 -        System.out.println("OUTE LITERAL OUTE GEOMETRIA!!! :"+value.toString());
     1.8  		return asRdbmsResource((Resource)value);
     1.9  	}
    1.10  
    1.11 @@ -328,7 +327,6 @@
    1.12  			if (r == null)
    1.13  				return ValueTable.NIL_ID;
    1.14  			RdbmsValue value = asRdbmsValue(r);
    1.15 -			System.out.println("PIRA TO VALUE: "+value.toString());
    1.16  			if (value instanceof RdbmsURI)
    1.17  				return uris.getInternalId((RdbmsURI)value);
    1.18  			if (value instanceof RdbmsBNode)
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsParser.java	Tue Nov 20 13:49:44 2012 +0200
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsParser.java	Tue Nov 20 19:48:47 2012 +0200
     2.3 @@ -201,38 +201,24 @@
     2.4  
     2.5      public Resource createValidTimeURI(String sb) throws ParseException, RDFParseException
     2.6      {
     2.7 -    	String strdf = "<http://strdf.di.uoa.gr/ontology#validTime";
     2.8 +    	String strdf = "http://strdf.di.uoa.gr/ontology#validTime";
     2.9      	validTimeLiteral=sb;
    2.10 -    	System.out.println("LITERAL RETURNED:"+ sb);
    2.11 -     	//if(Pattern.matches("[*,*]\"^^<http://strdf.di.uoa.gr/ontology#validTime>", sb.toString()))
    2.12 -    	// if( Pattern.matches("*va*", sb.toString()))
    2.13      	if(sb.toString().contains("^^<http://strdf.di.uoa.gr/ontology#validTime>"))
    2.14 -     	{	System.out.println("THIS IS A VALID TIME LITERAL");
    2.15 +     	{	
    2.16       	String[] splits = sb.toString().split(",");
    2.17 -     	System.out.println("split1= "+splits[0].toString());
    2.18 -     	System.out.println("split2= "+splits[1].toString());
    2.19 -//     	/String[] splash1 = splits[0].split("[");
    2.20       	int i = splits[0].indexOf('[');
    2.21       	String element1 = splits[0].substring(++i);
    2.22       	String[] splash2 = splits[1].split("]");
    2.23 -     	System.out.println("element1 ="+ element1);
    2.24 -     	System.out.println("splash2 ="+ splash2[0]);
    2.25 -     	//context= createURI(sb.toString());
    2.26          DateFormat dateformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
    2.27                  DateFormat.SHORT);
    2.28       	int syn = element1.indexOf('+');
    2.29       	String startDate = element1.substring(0,syn);
    2.30      	syn = element1.indexOf('+');
    2.31       	String endDate = element1.substring(0,syn);
    2.32 -     	//String endDate[] = splash2[0].split("+");
    2.33 -    	System.out.println("Starting date: "+ startDate);
    2.34 -     	System.out.println("Ending date: "+ endDate);
    2.35       	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    2.36       	Date start = format.parse(startDate);
    2.37       	Date end = format.parse(endDate);
    2.38 -      	System.out.println("Starting date: "+ start.toString());
    2.39 -     	System.out.println("Ending date: "+ end.toString());
    2.40 -        String uri = strdf+ startDate+"_"+ endDate+ "_" +format.getTimeZone().getID()+ ">"; 
    2.41 +        String uri = strdf+"/"+ startDate+"_"+ endDate+ "_" +format.getTimeZone().getID(); 
    2.42          Resource cont = createURI(uri);
    2.43          return cont;
    2.44      }
    2.45 @@ -256,43 +242,9 @@
    2.46          	System.out.println("PARSENODE");
    2.47              context = createBNode(sb.toString());
    2.48          }else if(c == '"'){
    2.49 -        	System.out.println("GOING TO PARSE THE LITERAL");
    2.50          	c = parseLiteral(c, sb);
    2.51          	validTimeLiteral=sb.toString();
    2.52          	context = createURI(sb.toString());
    2.53 -        	//context= createValidTimeURI(sb.toString());
    2.54 -        	/*System.out.println("LITERAL RETURNED:"+ sb);
    2.55 -         	//if(Pattern.matches("[*,*]\"^^<http://strdf.di.uoa.gr/ontology#validTime>", sb.toString()))
    2.56 -        	// if( Pattern.matches("*va*", sb.toString()))
    2.57 -        	if(sb.toString().contains("^^<http://strdf.di.uoa.gr/ontology#validTime>"))
    2.58 -         	{	System.out.println("THIS IS A VALID TIME LITERAL");
    2.59 -         	String[] splits = sb.toString().split(",");
    2.60 -         	System.out.println("split1= "+splits[0].toString());
    2.61 -         	System.out.println("split2= "+splits[1].toString());
    2.62 -//         	/String[] splash1 = splits[0].split("[");
    2.63 -         	int i = splits[0].indexOf('[');
    2.64 -         	String element1 = splits[0].substring(++i);
    2.65 -         	String[] splash2 = splits[1].split("]");
    2.66 -         	System.out.println("element1 ="+ element1);
    2.67 -         	System.out.println("splash2 ="+ splash2[0]);
    2.68 -         	//context= createURI(sb.toString());
    2.69 -            DateFormat dateformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
    2.70 -                    DateFormat.SHORT);
    2.71 -         	int syn = element1.indexOf('+');
    2.72 -         	String startDate = element1.substring(0,syn);
    2.73 -        	syn = element1.indexOf('+');
    2.74 -         	String endDate = element1.substring(0,syn);
    2.75 -         	//String endDate[] = splash2[0].split("+");
    2.76 -        	System.out.println("Starting date: "+ startDate);
    2.77 -         	System.out.println("Ending date: "+ endDate);
    2.78 -         	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    2.79 -         	Date start = format.parse(startDate);
    2.80 -         	Date end = format.parse(endDate);
    2.81 -          	System.out.println("Starting date: "+ start.toString());
    2.82 -         	System.out.println("Ending date: "+ end.toString());
    2.83 -            String uri = strdf+ startDate+"_"+ endDate+ "_" +format.getTimeZone().getID()+ ">"; 
    2.84 -            context = createURI(uri);
    2.85 -         	}*/
    2.86          	
    2.87          }else if (c == -1) {
    2.88              throwEOFException();
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsTranslator.java	Tue Nov 20 13:49:44 2012 +0200
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/NQuadsTranslator.java	Tue Nov 20 19:48:47 2012 +0200
     3.3 @@ -56,7 +56,7 @@
     3.4      	try {
     3.5  			parser.parse(is, "http://test.base.uri");
     3.6  		    handledTriples = handler.getTriples();
     3.7 -	        System.out.println("HANDLED TRIPLES: "+handledTriples.toString());
     3.8 +	       // System.out.println("HANDLED TRIPLES: "+handledTriples.toString());
     3.9  		} catch (RDFParseException e) {
    3.10  			// TODO Auto-generated catch block
    3.11  			e.printStackTrace();
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java	Tue Nov 20 13:49:44 2012 +0200
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java	Tue Nov 20 19:48:47 2012 +0200
     4.3 @@ -50,11 +50,11 @@
     4.4  	        public void handleStatement(Statement st) {
     4.5  	            //super.handleStatement(st);
     4.6  	            if(st.getContext().toString().contains("^^<http://strdf.di.uoa.gr/ontology#validTime>"))
     4.7 -	         	{	System.out.println("THIS IS A VALID TIME LITERAL");
     4.8 +	         	{	
     4.9  	         	    NQuadsParser parser = new NQuadsParser();
    4.10  	         		try {
    4.11  					 Resource graph = parser.createValidTimeURI(st.getContext().toString());
    4.12 -					 String triple = graph.toString() + " <http://strdf.di.uoa.gr/ontology#hasValidTime> "+ st.getContext().toString()+ " .\n" ;
    4.13 +					 String triple = "<"+graph.toString()+">"+  " <http://strdf.di.uoa.gr/ontology#hasValidTime> "+ st.getContext().toString()+ " .\n" ;
    4.14  					    triples.append(triple);
    4.15  					} catch (RDFParseException e) {
    4.16  						// TODO Auto-generated catch block
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Nov 20 13:49:44 2012 +0200
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Nov 20 19:48:47 2012 +0200
     5.3 @@ -21,6 +21,7 @@
     5.4  import java.net.MalformedURLException;
     5.5  import java.net.URL;
     5.6  import java.sql.SQLException;
     5.7 +import java.text.ParseException;
     5.8  import java.util.ArrayList;
     5.9  import java.util.Collection;
    5.10  import java.util.Iterator;
    5.11 @@ -28,6 +29,7 @@
    5.12  import java.util.regex.Matcher;
    5.13  import java.util.regex.Pattern;
    5.14  
    5.15 +import org.openrdf.model.Resource;
    5.16  import org.openrdf.model.Statement;
    5.17  import org.openrdf.model.URI;
    5.18  import org.openrdf.model.ValueFactory;
    5.19 @@ -474,24 +476,19 @@
    5.20  		if(format.equals(RDFFormat.NQUADS))
    5.21  		{
    5.22  			NQuadsTranslator translator = new NQuadsTranslator();
    5.23 -		//	 final ByteArrayInputStream bais = new ByteArrayInputStream(i);
    5.24 -			 final ByteArrayInputStream bais = new ByteArrayInputStream(
    5.25 -			            "<http://www.v/dat/4b> <http://www.w3.org/20/ica#dtend> <http://sin/value/2> \"[2005-01-01 00:00:00+01,2006-01-01 00:00:00+01]\"^^<http://strdf.di.uoa.gr/ontology#validTime> ."
    5.26 -			            .getBytes()
    5.27 -			        );
    5.28 -			 final ByteArrayInputStream bais2 = new ByteArrayInputStream(
    5.29 -			            "<http://strdf.di.uoa.gr/ontology#validTime2005-01-01 00:00:00_2005-01-01 00:00:00_Europe/Athens> <http://strdf.di.uoa.gr/ontology#hasValidTime> \"[2005-01-01 00:00:00+01,2006-01-01 00:00:00+01]\"^^<http://strdf.di.uoa.gr/ontology#validTime> ."
    5.30 -			            .getBytes()
    5.31 -			        );
    5.32 -			 
    5.33 -			Collection<Statement> statements = translator.translate(bais2, baseURI);
    5.34 +			Collection<Statement> statements = translator.translate(in, baseURI);
    5.35  			Iterator iterator = statements.iterator();
    5.36  			for(Statement st: statements)
    5.37  			{
    5.38  				//edw prepei na mpei sunartisi pou na metasximatizei to context an einai temporal
    5.39 -				con1.add(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
    5.40 -				System.out.println("STATEMENT: "+st.toString());
    5.41 -				System.out.println("CONTEXT: "+st.getContext().toString());
    5.42 +				try {
    5.43 +					int length= st.getContext().toString().length();
    5.44 +					Resource newContext = new NQuadsParser().createValidTimeURI(st.getContext().toString());
    5.45 +							con1.add(st.getSubject(), st.getPredicate(), st.getObject(), newContext);
    5.46 +				} catch (ParseException e) {
    5.47 +					// TODO Auto-generated catch block
    5.48 +					e.printStackTrace();
    5.49 +				}
    5.50  			}
    5.51  			StringReader quadGraphReader = new StringReader(translator.getHandledTriples().toString());
    5.52  			con1.add(quadGraphReader, "", RDFFormat.NTRIPLES);
    5.53 @@ -538,9 +535,26 @@
    5.54  		logger.info("[Strabon.storeString] Format   : " + ((format == null) ? "null" : format.toString()));
    5.55  
    5.56  		StringReader reader = new StringReader(text);
    5.57 +		if(format.equals(RDFFormat.NQUADS))
    5.58 +		{
    5.59 +			ByteArrayInputStream in = new ByteArrayInputStream(text.getBytes());
    5.60 +			NQuadsTranslator translator = new NQuadsTranslator();
    5.61 +		//	 final ByteArrayInputStream bais = new ByteArrayInputStream(i);
    5.62 +						 
    5.63 +			Collection<Statement> statements = translator.translate(in, baseURI);
    5.64 +			Iterator iterator = statements.iterator();
    5.65 +			for(Statement st: statements)
    5.66 +			{
    5.67 +				//edw prepei na mpei sunartisi pou na metasximatizei to context an einai temporal
    5.68 +				con1.add(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
    5.69 +				System.out.println("STATEMENT: "+st.toString());
    5.70 +				System.out.println("CONTEXT: "+st.getContext().toString());
    5.71 +			}
    5.72 +			StringReader quadGraphReader = new StringReader(translator.getHandledTriples().toString());
    5.73 +			con1.add(quadGraphReader, "", RDFFormat.NTRIPLES);
    5.74 +			return;
    5.75 +		}
    5.76  		
    5.77 -		
    5.78 -
    5.79  		RDFParser parser = Rio.createParser(format);
    5.80  
    5.81  		GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase();