Strabon

view scripts/strabon @ 235:deddf369e10f

progress on strabon script
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Jun 03 15:16:14 2012 +0300 (2012-06-03)
parents dbbfb1a23017
children 7f8b766725fc
line source
1 #!/bin/bash
2 #
3 # Script for running the main classes of Strabon. The main classes of Strabon comprises
4 # QueryOp, , UpdateOp, and StoreOp.
5 #
6 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
7 #
9 # command name
10 CMD="$(basename ${0})"
12 # absolute directory name of this command
13 LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15 RUNTIME="${LOC}/../runtime"
17 function help() {
18 echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
19 echo
20 echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, etc."
21 echo
22 echo " COMMAND : one of \`query', \`update', \`store', or \`help'"
23 echo " ARGS : arguments according to selected command"
24 echo
25 echo "OPTIONS can be any of the following"
26 echo " -d : don't run, just print what shall be executed"
27 echo " -c FILE : configuration file to use for the connection. It defaults to \`${HOME}/.strabon'."
28 }
30 function help_query() {
31 echo "Usage: ${CMD} query SPARQL_QUERY"
32 echo
33 echo "Execute a SPARQL query on Strabon."
34 echo
35 echo " SPARQL_QUERY : the SPARQL query to execute or an alias name such as the following:"
36 echo " size: returns the number of triples"
37 }
39 function help_update() {
40 echo "Usage: ${CMD} update SPARQL_UPDATE"
41 echo
42 echo "Execute a SPARQL Update query on Strabon."
43 echo
44 echo " SPARQL_UPDATE : the SPARQL update query to execute or an alias name such as the"
45 echo " the following:"
46 echo " clear: deletes all triples"
47 }
49 function help_store() {
50 echo "Usage: ${CMD} store FILE..."
51 echo
52 echo "Store RDF documents in Strabon."
53 echo
54 echo " FILE : the file containing the RDF document to store. It can be a filename or a URL,"
55 echo " (i.e., file:///tmp/file.nt, http://www.example.org/file.nt,"
56 echo " ftp://www.example.org/file.nt, etc.)."
57 }
59 # runtime package
60 PKG="eu.earthobservatory.runtime"
62 # the underlying database to use (one of postgis or monetdb)
63 DATABASE="postgis"
65 # the main class to run
66 CLASS="QueryOp"
68 # the hostname at which the database runs
69 HOST="localhost"
71 # the port at which the database listens
72 PORT=5432
74 # the database name to connect to
75 DB="endpoint"
76 DB="strabon"
78 # the username for the database connection
79 DBUSER="charnik"
81 # the password for the database connection
82 DBPASS="charnik"
84 # the query to run
85 QUERY=
87 # predefined queries
88 QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
89 QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
91 # debug option for log4j configuration:
92 #-Dlog4j.debug
93 #-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
95 # just print what shall be executed
96 DEBUG=0
98 # configuration file for the Strabon connection
99 STRABON_CONF="${HOME}/.strabon"
100 case "${1}" in
101 -d)
102 shift
103 DEBUG=1
104 ;;
105 -c)
106 shift
107 if ! test $# -gt 1; then
108 help
109 exit 1
110 fi
111 STRABON_CONF="${1}"
112 if ! test -e "${STRABON_CONF}"; then
113 echo "${CMD}: configuration file \"${1}\" does not exist."
114 exit 1
115 fi
116 shift
117 ;;
118 esac
120 case "${1}" in
121 help)
122 shift
123 if test $# -eq 1; then
124 case "${1}" in
125 query)
126 help_query
127 ;;
128 update)
129 help_update
130 ;;
131 store)
132 help_store
133 ;;
134 *)
135 help
136 ;;
137 esac
138 exit 1
139 fi
140 help
141 exit 0
142 ;;
143 query)
144 CLASS="QueryOp"
145 shift
146 if ! test $# -eq 1; then
147 help_query
148 exit 1
149 fi
150 QUERY="${1}"
152 # check for predefined queries
153 case "${QUERY}" in
154 size)
155 QUERY="${QUERY_SIZE}"
156 ;;
157 esac
158 ;;
159 update)
160 CLASS="UpdateOp"
161 shift
162 if ! test $# -eq 1; then
163 help_update
164 exit 1
165 fi
166 QUERY="${1}"
168 # check for predefined queries
169 case "${QUERY}" in
170 clear)
171 QUERY="${QUERY_DELETEALL}"
172 ;;
173 esac
174 ;;
175 store)
176 CLASS="StoreOp"
177 shift
178 if ! test $# -ge 1; then
179 help_store
180 exit 1
181 fi
182 # do not make an assignment of the files to QUERY
183 # handle the case afterwards
184 # QUERY="${@}"
185 ;;
186 *)
187 help
188 echo
189 echo "${CMD}: Unknown command \"${1}\"."
190 exit 1
191 ;;
192 esac
194 if test "${CLASS}" = "StoreOp"; then
195 STRABON_EXEC=
196 for file in "${@}"; do
197 STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\");
198 "
199 done
200 else
201 STRABON_EXEC="(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${QUERY}\")"
202 fi
204 # execute or debug
205 if test ${DEBUG} -eq 1; then
206 echo "${CMD}: Debug is ON"
207 echo "${CMD}: Printing command for execution"
208 echo "${STRABON_EXEC}"
209 else
210 eval ${STRABON_EXEC}
211 fi