summaryrefslogtreecommitdiffhomepage
path: root/pipeline/read.sh
blob: b3129a59c94432c0d0324dc33e87f1371f119cd8 (plain)
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
#!/bin/sh
# Every reader and both libraries, over every document, into $OUT/read/.
#
# What each produces:
#
#   read/ssp-{d,g}/<doc>.txt      the .ssp readers' summary
#   read/db-{d,g}/<doc>.txt       the .ocda.db readers' summary
#   read/dump-{d,g}/<doc>.ssp     the library's dump, loaded from the .ssp
#   read/dump-{d,g}/<doc>.db      the same, loaded from the .ocda.db
#
# The dumps are the interesting ones. All four of them should be identical:
# the two serialisations say the same thing, and the two languages read it the
# same way. `diff` says so, and the summary at the end counts it.
set -e
. "$(dirname "$0")/config.sh"
: "${ARTEFACTS:?set ARTEFACTS to a directory of .ssp and .ocda.db files}"
mkdir -p "$OUT/read"
for d in ssp-d ssp-g db-d db-g dump-d dump-g; do mkdir -p "$OUT/read/$d"; done

list=$(find "$ARTEFACTS" -name '*.ssp' | sort)
[ -n "$LIMIT" ] && list=$(echo "$list" | head -n "$LIMIT")

n=0; same=0
for ssp in $list; do
  stem=$(basename "$ssp" .ssp); lang=${stem##*.}; uid=${stem%.*}
  db=$(find "$ARTEFACTS" -name "$uid.ocda.db" | head -1)
  n=$((n+1))
  sh "$(dirname "$0")/one.sh" ssp-d "$ssp" > "$OUT/read/ssp-d/$stem.txt"
  sh "$(dirname "$0")/one.sh" ssp-g "$ssp" > "$OUT/read/ssp-g/$stem.txt"
  sh "$(dirname "$0")/one.sh" dump-d "$ssp" > "$OUT/read/dump-d/$stem.ssp"
  sh "$(dirname "$0")/one.sh" dump-g "$ssp" > "$OUT/read/dump-g/$stem.ssp"
  [ -n "$db" ] || continue
  sh "$(dirname "$0")/one.sh" db-d "$db" > "$OUT/read/db-d/$stem.txt"
  sh "$(dirname "$0")/one.sh" db-g "$db" > "$OUT/read/db-g/$stem.txt"
  sh "$(dirname "$0")/one.sh" dump-d "$db" "$lang" > "$OUT/read/dump-d/$stem.db"
  sh "$(dirname "$0")/one.sh" dump-g "$db" "$lang" > "$OUT/read/dump-g/$stem.db"
  # the four-way agreement, which is the library's whole claim
  if cmp -s "$OUT/read/dump-d/$stem.ssp" "$OUT/read/dump-d/$stem.db" \
  && cmp -s "$OUT/read/dump-g/$stem.ssp" "$OUT/read/dump-g/$stem.db" \
  && cmp -s "$OUT/read/dump-d/$stem.ssp" "$OUT/read/dump-g/$stem.ssp"
  then same=$((same+1))
  else echo "DUMPS DIFFER $stem"
  fi
done
echo
echo "documents read:                            $n"
echo "all four dumps identical                   $same"