-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-any.sh
208 lines (170 loc) · 6.45 KB
/
run-any.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env bash
hashxml() {
sed '/^<sparql/{$!{:m;s/>/END/;te;N;bm;:e;s/^<sparql.*END/<sparql>/g}}' $1 > $2
xsltproc -o _temp tools/hasher.xslt $2
sort _temp > $2
}
compare() {
groundTruth=`wc -l $1 | sed 's/^[ ^t]*//' | cut -d' ' -f1`
commons=`comm -12 $2 $1 | wc -l`
comparison=`echo "scale=2; $commons/$groundTruth" | bc`
echo -n "$comparison;"
}
log() {
if [[ $verbose ]] && [[ $completeness != 1.00 || $soundness != 1.00 ]]; then
echo ""
cat tempRef
cat tempRes
fi
}
usage() {
echo "Usage: $0 [-v] [-f <name of folder to parse || *>] [-j <jena use path>] [-g <sage-jena use path>] [-s <sage js use path>]" 1>&2;
exit 1;
}
FOLDER="*"
while getopts ":f:j:g:s:v" o; do
case "${o}" in
f)
FOLDER=${OPTARG}
;;
j)
jenapath=${OPTARG}
;;
g)
sagejenapath=${OPTARG}
;;
s)
sagejspath=${OPTARG}
;;
v)
verbose=1
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
for MANIFEST in query-expect/w3c/$FOLDER/manifest.ttl; do
WAY="${MANIFEST%/*.ttl}"
DIR="${WAY#*w3c/}"
#echo $DIR
exec 3<> $MANIFEST;
while read -r LINE; do
# looking for query line
if [[ $LINE = *"qt:query "* ]] && ! [[ $LINE = "#"* ]] ; then
# slicing the name and "address" of the query
# linking it to its path
# and outputing it
AQUERY=$LINE
AQUERY="${AQUERY%>*}"
AQUERY="${AQUERY#*<}"
NAME="${AQUERY%.rq}"
AQUERY="$WAY/$AQUERY"
echo -n "$DIR/$NAME;"
# one-lining the query from the file and
# removing all of its comments
QUERY=""
exec 4<> $AQUERY
while read -r MUSTREMOVECOMMENTS; do
COMMMENTSREMOVED="${MUSTREMOVECOMMENTS%# *}"
QUERY="$QUERY $COMMMENTSREMOVED"
done <&4
exec 4>&-
# looking for data line and
# slicing the name of the dataset
read -r LINE;
if [[ $LINE = *"qt:data "* ]] && [[ $LINE = *".ttl"* ]]; then
ADATA=$LINE
ADATA="${ADATA%.ttl>*}"
ADATA="${ADATA#*<}"
# looking for result line and
# slicing the filename
while ! [[ $LINE = *"mf:result "* ]]; do
read -r LINE
done
EXPECT=$LINE
EXPECT="${EXPECT%>*}"
EXPECT="${EXPECT#*<}"
if [[ $EXPECT = *".srx"* ]]; then
reference=$WAY/$EXPECT
hashxml "$reference" "tempRef"
# for every kind of query engine supplied
# set the destination to store query results
# generate, format and compare
# log accordingly
if [[ $jenapath ]]; then
DEST=results/jena/$DIR
mkdir -p $DEST/
iwantmeback=`pwd`
jenafolder="${jenapath%bin*.sh}"
cd $jenafolder
`$jenapath $iwantmeback/data/w3c/$DIR/$ADATA.hdt "$QUERY" 1> $iwantmeback/$DEST/res.$NAME.hashed`
cd $iwantmeback
results=$DEST/res.$NAME.hashed
# '/^<sparql/{$!{:m;s/>/END/;te;N;bm;:e;s/^<sparql.*END/<sparql>/g}}'
#'/^\[INFO\]/{$!{:m;N;s/\[INFO\].*/END/;tm;s/[END]*/ /g}}'
# '/^\[INFO\]/{$!{:m;N;s/\[INFO\]/a/;tm;s/*/ /g}}'
# 's/\[INFO\].*/ /g'
sed '/^\[INFO\]/{$!{:m;N;s/.*\[INFO\].*/ /;tm;N;s/.*\n//g}}' $results > _temp
sed 's/^ //' _temp > tempRes
sed 's/,//g' tempRes > _temp
sed -e 's/\r//g' _temp > tempRes
sed 's/""//g' tempRes > _temp
cat _temp > tempRes
exec 5<> $results
while read -r ISITBOOLEAN; do
if [ "$ISITBOOLEAN" == "true" ] || [ "$ISITBOOLEAN" == "false" ] ; then
echo "$ISITBOOLEAN" > tempRes
fi
done <&5
exec 5>&-
echo '<?xml version="1.0"?>' >> tempRes
sort tempRes > _temp
cat _temp > tempRes
# soundness
compare tempRes tempRef
soundness=$comparison
# completeness
compare tempRef tempRes
completeness=$comparison
diff tempRef tempRes > damn.txt
log
fi
if [[ $sagejenapath ]]; then
DEST=results/sagejena/$DIR
mkdir -p $DEST/
`$sagejenapath -u "http://localhost:8000/sparql/$DIR$ADATA" -q "$QUERY" 1> $DEST/res.$NAME.xml`
results=$DEST/res.$NAME.xml
hashxml "$results" "tempRes"
# soundness
compare tempRes tempRef
soundness=$comparison
# completeness
compare tempRef tempRes
completeness=$comparison
log
fi
if [[ $sagejspath ]]; then
# ./../SaGe/sage-client/bin/sage-client.js -t xml http://localhost:8000/sparql/functionsdata -f w3c/functions/strlang02.rq
DEST=results/sagejs/$DIR
mkdir -p $DEST/
`node $sagejspath -t xml http://localhost:8000/sparql/$DIR$ADATA -q "$QUERY" 1> $DEST/res.$NAME.xml`
results="$DEST/res.$NAME.xml"
hashxml "$results" "tempRes"
# soundness
compare tempRes tempRef
soundness=$comparison
# completeness
compare tempRef tempRes
completeness=$comparison
log
fi
rm -f tempRef tempRes _temp
fi
fi
echo ""
fi
done <&3;
exec 3>&-
done