Strabon

changeset 943:bca2c7b71212 temporals

In the N-Quads format, the fourth element is *optional*. Made respective modifications and added tests
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Thu Mar 28 16:57:09 2013 +0200 (2013-03-28)
parents 6f223f6b7aeb
children c7e4d63ef1ab
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/storeTests.java runtime/src/test/resources/triples-and-quads.nq
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java	Thu Mar 28 13:49:51 2013 +0200
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/QuadRDFHandler.java	Thu Mar 28 16:57:09 2013 +0200
     1.3 @@ -30,6 +30,8 @@
     1.4  //import org.openrdf.model.URI;
     1.5  import org.openrdf.rio.RDFHandlerException;
     1.6  import org.openrdf.rio.RDFParseException;
     1.7 +import org.openrdf.rio.RDFParser;
     1.8 +import org.openrdf.rio.Rio;
     1.9  import org.openrdf.rio.helpers.StatementCollector;
    1.10  
    1.11  public class QuadRDFHandler extends StatementCollector {
    1.12 @@ -56,7 +58,17 @@
    1.13  	        
    1.14  	        @Override
    1.15  	        public void handleStatement(Statement st) {
    1.16 -	            if(st.getContext().toString().contains("^^<"+TemporalConstants.PERIOD)||st.getContext().toString().contains("^^<"+TemporalConstants.INSTANT))
    1.17 +	        	if(st.getContext() == null)
    1.18 +	        	{ //commented out code so that the statement will be stored in Strabon.Store as it will be handled
    1.19 +	        		/*try {
    1.20 +	        			RDFParser parser = Rio.createParser(RDFFormat.NTRIPLES);
    1.21 +						connection.add(st);
    1.22 +					} catch (RepositoryException e) {
    1.23 +						System.out.println("QuadRDFHandler: error in storing the triple ");
    1.24 +						e.printStackTrace();
    1.25 +					}*/
    1.26 +	        	}
    1.27 +	        	else if(st.getContext().toString().contains("^^<"+TemporalConstants.PERIOD)||st.getContext().toString().contains("^^<"+TemporalConstants.INSTANT))
    1.28  	         	{	
    1.29  	         	    NQuadsParser parser = new NQuadsParser();
    1.30  	         		try {
    1.31 @@ -73,14 +85,13 @@
    1.32  					 
    1.33  					 String triple = "<"+graph.toString()+">"+  " <http://strdf.di.uoa.gr/ontology#hasValidTime> "+ validPeriod+ " .\n" ;
    1.34  				
    1.35 -					 
    1.36  					 try {
    1.37  						//connection.add(new URIImpl("<"+graph.toString()+">"),new URIImpl(" <http://strdf.di.uoa.gr/ontology#hasValidTime>"), new URIImpl(validPeriod));
    1.38  					   StringReader reader = new StringReader(triple);
    1.39  						 connection.add(reader, "null", RDFFormat.NTRIPLES);
    1.40  					 } catch (RepositoryException e) {
    1.41  						// TODO Auto-generated catch block
    1.42 -						System.out.println("Error in QuadRDFHandler: could not store rewritter triple");
    1.43 +						System.out.println("Error in QuadRDFHandler: could not store rewritten triple");
    1.44  						e.printStackTrace();
    1.45  					} catch (IOException e) {
    1.46  						// TODO Auto-generated catch block
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Mar 28 13:49:51 2013 +0200
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Mar 28 16:57:09 2013 +0200
     2.3 @@ -615,29 +615,32 @@
     2.4  			Iterator iterator = statements.iterator();
     2.5  			for(Statement st: statements)
     2.6  			{
     2.7 -				String cont = st.getContext().toString();
     2.8 -				 String validPeriod= cont;
     2.9 -				 if(!cont.contains(","))
    2.10 -				 {
    2.11 -					 int i = cont.indexOf('"')+1;
    2.12 -					 int j = cont.lastIndexOf('"');
    2.13 -					 validPeriod = "\"[" + cont.substring(i,j) + "," + cont.substring(i,j) + "]\"^^<"+TemporalConstants.PERIOD; 
    2.14 -					 //validPeriod = cont.replace("]",","+cont.substring(i, j)+"]");
    2.15 -					 
    2.16 -				 }
    2.17 -				 
    2.18 -				try {
    2.19 -					Resource newContext = new NQuadsParser().createValidTimeURI(validPeriod);
    2.20 -					con1.add(st.getSubject(), st.getPredicate(), st.getObject(), newContext);
    2.21 -				} catch (ParseException e) {
    2.22 -					logger.error(this.getClass().toString()+": error when constructing the new context");
    2.23 -					e.printStackTrace();
    2.24 +				if(st.getContext() == null)
    2.25 +				{ //this statement of the NQUAD graph is a triple- (null context)
    2.26 +
    2.27 +					con1.add(st.getSubject(), st.getPredicate(), st.getObject());
    2.28 +
    2.29  				}
    2.30 -	
    2.31 +				else //this statement of the NQUAD graph is a quad
    2.32 +				{
    2.33 +					String cont = st.getContext().toString();
    2.34 +					 String validPeriod= cont;
    2.35 +					 if(!cont.contains(","))
    2.36 +					 {
    2.37 +						 int i = cont.indexOf('"')+1;
    2.38 +						 int j = cont.lastIndexOf('"');
    2.39 +						 validPeriod = "\"[" + cont.substring(i,j) + "," + cont.substring(i,j) + "]\"^^<"+TemporalConstants.PERIOD; 				 
    2.40 +					 }	 
    2.41 +					try {
    2.42 +						Resource newContext = new NQuadsParser().createValidTimeURI(validPeriod);
    2.43 +						con1.add(st.getSubject(), st.getPredicate(), st.getObject(), newContext);
    2.44 +					} catch (ParseException e) {
    2.45 +						logger.error(this.getClass().toString()+": error when constructing the new context");
    2.46 +						e.printStackTrace();
    2.47 +					}
    2.48 +		
    2.49 +				}
    2.50  			}
    2.51 -			//StringReader quadGraphReader = new StringReader(translator.getHandledTriples().toString());
    2.52 -			//System.out.println("HANDLED TRIPLES" +translator.getHandledTriples().toString());
    2.53 -			//con1.add(quadGraphReader, "", RDFFormat.NTRIPLES);
    2.54  			return;
    2.55  		}
    2.56  		
     3.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/storeTests.java	Thu Mar 28 13:49:51 2013 +0200
     3.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgres/temporals/storeTests.java	Thu Mar 28 16:57:09 2013 +0200
     3.3 @@ -31,7 +31,6 @@
     3.4  
     3.5  
     3.6  /**
     3.7 - * A set of simple tests on query rewriting functionality 
     3.8   * 
     3.9   * @author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
    3.10   */
    3.11 @@ -125,4 +124,42 @@
    3.12  
    3.13  	}
    3.14  	
    3.15 +	@Test
    3.16 +	public void testStoreNQUADString() 
    3.17 +	{
    3.18 +		String text1 = "<http://example.org/itemOfString1> <http://example.org/id> \"String111\" \"[2005-11-19T12:41:00,2010-11-19T13:41:00]\"^^<http://strdf.di.uoa.gr/ontology#period> . \n" +
    3.19 +				"<http://example.org/itemOfString2> <http://example.org/id> \"String112\" \"[2005-11-19T12:42:00,2010-11-19T13:41:00]\"^^<http://strdf.di.uoa.gr/ontology#period>.";
    3.20 +		
    3.21 +		String text2 = "<http://example.org/itemOfString31> <http://example.org/id> \"String3121\"  . \n" +
    3.22 +				"<http://example.org/itemOfString322> <http://example.org/id> \"String3122\" .";
    3.23 +		try {
    3.24 +			strabon.storeInRepo(text1, "NQUADS");
    3.25 +			strabon.storeInRepo(text2, "NQUADS");
    3.26 +
    3.27 +		} catch (RDFParseException e) {
    3.28 +			// TODO Auto-generated catch block
    3.29 +			e.printStackTrace();
    3.30 +		} catch (RepositoryException e) {
    3.31 +			// TODO Auto-generated catch block
    3.32 +			e.printStackTrace();
    3.33 +		} catch (RDFHandlerException e) {
    3.34 +			// TODO Auto-generated catch block
    3.35 +			e.printStackTrace();
    3.36 +		} catch (IOException e) {
    3.37 +			// TODO Auto-generated catch block
    3.38 +			e.printStackTrace();
    3.39 +		} catch (InvalidDatasetFormatFault e) {
    3.40 +			// TODO Auto-generated catch block
    3.41 +			e.printStackTrace();
    3.42 +		}
    3.43 +		
    3.44 +	}
    3.45 +	
    3.46 +	@Test
    3.47 +	public void testNQUADSFile() throws RDFParseException, RepositoryException, RDFHandlerException, IOException, InvalidDatasetFormatFault 
    3.48 +	{
    3.49 +		strabon.storeInRepo("/triples-and-quads.nq", "NQUADS");
    3.50 +
    3.51 +	}
    3.52 +	
    3.53  }
    3.54 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/runtime/src/test/resources/triples-and-quads.nq	Thu Mar 28 16:57:09 2013 +0200
     4.3 @@ -0,0 +1,15 @@
     4.4 +<http://example.org/item1> <http://example.org/id> "1"^^<http://www.w3.org/2001/XMLSchema#int> "[2012-11-19T12:41:00,2012-11-19T13:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
     4.5 +<http://example.org/item2> <http://example.org/id> "332"^^<http://www.w3.org/2001/XMLSchema#int> .
     4.6 +<http://example.org/item3> <http://example.org/id> "3"^^<http://www.w3.org/2001/XMLSchema#int> "[2012-11-19T12:41:00,2012-11-19T13:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
     4.7 +<http://example.org/item1> <http://example.org/value> "310"^^<http://www.w3.org/2001/XMLSchema#int> .
     4.8 +<http://example.org/item2> <http://example.org/value> "320"^^<http://www.w3.org/2001/XMLSchema#int> .
     4.9 +<http://example.org/item1> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(1 0)"^^<http://strdf.di.uoa.gr/ontology#WKT> "[2012-11-19T12:41:00+02,2012-11-19T13:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
    4.10 +<http://example.org/item2> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(2 0)"^^<http://strdf.di.uoa.gr/ontology#WKT> "[2012-11-19T12:41:00+02,2012-11-19T13:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
    4.11 +<http://example.org/item3> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#hasGeometry> "POINT(3 0)"^^<http://strdf.di.uoa.gr/ontology#WKT> "[2012-11-19t12:41:00+02,2012-11-19T13:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
    4.12 +<http://example.org/item1> <http://example.org/value> "10"^^<http://www.w3.org/2001/XMLSchema#int> "[2012-11-19T10:41:00,2012-11-19T11:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
    4.13 +<http://example.org/item2> <http://example.org/value> "20"^^<http://www.w3.org/2001/XMLSchema#int> "[2012-11-19T10:41:00,2012-11-19T15:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
    4.14 +<http://example.org/item34> <http://example.org/value3> "320"^^<http://www.w3.org/2001/XMLSchema#int>  .
    4.15 +<http://example.org/item35> <http://example.org/value3> "320"^^<http://www.w3.org/2001/XMLSchema#int>  .
    4.16 +<http://example.org/item6> <http://example.org/value> "20"^^<http://www.w3.org/2001/XMLSchema#int> "2012-01-19T12:41:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
    4.17 +<http://example.org/item7> <http://example.org/id> "7"^^<http://www.w3.org/2001/XMLSchema#int> "[2012-11-19T13:41:00,2012-11-19T14:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.
    4.18 +<http://example.org/item8> <http://example.org/id> "8"^^<http://www.w3.org/2001/XMLSchema#int> "[2012-11-19T14:41:00.000001,2012-11-19T15:41:00]"^^<http://strdf.di.uoa.gr/ontology#period>.