Strabon

changeset 8:aa5d6be7ba75

add StoreOp, DescribeOp, QueryOp in runtime.postgis
correct bug about geoValues deletion and function calls with only one argument
author Giorgos Garbis <ggarbis@di.uoa.gr>
date Fri Feb 03 21:21:27 2012 +0200 (2012-02-03)
parents b6efeb63fa65
children fca0b46359d0
files .hgignore generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/UpdateOp.java
line diff
     1.1 --- a/.hgignore	Fri Feb 03 15:22:18 2012 +0200
     1.2 +++ b/.hgignore	Fri Feb 03 21:21:27 2012 +0200
     1.3 @@ -1,6 +1,2 @@
     1.4  /target$
     1.5 -\.project
     1.6 -\.hgignore
     1.7 -classpath
     1.8 -settings
     1.9  
     2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Fri Feb 03 15:22:18 2012 +0200
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Fri Feb 03 21:21:27 2012 +0200
     2.3 @@ -113,7 +113,7 @@
     2.4  	{
     2.5  		removeStatementsInternal(null, null, null, contexts);
     2.6  		//XXX our code
     2.7 -		triples.clearGeoValues();
     2.8 +//		triples.clearGeoValues();
     2.9  	}
    2.10  
    2.11  	@Override
     3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Feb 03 15:22:18 2012 +0200
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Feb 03 21:21:27 2012 +0200
     3.3 @@ -292,9 +292,10 @@
     3.4  		}
     3.5  
     3.6  
     3.7 -		if(!(function instanceof EnvelopeFunc) 
     3.8 -				&& !(function instanceof ConvexHullFunc) 
     3.9 -				&& !(function instanceof BoundaryFunc))
    3.10 +//		if(!(function instanceof EnvelopeFunc) 
    3.11 +//				&& !(function instanceof ConvexHullFunc) 
    3.12 +//				&& !(function instanceof BoundaryFunc))
    3.13 +		if ( fc.getArgs().size() == 2 )
    3.14  		{
    3.15  			ValueExpr right = fc.getArgs().get(1);
    3.16  			try {
    3.17 @@ -304,8 +305,8 @@
    3.18  			} catch (QueryEvaluationException e) {
    3.19  				e.printStackTrace();
    3.20  			}
    3.21 -
    3.22  		}
    3.23 +		
    3.24  		try {
    3.25  			if ( function instanceof SpatialConstructFunc ) 
    3.26  				return spatialConstructPicker(function, leftResult, rightResult);
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Feb 03 15:22:18 2012 +0200
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Feb 03 21:21:27 2012 +0200
     4.3 @@ -2,7 +2,10 @@
     4.4  
     4.5  import java.io.DataOutputStream;
     4.6  import java.io.File;
     4.7 +import java.io.FileNotFoundException;
     4.8 +import java.io.FileOutputStream;
     4.9  import java.io.IOException;
    4.10 +import java.io.OutputStream;
    4.11  import java.io.OutputStreamWriter;
    4.12  import java.io.StringReader;
    4.13  import java.net.URL;
    4.14 @@ -22,6 +25,7 @@
    4.15  import org.openrdf.model.ValueFactory;
    4.16  import org.openrdf.query.Binding;
    4.17  import org.openrdf.query.BindingSet;
    4.18 +import org.openrdf.query.GraphQuery;
    4.19  import org.openrdf.query.MalformedQueryException;
    4.20  import org.openrdf.query.QueryEvaluationException;
    4.21  import org.openrdf.query.QueryLanguage;
    4.22 @@ -35,7 +39,10 @@
    4.23  import org.openrdf.repository.sail.SailRepository;
    4.24  import org.openrdf.repository.sail.SailRepositoryConnection;
    4.25  import org.openrdf.rio.RDFFormat;
    4.26 +import org.openrdf.rio.RDFHandler;
    4.27 +import org.openrdf.rio.RDFHandlerException;
    4.28  import org.openrdf.rio.RDFParseException;
    4.29 +import org.openrdf.rio.ntriples.NTriplesWriter;
    4.30  import org.openrdf.sail.helpers.SailBase;
    4.31  
    4.32  import com.vividsolutions.jts.geom.Geometry;
    4.33 @@ -510,9 +517,11 @@
    4.34  		System.out.println("-------------------------------------------");
    4.35  	}
    4.36  
    4.37 +	@SuppressWarnings("unused")
    4.38  	private void store(File file, String baseURI, RDFFormat format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault {
    4.39  		con1.add(file, baseURI, format);
    4.40  	}
    4.41 +	
    4.42  	public void storeInRepo(Object src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault
    4.43  	{
    4.44  		storeInRepo(src, null, null, format);
    4.45 @@ -629,4 +638,41 @@
    4.46  		}
    4.47  	}
    4.48  
    4.49 +	public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException
    4.50 +	{
    4.51 +		GraphQuery  graphQuery = null;
    4.52 +		
    4.53 +		try {
    4.54 +			graphQuery = con.prepareGraphQuery(QueryLanguage.SPARQL, describeString);
    4.55 +		} catch (RepositoryException e) {
    4.56 +			e.printStackTrace();
    4.57 +		}
    4.58 +		
    4.59 +		System.out.println("Placemark0");
    4.60 +		System.out.println("\n\n\nGot query: " + describeString + "\n\n\n");
    4.61 +
    4.62 +		try {
    4.63 +			OutputStream out = new FileOutputStream(outFile);
    4.64 +			RDFHandler rdfHandler = new NTriplesWriter(out);
    4.65 +			graphQuery.evaluate(rdfHandler);
    4.66 +			out.close();
    4.67 +		} catch (FileNotFoundException e) {
    4.68 +			// TODO Auto-generated catch block
    4.69 +			e.printStackTrace();
    4.70 +		} catch (QueryEvaluationException e) {
    4.71 +			// TODO Auto-generated catch block
    4.72 +			e.printStackTrace();
    4.73 +		} catch (RDFHandlerException e) {
    4.74 +			// TODO Auto-generated catch block
    4.75 +			e.printStackTrace();
    4.76 +		} catch (IOException e) {
    4.77 +			// TODO Auto-generated catch block
    4.78 +			e.printStackTrace();
    4.79 +		}
    4.80 +
    4.81 +		System.out.println("Output: "+outFile);
    4.82 +		System.out.println("---------------------------------------------");
    4.83 +		System.out.println("-            DESCRIBE EXECUTED              -");
    4.84 +		System.out.println("---------------------------------------------");
    4.85 +	}
    4.86  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Fri Feb 03 21:21:27 2012 +0200
     5.3 @@ -0,0 +1,37 @@
     5.4 +package eu.earthobservatory.runtime.postgis;
     5.5 +
     5.6 +
     5.7 +public class DescribeOp {
     5.8 +
     5.9 +	/**
    5.10 +	 * @param args
    5.11 +	 * @throws Exception 
    5.12 +	 */
    5.13 +	public static void main(String[] args) throws Exception {
    5.14 +
    5.15 +		if (args.length < 7) {
    5.16 +			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <OUTPUT>");
    5.17 +			System.err.println("       where <HOST>       is the postgis database host to connect to");
    5.18 +			System.err.println("             <PORT>       is the port to connect to on the database host");		
    5.19 +			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    5.20 +			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    5.21 +			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    5.22 +			System.err.println("             <QUERY>      is the stSPARQL query to evaluate.");
    5.23 +			System.err.println("             <OUTPUT>      is the stSPARQL query to evaluate.");
    5.24 +			System.exit(0);
    5.25 +		}
    5.26 +
    5.27 +		String host = args[0];
    5.28 +		Integer port = new Integer(args[1]);
    5.29 +		String db = args[2];
    5.30 +		String user = args[3];
    5.31 +		String passwd = args[4];		
    5.32 +		String queryString = args[5];
    5.33 +		String outFile = args[6];
    5.34 +		
    5.35 +		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    5.36 +		strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
    5.37 +
    5.38 +		strabon.close();
    5.39 +	}
    5.40 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Fri Feb 03 21:21:27 2012 +0200
     6.3 @@ -0,0 +1,46 @@
     6.4 +package eu.earthobservatory.runtime.postgis;
     6.5 +
     6.6 +import java.io.File;
     6.7 +
     6.8 +
     6.9 +public class StoreOp {
    6.10 +
    6.11 +	/**
    6.12 +	 * @param args
    6.13 +	 * @throws Exception 
    6.14 +	 */
    6.15 +	public static void main(String[] args) throws Exception {
    6.16 +
    6.17 +		if (args.length < 6) {
    6.18 +			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> ");
    6.19 +			System.err.println("       where <HOST>       is the postgis database host to connect to");
    6.20 +			System.err.println("             <PORT>       is the port to connect to on the database host");		
    6.21 +			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    6.22 +			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    6.23 +			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    6.24 +			System.err.println("             <FILE>       is the file to be stored");
    6.25 +			System.err.println("             [<FORMAT>]   is the format of the file (NTRIPLES)");
    6.26 +			System.exit(0);
    6.27 +		}
    6.28 +
    6.29 +		String host = args[0];
    6.30 +		Integer port = new Integer(args[1]);
    6.31 +		String db = args[2];
    6.32 +		String user = args[3];
    6.33 +		String passwd = args[4];		
    6.34 +		String src = args[5];
    6.35 +		String format = "NTRIPLES";
    6.36 +		if ( args.length == 7 ) {
    6.37 +			format = args[6];
    6.38 +		}
    6.39 +
    6.40 +		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    6.41 +		
    6.42 +		File file = new File (src);
    6.43 +		strabon.storeInRepo(file, format);
    6.44 +//		strabon.storeInRepo(file, null, null, fileRDFFormat);
    6.45 +
    6.46 +		strabon.close();
    6.47 +	}
    6.48 +
    6.49 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/UpdateOp.java	Fri Feb 03 21:21:27 2012 +0200
     7.3 @@ -0,0 +1,36 @@
     7.4 +package eu.earthobservatory.runtime.postgis;
     7.5 +
     7.6 +
     7.7 +public class UpdateOp {
     7.8 +
     7.9 +	/**
    7.10 +	 * @param args
    7.11 +	 * @throws Exception 
    7.12 +	 */
    7.13 +	public static void main(String[] args) throws Exception {
    7.14 +
    7.15 +		if (args.length < 6) {
    7.16 +			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <UPDATE> ");
    7.17 +			System.err.println("       where <HOST>       is the postgis database host to connect to");
    7.18 +			System.err.println("             <PORT>       is the port to connect to on the database host");		
    7.19 +			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    7.20 +			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    7.21 +			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    7.22 +			System.err.println("             <UPDATE>     is the stSPARQL update query to evaluate.");
    7.23 +			System.exit(0);
    7.24 +		}
    7.25 +
    7.26 +		String host = args[0];
    7.27 +		Integer port = new Integer(args[1]);
    7.28 +		String db = args[2];
    7.29 +		String user = args[3];
    7.30 +		String passwd = args[4];		
    7.31 +		String queryString = args[5];
    7.32 +		
    7.33 +		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    7.34 +
    7.35 +		strabon.update(queryString, strabon.getSailRepoConnection());
    7.36 +
    7.37 +		strabon.close();
    7.38 +	}
    7.39 +}