Strabon

changeset 809:03a464962cbb

modified StoreOp to accept another optional argument for storing RDF files in given named graphs.
For this, the optional argument for the RDF format now it must be given together with an option -f FORMAT.
Option -g has been also added: -g NAMED_GRAPH

The strabon script has been updated accordingly
author Babis Nikolaou <charnik@di.uoa.gr>
date Mon Dec 17 18:14:19 2012 +0200 (2012-12-17)
parents bf75e2888730
children 35ac9525856c
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/StoreOp.java scripts/strabon
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Dec 11 19:33:47 2012 +0200
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Mon Dec 17 18:14:19 2012 +0200
     1.3 @@ -372,9 +372,9 @@
     1.4  	{
     1.5  		logger.info("[Strabon.storeURL] Storing file.");
     1.6  		logger.info("[Strabon.storeURL] URL      : {}", url.toString());
     1.7 +		logger.info("[Strabon.storeURL] Context  : {}", ((context == null) ? "default" : context));
     1.8  		if (logger.isDebugEnabled()) {
     1.9  			logger.debug("[Strabon.storeURL] Base URI : {}", ((baseURI == null) ? "null" : baseURI));
    1.10 -			logger.debug("[Strabon.storeURL] Context  : {}", ((context == null) ? "null" : context));
    1.11  			logger.debug("[Strabon.storeURL] Format   : {}", ((format == null) ? "null" : format));
    1.12  		}
    1.13  
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java	Tue Dec 11 19:33:47 2012 +0200
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/StoreOp.java	Mon Dec 17 18:14:19 2012 +0200
     2.3 @@ -23,15 +23,8 @@
     2.4  	public static void main(String[] args) {
     2.5  
     2.6  		if (args.length < 6) {
     2.7 -			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> ");
     2.8 -			System.err.println("       where <HOST>       is the postgis database host to connect to");
     2.9 -			System.err.println("             <PORT>       is the port to connect to on the database host");		
    2.10 -			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    2.11 -			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    2.12 -			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    2.13 -			System.err.println("             <FILE>       is the file to be stored");
    2.14 -			System.err.println("             [<FORMAT>]   is the format of the file (NTRIPLES)");
    2.15 -			System.exit(0);
    2.16 +			help();
    2.17 +			System.exit(1);
    2.18  		}
    2.19  
    2.20  		String host = args[0];
    2.21 @@ -41,14 +34,44 @@
    2.22  		String passwd = args[4];		
    2.23  		String src = args[5];
    2.24  		String format = "NTRIPLES";
    2.25 -		if ( args.length == 7 ) {
    2.26 -			format = args[6];
    2.27 +		String graph = null;
    2.28 +		
    2.29 +		for (int i = 6; i < args.length; i += 2) {
    2.30 +			if (args[i].equals("-f")) {
    2.31 +				if (i + 1 >= args.length) {
    2.32 +					System.err.println("Option \"-f\" requires an argument.");
    2.33 +					help();
    2.34 +					System.exit(1);
    2.35 +					
    2.36 +				} else {
    2.37 +					format = args[i+1];
    2.38 +				}
    2.39 +			} else if (args[i].equals("-g")) {
    2.40 +				if (i + 1 >= args.length) {
    2.41 +					System.err.println("Option \"-g\" requires an argument.");
    2.42 +					help();
    2.43 +					System.exit(1);
    2.44 +					
    2.45 +				} else {
    2.46 +					graph = args[i+1];
    2.47 +				}
    2.48 +				
    2.49 +			} else {
    2.50 +				System.err.println("Unknown argument \"" + args[i] + "\".");
    2.51 +				help();
    2.52 +				System.exit(1);
    2.53 +			}
    2.54  		}
    2.55  
    2.56  		Strabon strabon = null;
    2.57  		try {
    2.58  			strabon = new Strabon(db, user, passwd, port, host, false);
    2.59 -			strabon.storeInRepo(src, format);
    2.60 +			if (graph == null) {
    2.61 +				strabon.storeInRepo(src, format);
    2.62 +				
    2.63 +			} else {
    2.64 +				strabon.storeInRepo(src, null, graph, format);
    2.65 +			}
    2.66  		
    2.67  		} catch (Exception e) {
    2.68  			logger.error("[Strabon.StoreOp] Error during store.", e);
    2.69 @@ -59,5 +82,17 @@
    2.70  			}
    2.71  		}
    2.72  	}
    2.73 +	
    2.74 +	private static void help() {
    2.75 +		System.err.println("Usage: eu.earthobservatory.runtime.monetdb.StoreOp <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <FILE> [-f <FORMAT>] [-g <NAMED_GRAPH>]");
    2.76 +		System.err.println("       where <HOST>       		 is the postgis database host to connect to");
    2.77 +		System.err.println("             <PORT>       		 is the port to connect to on the database host");		
    2.78 +		System.err.println("             <DATABASE>   		 is the spatially enabled postgis database that Strabon will use as a backend, ");
    2.79 +		System.err.println("             <USERNAME>   		 is the username to use when connecting to the database ");
    2.80 +		System.err.println("             <PASSWORD>   		 is the password to use when connecting to the database");
    2.81 +		System.err.println("             <FILE>       		 is the file to be stored");
    2.82 +		System.err.println("             [-f <FORMAT>] 		 is the format of the file (default: NTRIPLES)");
    2.83 +		System.err.println("             [-g <NAMED_GRAPH>]  is the URI of the named graph to store the input file (default: default graph)");
    2.84 +	}
    2.85  
    2.86  }
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Tue Dec 11 19:33:47 2012 +0200
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Mon Dec 17 18:14:19 2012 +0200
     3.3 @@ -23,16 +23,8 @@
     3.4  	public static void main(String[] args) {
     3.5  
     3.6  		if (args.length < 6) {
     3.7 -			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <FILE> [<FORMAT>]");
     3.8 -			System.err.println("       where <HOST>       is the postgis database host to connect to");
     3.9 -			System.err.println("             <PORT>       is the port to connect to on the database host");		
    3.10 -			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    3.11 -			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    3.12 -			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    3.13 -			System.err.println("             <FILE>       is the file to be stored");
    3.14 -			System.err.println("             [<FORMAT>]   is the format of the file (default: NTRIPLES)");
    3.15 -			System.err.println("Args: "+args.length);
    3.16 -			System.exit(0);
    3.17 +			help();
    3.18 +			System.exit(1);
    3.19  		}
    3.20  
    3.21  		String host = args[0];
    3.22 @@ -42,14 +34,44 @@
    3.23  		String passwd = args[4];		
    3.24  		String src = args[5];
    3.25  		String format = "NTRIPLES";
    3.26 -		if ( args.length == 7 ) {
    3.27 -			format = args[6];
    3.28 +		String graph = null;
    3.29 +		
    3.30 +		for (int i = 6; i < args.length; i += 2) {
    3.31 +			if (args[i].equals("-f")) {
    3.32 +				if (i + 1 >= args.length) {
    3.33 +					System.err.println("Option \"-f\" requires an argument.");
    3.34 +					help();
    3.35 +					System.exit(1);
    3.36 +					
    3.37 +				} else {
    3.38 +					format = args[i+1];
    3.39 +				}
    3.40 +			} else if (args[i].equals("-g")) {
    3.41 +				if (i + 1 >= args.length) {
    3.42 +					System.err.println("Option \"-g\" requires an argument.");
    3.43 +					help();
    3.44 +					System.exit(1);
    3.45 +					
    3.46 +				} else {
    3.47 +					graph = args[i+1];
    3.48 +				}
    3.49 +				
    3.50 +			} else {
    3.51 +				System.err.println("Unknown argument \"" + args[i] + "\".");
    3.52 +				help();
    3.53 +				System.exit(1);
    3.54 +			}
    3.55  		}
    3.56  
    3.57  		Strabon strabon = null;
    3.58  		try {
    3.59  			strabon = new Strabon(db, user, passwd, port, host, false);
    3.60 -			strabon.storeInRepo(src, format);
    3.61 +			if (graph == null) {
    3.62 +				strabon.storeInRepo(src, format);
    3.63 +				
    3.64 +			} else {
    3.65 +				strabon.storeInRepo(src, null, graph, format);
    3.66 +			}
    3.67  			
    3.68  		} catch (Exception e) {
    3.69  			logger.error("[Strabon.StoreOp] Error during store.", e);
    3.70 @@ -61,4 +83,15 @@
    3.71  		}
    3.72  	}
    3.73  
    3.74 +	private static void help() {
    3.75 +		System.err.println("Usage: eu.earthobservatory.runtime.postgis.StoreOp <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <FILE> [-f <FORMAT>] [-g <NAMED_GRAPH>]");
    3.76 +		System.err.println("       where <HOST>       		 is the postgis database host to connect to");
    3.77 +		System.err.println("             <PORT>       		 is the port to connect to on the database host");		
    3.78 +		System.err.println("             <DATABASE>   		 is the spatially enabled postgis database that Strabon will use as a backend, ");
    3.79 +		System.err.println("             <USERNAME>   		 is the username to use when connecting to the database ");
    3.80 +		System.err.println("             <PASSWORD>   		 is the password to use when connecting to the database");
    3.81 +		System.err.println("             <FILE>       		 is the file to be stored");
    3.82 +		System.err.println("             [-f <FORMAT>] 		 is the format of the file (default: NTRIPLES)");
    3.83 +		System.err.println("             [-g <NAMED_GRAPH>]  is the URI of the named graph to store the input file (default: default graph)");
    3.84 +	}
    3.85  }
     4.1 --- a/scripts/strabon	Tue Dec 11 19:33:47 2012 +0200
     4.2 +++ b/scripts/strabon	Mon Dec 17 18:14:19 2012 +0200
     4.3 @@ -55,6 +55,9 @@
     4.4  # the RDF format of the files to store (defaults to ntriples)
     4.5  FORMAT="ntriples"
     4.6  
     4.7 +# the URI of the named graph into which the RDF files shall be stored
     4.8 +NAMED_GRAPH=
     4.9 +
    4.10  # predefined queries
    4.11  QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
    4.12  QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
    4.13 @@ -161,6 +164,8 @@
    4.14  	echo "OPTIONS can be one of the following"
    4.15  	echo "	-f FORMAT : the RDF format of the files to store. The format can be one of the following:"
    4.16  	echo "		    \`ntriples' (default), \`n3', \`rdfxml', or \`turtle'."
    4.17 +	echo "	-g NAMED_GRAPH : the URI of the named graph into which the RDF files shall be stored"
    4.18 +	echo "	                 (defaults to the default graph)."
    4.19  }
    4.20  
    4.21  function help_describe() {
    4.22 @@ -455,31 +460,49 @@
    4.23  			help_store
    4.24  			exit 1
    4.25  		fi
    4.26 -		# check whether format is specified
    4.27 -		if test "${1}" = "-f"; then
    4.28 -			shift
    4.29 -			if ! test $# -ge 1; then
    4.30 -				echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')"
    4.31 -				exit 2
    4.32 -			else
    4.33 -				FORMAT="${1}"
    4.34 -				case "${FORMAT}" in
    4.35 -					ntriples|n3|rdfxml|turtle)
    4.36 -						shift
    4.37 -						;;
    4.38 -					*)
    4.39 -						echo "${CMD}: invalid RDF format \"${FORMAT}\"."
    4.40 -						echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'"
    4.41 -						exit 2
    4.42 -						;;
    4.43 -				esac
    4.44 +
    4.45 +		while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
    4.46 +			# check whether format is specified
    4.47 +			if test "${1}" = "-f"; then
    4.48 +				shift
    4.49 +				if ! test $# -ge 1; then
    4.50 +					echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')"
    4.51 +					exit 2
    4.52 +				else
    4.53 +					FORMAT="${1}"
    4.54 +					case "${FORMAT}" in
    4.55 +						ntriples|n3|rdfxml|turtle)
    4.56 +							shift
    4.57 +							;;
    4.58 +						*)
    4.59 +							echo "${CMD}: invalid RDF format \"${FORMAT}\"."
    4.60 +							echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'"
    4.61 +							exit 2
    4.62 +							;;
    4.63 +					esac
    4.64 +				fi
    4.65  			fi
    4.66 -		fi
    4.67 +
    4.68 +			# check whether a named graph is specified
    4.69 +			if test "${1}" = "-g"; then
    4.70 +				shift
    4.71 +				if ! test $# -ge 1; then
    4.72 +					echo "${CMD}: Option -g requires a URI argument"
    4.73 +					exit 2
    4.74 +				else
    4.75 +					NAMED_GRAPH="-g ${1}"
    4.76 +					shift
    4.77 +				fi
    4.78 +			fi
    4.79 +
    4.80 +		done
    4.81 +
    4.82  		# if no files are given
    4.83  		if ! test $# -ge 1; then
    4.84  			help_store
    4.85  			exit 1
    4.86  		fi
    4.87 +
    4.88  		# do not make an assignment of the files to QUERY
    4.89  		# handle the case of storing multiple files afterwards
    4.90  		# QUERY="${@}"
    4.91 @@ -537,7 +560,7 @@
    4.92  			file="$(pwd)/${file}"
    4.93  		fi
    4.94  
    4.95 -		STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" ${FORMAT});
    4.96 +		STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" -f ${FORMAT} ${NAMED_GRAPH});
    4.97  "
    4.98  	done
    4.99  else