#!/bin/bash

s=$1
t=$2

# 'ds' is not a valid ISO 639 language code
if [ $s == ds ]
then
    sl=da
else
    sl=$s
fi

mkdir -p split.$s
mkdir -p split.$t
split -a 5 -d -l 10000 OpenSubtitles2016.$s-$t.$s split.$s/
split -a 5 -d -l 10000 OpenSubtitles2016.$s-$t.$t split.$t/

treex \
    Read::AlignedSentences $sl=!split.$s'/*' $t=!split.$t'/*' \
    W2A::Tokenize \
    W2A::UDPipe language=$sl tokenize=0 parse=0 model=./$s.tagger.udpipe \
    W2A::UDPipe language=$t tokenize=0 parse=0 model=./$t.tagger.udpipe \
    Util::Eval anode='$anode->set_tag($anode->conll_cpos)' \
    Align::A::MonolingualGreedy language=$sl to_language=$t to_selector= \
    Write::AttributeSentencesAligned layer=a attributes='form,tag,conll/feat,aligned->form,aligned->tag,aligned->conll/feat' language=$sl alignment_language=$t alignment_type=monolingual alignment_is_backwards=0 to=-

rm -r split.$s split.$t

