#! /bin/bash -eu
# Last edited on 2026-07-05 03:40:59 by stolfi

# The raw file should be an ".ivt" transcription of the starred parags
# section, "parags" subset only, in J. Stolfi's variant of the IVTFF
# format.

raw_file="$1"; shift
ecorr=$1; shift
simil=$1; shift

export LC_ALL=en_US.utf8
export LANG=en_US.utf8
export LC_CTYPE=en_US.utf8

ecorr_maps=( n050_noop.sed n050_correct_scribal_errors.sed )
simil_maps=( cat n050_collapse_similar_voynichese_words.py )

opref="res/modif_starps-e${ecorr}-s${simil}"
txfile="${opref}.txt"

echo "creating ${txfile} with ecorr = ${ecorr} simil = ${simil} ..." 1>&2
utype="wc"
cat ${raw_file} \
  | convert_starps_raw_to_lin_ivt.py ${utype} \
  | convert_starps_lin_to_par_ivt.py ${utype} \
  | gawk \
      ' /^</ { 
          loc = $1; $1 = ""; tx = $0;
          gsub(/<[%$]>/, "", tx)
          gsub(/[«=»]/, "", tx)
          gsub(/[.,-]/, " ", tx)
          gsub(/^[ ]+/, "", tx)
          gsub(/[ ]+$/, "", tx)
          gsub(/[ ][ ]+/, " ", tx)
          printf "%-11s %s\n", loc, tx
        }
      ' \
  | n050_split_joined_words.sed \
  | ${ecorr_maps[$ecorr]} \
  | ${simil_maps[$simil]} \
  > ${txfile}
echo "processed $( cat ${txfile} | wc -l ) SPS lines."  1>&2

#   | sed \
#       -e 's:<[0-9]+>::g' \
#       -e 's:<[%$]>::g' \
# 
