Strabon

changeset 226:dbbfb1a23017

removed Strabon.storeInRepo and Strabon.storeFile that were not used anymore, and made the first argument of store methods to be String, instead of object
author Babis Nikolaou <charnik@di.uoa.gr>
date Sat Jun 02 18:06:53 2012 +0300 (2012-06-02)
parents bd824b11051a
children d9d201dcc4c6
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/testCRS.java runtime/src/test/java/eu/earthobservatory/runtime/monetdb/TemplateTests.java runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java scripts/strabon
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Sat Jun 02 01:18:19 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Sat Jun 02 18:06:53 2012 +0300
     1.3 @@ -786,17 +786,12 @@
     1.4  //		System.out.println("-------------------------------------------");
     1.5  	}
     1.6  
     1.7 -	@SuppressWarnings("unused")
     1.8 -	private void store(File file, String baseURI, RDFFormat format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault {
     1.9 -		con1.add(file, baseURI, format);
    1.10 -	}
    1.11 -
    1.12 -	public void storeInRepo(Object src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException
    1.13 +	public void storeInRepo(String src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException
    1.14  	{
    1.15  		storeInRepo(src, null, null, format);
    1.16  	}
    1.17  
    1.18 -	public void storeInRepo(Object src, String baseURI, String context, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException
    1.19 +	public void storeInRepo(String src, String baseURI, String context, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException
    1.20  	{
    1.21  		RDFFormat realFormat = null;
    1.22  
    1.23 @@ -873,34 +868,6 @@
    1.24  		}*/
    1.25  	}
    1.26  
    1.27 -	private void storeFile(File file, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException
    1.28 -	{
    1.29 -		logger.info("[Strabon.storeFile] File     : " + file.getName());
    1.30 -		logger.info("[Strabon.storeFile] Base URI : " + ((baseURI == null) ? "null" : baseURI));
    1.31 -		logger.info("[Strabon.storeFile] Context  : " + ((context == null) ? "null" : context));
    1.32 -		logger.info("[Strabon.storeFile] Format   : " + ((format == null) ? "null" : format.toString()));
    1.33 -
    1.34 -		RDFParser parser = Rio.createParser(format);
    1.35 -		GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase();
    1.36 -		FileReader reader = new FileReader(file);
    1.37 -		handler.startRDF();
    1.38 -		parser.setRDFHandler(handler);
    1.39 -		parser.parse(reader, "");
    1.40 -		logger.info("[Strabon.storeFile] Inferred " + handler.getNumberOfTriples() + " triples.");
    1.41 -		if (handler.getNumberOfTriples() > 0) {
    1.42 -			logger.info("[Strabon.storeFile] Triples inferred:"+ handler.getTriples().toString());
    1.43 -		}
    1.44 -		StringReader georeader= new StringReader(handler.getTriples().toString());
    1.45 -		handler.endRDF();
    1.46 -		if (context == null) {
    1.47 -			con1.add(file, baseURI, format);
    1.48 -		} else {
    1.49 -			con1.add(file, baseURI, format, context);
    1.50 -		}
    1.51 -		con1.add(georeader, "", RDFFormat.NTRIPLES);
    1.52 -
    1.53 -	}
    1.54 -
    1.55  	private void storeURL(URL url, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException
    1.56  	{
    1.57  		logger.info("[Strabon.storeURL] URL      : " + url.toString());
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java	Sat Jun 02 01:18:19 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java	Sat Jun 02 18:06:53 2012 +0300
     2.3 @@ -35,11 +35,7 @@
     2.4  		}
     2.5  
     2.6  		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
     2.7 -		
     2.8 -		File file = new File (src);
     2.9 -		strabon.storeInRepo(file, format);
    2.10 -//		strabon.storeInRepo(file, null, null, fileRDFFormat);
    2.11 -
    2.12 +		strabon.storeInRepo(src, format);
    2.13  		strabon.close();
    2.14  	}
    2.15  
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/testCRS.java	Sat Jun 02 01:18:19 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/testCRS.java	Sat Jun 02 18:06:53 2012 +0300
     3.3 @@ -1,15 +1,12 @@
     3.4  package eu.earthobservatory.runtime.postgis;
     3.5 +import java.io.IOException;
     3.6 +import java.net.URL;
     3.7 +import java.sql.SQLException;
     3.8 +
     3.9  import org.openrdf.repository.RepositoryException;
    3.10 -
    3.11 -
    3.12 -import org.openrdf.rio.RDFFormat;
    3.13  import org.openrdf.rio.RDFHandlerException;
    3.14  import org.openrdf.rio.RDFParseException;
    3.15  
    3.16 -import java.io.File;
    3.17 -import java.io.IOException;
    3.18 -import java.net.URL;
    3.19 -import java.sql.SQLException;
    3.20  import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    3.21  
    3.22  public class testCRS {
    3.23 @@ -42,7 +39,7 @@
    3.24  				"\"^^<http://strdf.di.uoa.gr/ontology#WKT> .";
    3.25  		String gml =  "<http://example.org/rcc8Obj1> <http://example.org/hasGeometry> \"<gml:Point> <gml:coordinates>45.67, 88.56</gml:coordinates> </gml:Point>\"^^<http://strdf.di.uoa.gr/ontology#GML> .\n";
    3.26  				
    3.27 -		File file = new File ("/home/konstantina/gmlread.nt");
    3.28 +		String file = "/home/konstantina/gmlread.nt";
    3.29  		URL url = new URL("http://www.di.uoa.gr/~pms509/rdf-data/streason.nt");
    3.30  		String fileBaseURI = "http://example#";
    3.31  		String fileRDFFormat = "NTRIPLES";
    3.32 @@ -52,23 +49,16 @@
    3.33  			//strabon.storeInRepo(statement1, stringBaseURI, null, stringRDFFormat);
    3.34  			//strabon.storeInRepo(statement2, stringBaseURI, null, stringRDFFormat);
    3.35  			//strabon.storeInRepo(text, null, null, "NTRIPLES");
    3.36 -			strabon.storeInRepo(file, null, null, fileRDFFormat);
    3.37 +			strabon.storeInRepo(file, fileRDFFormat);
    3.38  			//strabon.storeInRepo(gml, null, null, fileRDFFormat);
    3.39 +			
    3.40  		} catch (RDFParseException e) {
    3.41 -			// TODO Auto-generated catch block
    3.42  			e.printStackTrace();
    3.43 -			strabon.close();
    3.44  		} catch (RepositoryException e) {
    3.45 -			// TODO Auto-generated catch block
    3.46 -			strabon.close();
    3.47  			e.printStackTrace();
    3.48  		} catch (IOException e) {
    3.49 -			// TODO Auto-generated catch block
    3.50 -			strabon.close();
    3.51  			e.printStackTrace();
    3.52  		} catch (InvalidDatasetFormatFault e) {
    3.53 -			// TODO Auto-generated catch block
    3.54 -			strabon.close();
    3.55  			e.printStackTrace();
    3.56  		}
    3.57  		finally{
     4.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/monetdb/TemplateTests.java	Sat Jun 02 01:18:19 2012 +0300
     4.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/monetdb/TemplateTests.java	Sat Jun 02 18:06:53 2012 +0300
     4.3 @@ -78,8 +78,7 @@
     4.4  	protected static void loadTestData(String inputfile, Strabon strabon)
     4.5  			throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault
     4.6  		{
     4.7 -			URL src = SimpleTests.class.getResource(inputfile);
     4.8 -			strabon.storeInRepo(src, "NTRIPLES");
     4.9 +			strabon.storeInRepo(inputfile, "NTRIPLES");
    4.10  		}
    4.11  	
    4.12  //	/**
     5.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Sat Jun 02 01:18:19 2012 +0300
     5.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Sat Jun 02 18:06:53 2012 +0300
     5.3 @@ -86,8 +86,7 @@
     5.4  	protected static void loadTestData(String inputfile, Strabon strabon)
     5.5  		throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault
     5.6  	{
     5.7 -		URL src = SimpleTests.class.getResource(inputfile);
     5.8 -		strabon.storeInRepo(src, "NTRIPLES");
     5.9 +		strabon.storeInRepo(inputfile, "NTRIPLES");
    5.10  	}
    5.11  	
    5.12  //	/**
     6.1 --- a/scripts/strabon	Sat Jun 02 01:18:19 2012 +0300
     6.2 +++ b/scripts/strabon	Sat Jun 02 18:06:53 2012 +0300
     6.3 @@ -1,26 +1,59 @@
     6.4  #!/bin/bash
     6.5  #
     6.6  # Script for running the main classes of Strabon. The main classes of Strabon comprises
     6.7 -# QueryOp, StoreOp, etc.
     6.8 +# QueryOp, , UpdateOp, and StoreOp.
     6.9  #
    6.10  # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
    6.11  #
    6.12  
    6.13 +# command name
    6.14 +CMD="$(basename ${0})"
    6.15 +
    6.16  # absolute directory name of this command
    6.17  LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
    6.18  
    6.19  RUNTIME="${LOC}/../runtime"
    6.20  
    6.21  function help() {
    6.22 -	echo "Usage: `basename ${0}` [OPTIONS] COMMAND ARGS"
    6.23 +	echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
    6.24  	echo
    6.25  	echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, etc."
    6.26  	echo
    6.27  	echo "	COMMAND	 : one of \`query', \`update', \`store', or \`help'"
    6.28  	echo "	ARGS	 : arguments according to selected command"
    6.29 -	echo 
    6.30 -#	echo "OPTIONS can be any of the following"
    6.31 -#	echo "	-d	 : don't run, just print what shall be executed"
    6.32 +	echo
    6.33 +	echo "OPTIONS can be any of the following"
    6.34 +	echo "	-d	 : don't run, just print what shall be executed"
    6.35 +	echo "	-c FILE	 : configuration file to use for the connection. It defaults to \`${HOME}/.strabon'."
    6.36 +}
    6.37 +
    6.38 +function help_query() {
    6.39 +	echo "Usage: ${CMD} query SPARQL_QUERY"
    6.40 +	echo
    6.41 +	echo "Execute a SPARQL query on Strabon."
    6.42 +	echo
    6.43 +	echo "	SPARQL_QUERY	: the SPARQL query to execute or an alias name such as the following:"
    6.44 +	echo "				size: returns the number of triples"
    6.45 +}
    6.46 +
    6.47 +function help_update() {
    6.48 +	echo "Usage: ${CMD} update SPARQL_UPDATE"
    6.49 +	echo
    6.50 +	echo "Execute a SPARQL Update query on Strabon."
    6.51 +	echo
    6.52 +	echo "	SPARQL_UPDATE	: the SPARQL update query to execute or an alias name such as the"
    6.53 +	echo "			  the following:"
    6.54 +	echo "				clear: deletes all triples"
    6.55 +}
    6.56 +
    6.57 +function help_store() {
    6.58 +	echo "Usage: ${CMD} store FILE"
    6.59 +	echo
    6.60 +	echo "Store an RDF document or ??? in Strabon."
    6.61 +	echo
    6.62 +	echo "	FILE	: the file containing the RDF document to store. It can be a filename or a URL"
    6.63 +	echo "		  (i.e., file:///tmp/file.nt, http://www.example.org/file.nt,"
    6.64 +	echo "		  ftp://www.example.org/file.nt, etc.)"
    6.65  }
    6.66  
    6.67  # runtime package
    6.68 @@ -40,6 +73,7 @@
    6.69  
    6.70  # the database name to connect to
    6.71  DB="endpoint"
    6.72 +DB="strabon"
    6.73  
    6.74  # the username for the database connection
    6.75  DBUSER="charnik"
    6.76 @@ -58,13 +92,30 @@
    6.77  #-Dlog4j.debug
    6.78  #-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
    6.79  
    6.80 +# just print what shall be executed
    6.81  DEBUG=0
    6.82 -#case "${1}" in
    6.83 -#	-d)
    6.84 -#		shift
    6.85 -#		DEBUG=1
    6.86 -#		;;
    6.87 -#esac
    6.88 +
    6.89 +# configuration file for the Strabon connection
    6.90 +STRABON_CONF="${HOME}/.strabon"
    6.91 +case "${1}" in
    6.92 +	-d)
    6.93 +		shift
    6.94 +		DEBUG=1
    6.95 +		;;
    6.96 +	-c)
    6.97 +		shift
    6.98 +		if ! test $# -gt 1; then
    6.99 +			help
   6.100 +			exit 1
   6.101 +		fi
   6.102 +		STRABON_CONF="${1}"
   6.103 +		if ! test -e "${STRABON_CONF}"; then
   6.104 +			echo "${CMD}: configuration file \"${1}\" does not exist."
   6.105 +			exit 1
   6.106 +		fi
   6.107 +		shift
   6.108 +		;;
   6.109 +esac
   6.110  
   6.111  case "${1}" in
   6.112  	help)
   6.113 @@ -141,14 +192,14 @@
   6.114  		;;
   6.115  esac
   6.116  
   6.117 -CMD="(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${QUERY}\")"
   6.118 +STRABON_EXEC="(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${QUERY}\")"
   6.119  
   6.120  # execute or debug
   6.121  if test ${DEBUG} -eq 1; then
   6.122  	echo "`basename ${0}`: Debug is ON"
   6.123  	echo "`basename ${0}`: Printing command for execution"	
   6.124 -	echo "	${CMD}"
   6.125 +	echo "	${STRABON_EXEC}"
   6.126  else
   6.127 -	eval ${CMD}
   6.128 +	eval ${STRABON_EXEC}
   6.129  fi
   6.130