-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathswish-ask.sh
executable file
·100 lines (89 loc) · 2.07 KB
/
swish-ask.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
#
# Ask information from a Pengines/SWISH server from the shell.
#
# This program allows you to download query results from a SWISH server
# as CSV data.
#
# This code is un the public domain.
server=${SWISH_SERVER-http://localhost:3050}
srctext=
curlarg=
format=${SWISH_FORMAT-csv}
program=$(basename $0)
application=swish
usage()
{
cat << _EOM_
Usage: $program "[--server=URL] [--format=rdf|prolog]" file.pl ... projection query
Where
- server is by default "$server". Environment: SWISH_SERVER
- format is by default "$format". Environment: SWISH_FORMAT
- file.pl ... are files saved in SWISH. Zero or more files are allowed
- projection is a comma-separated list of Prolog variables that define
the CSV columns.
- query is a Prolog goal using the variables from projection.
For example
$program X 'X is 1<<100'
X
1267650600228229401496703205376
$program factbook.pl Code,Country 'country(Country,Code)'
Code,Country
af,http://www4.wiwiss.fu-berlin.de/factbook/resource/Afghanistan
ax,http://www4.wiwiss.fu-berlin.de/factbook/resource/Akrotiri
...
_EOM_
}
done=false
while [ $done = false ]; do
case "$1" in
--server=*)
server=$(echo $1 | sed 's/.*=//')
shift
;;
--format=*)
format=$(echo $1 | sed 's/.*=//')
case "$format" in
rdf|prolog|json)
;;
*)
usage
exit 1
;;
esac
shift
;;
--application=*)
application=$(echo $1 | sed 's/.*=//')
shift
;;
https://*.pl|http://*.pl)
curlarg+=" -d src_url=$1"
shift
;;
*.pl)
script=$(echo $1 | sed 's/.*=//')
srctext+=":- include('$script'). "
shift
;;
*)
done=true
;;
esac
done
vars="$1"
query="$2"
if [ -z "$vars" -o -z "$query" ]; then
usage
exit 1
fi
curl -s \
-d ask="$query" \
-d template="$format($vars)" \
-d application="$application" \
-d src_text="$srctext" \
-d format="$format" \
-d chunk=10 \
-d solutions=all \
$curlarg \
$server/pengine/create