Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
🎨 simplify awk program
Browse files Browse the repository at this point in the history
  • Loading branch information
znculee committed Mar 27, 2020
1 parent ec524ce commit b09eb28
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
15 changes: 3 additions & 12 deletions scripts/measure_scores.e2e.replfail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ fi
SCORER=e2e-metrics/measure_scores.py
org=data/E2E_compositional/testset_w_refs.csv
tmp=scripts/tmp
baserepl=$tmp/baserepl
hyprepl=$tmp/hyprepl
hyp=$tmp/hyp
ref=$tmp/ref
src=$tmp/src
Expand All @@ -36,18 +34,11 @@ rmtreeinfo () {
}

repl=$(grep H- $gen | awk -F '\t' '$2=="-inf" {print $1}' | cut -d '-' -f 2 | awk '{print $1+1}')

awk 'NR==FNR{l[$0];next;} (FNR in l)' <(echo "$repl") \
<(grep H- $base | sort -n -k 2 -t -) > $baserepl

awk 'NR==FNR{l[$0];next;} !(FNR in l)' <(echo "$repl") \
<(grep H- $gen | sort -n -k 2 -t -) > $hyprepl

cat $baserepl >> $hyprepl
cat $hyprepl | sort -n -k 2 -t - | awk -F '\t' '{print $3}' | rmtreeinfo > $hyp
awk -F '\t' 'NR==FNR {l[$0];next;} !(FNR in l) {print $3} (FNR in l) {print $6}' \
<(echo "$repl") <(paste <(grep H- $gen | sort -n -k 2 -t -) <(grep H- $base | sort -n -k 2 -t -)) | \
rmtreeinfo > $hyp

cat $ref_tree | rmtreeinfo > $ref

tail -n +2 $org | cut -d '"' -f 2 > $src

python scripts/_eval_e2e_helper.py
Expand Down
14 changes: 3 additions & 11 deletions scripts/measure_scores.replfail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ fi

SCORER=e2e-metrics/measure_scores.py
tmp=scripts/tmp
baserepl=$tmp/baserepl
hyprepl=$tmp/hyprepl
hyp=$tmp/hyp
ref=$tmp/ref

Expand All @@ -34,15 +32,9 @@ rmtreeinfo () {
}

repl=$(grep H- $gen | awk -F '\t' '$2=="-inf" {print $1}' | cut -d '-' -f 2 | awk '{print $1+1}')

awk 'NR==FNR{l[$0];next;} (FNR in l)' <(echo "$repl") \
<(grep H- $base | sort -n -k 2 -t -) > $baserepl

awk 'NR==FNR{l[$0];next;} !(FNR in l)' <(echo "$repl") \
<(grep H- $gen | sort -n -k 2 -t -) > $hyprepl

cat $baserepl >> $hyprepl
cat $hyprepl | sort -n -k 2 -t - | awk -F '\t' '{print $3}' | rmtreeinfo > $hyp
awk -F '\t' 'NR==FNR {l[$0];next;} !(FNR in l) {print $3} (FNR in l) {print $6}' \
<(echo "$repl") <(paste <(grep H- $gen | sort -n -k 2 -t -) <(grep H- $base | sort -n -k 2 -t -)) | \
rmtreeinfo > $hyp

cat $ref_tree | rmtreeinfo > $ref

Expand Down
17 changes: 4 additions & 13 deletions scripts/tree_acc.replfail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ tmp=scripts/tmp
tsv=$tmp/tsv
id=$tmp/id
src=$tmp/src
baserepl=$tmp/baserepl
hyprepl=$tmp/hyprepl
hyp=$tmp/hyp

mkdir -p $tmp
Expand All @@ -24,20 +22,13 @@ tree_acc () {
python compute_tree_acc.py -tsv $1
}

repl=$(grep H- $gen | awk -F '\t' '$2=="-inf" {print $1}' | cut -d '-' -f 2 | awk '{print $1+1}')

grep S- $gen | sort -n -k 2 -t - | awk -F '\t' '{print $1}' | sed 's/^S-//' > $id

grep S- $gen | sort -n -k 2 -t - | awk -F '\t' '{print $2}' > $src

awk 'NR==FNR{l[$0];next;} (FNR in l)' <(echo "$repl") \
<(grep H- $base | sort -n -k 2 -t -) > $baserepl

awk 'NR==FNR{l[$0];next;} !(FNR in l)' <(echo "$repl") \
<(grep H- $gen | sort -n -k 2 -t -) > $hyprepl

cat $baserepl >> $hyprepl
cat $hyprepl | sort -n -k 2 -t - | awk -F '\t' '{print $3}' > $hyp
repl=$(grep H- $gen | awk -F '\t' '$2=="-inf" {print $1}' | cut -d '-' -f 2 | awk '{print $1+1}')
awk -F '\t' 'NR==FNR {l[$0];next;} !(FNR in l) {print $3} (FNR in l) {print $6}' \
<(echo "$repl") <(paste <(grep H- $gen | sort -n -k 2 -t -) <(grep H- $base | sort -n -k 2 -t -)) \
> $hyp

paste $id $src $hyp > $tsv

Expand Down

0 comments on commit b09eb28

Please sign in to comment.