Aligning a corpus with fast align

From Apertium
Jump to navigation Jump to search


What you need[edit]

  • A sentence-aligned parallel corpus
  • Fast_align (get it here)
  • Two apertium language packages
  • fast_align merge script (get it here)

Process[edit]

Warning: On Mac, you will need to use GNU alternatives of sed, awk etc.

First analyse the corpus with the language packages.

$ cat /tmp/udhr.kaz | apertium-destxt | lt-proc -w ~/source/apertium/languages/apertium-kaz/kaz.automorf.bin | cg-proc -n -1 ~/source/apertium/languages/apertium-kaz/kaz.rlx.bin | apertium-retxt > /tmp/udhr.kaz.tagged
$ cat /tmp/udhr.kir | apertium-destxt | lt-proc -w ~/source/apertium/languages/apertium-kir/kir.automorf.bin | cg-proc -n -1 ~/source/apertium/languages/apertium-kir/kir.rlx.bin | apertium-retxt > /tmp/udhr.kir.tagged

Then remove superfluous tags (for example for lexical alignment, case is not really interesting).

cat /tmp/udhr.kaz.tagged | sed 's/\(<\(n\|adj\|adv\)>\)\(<[^>]\+>\)\+/\1/g' | sed 's/\(<v><tv>\|<v><iv>\)\(<[^>]\+>\)\+/\1/g' | sed 's/\$/$ /g' | sed 's/  */ /g' | apertium-pretransfer  > /tmp/udhr.kaz.trimmed
cat /tmp/udhr.kir.tagged | sed 's/\(<\(n\|adj\|adv\)>\)\(<[^>]\+>\)\+/\1/g' | sed 's/\(<v><tv>\|<v><iv>\)\(<[^>]\+>\)\+/\1/g' | sed 's/\$/$ /g' | sed 's/  */ /g' | apertium-pretransfer  > /tmp/udhr.kir.trimmed

Create the input file for fast_align:

$ paste /tmp/udhr.kaz.trimmed /tmp/udhr.kir.trimmed  | sed 's/ *\t */ ||| /g' > /tmp/udhr.kaz-kir.input

Run fast_align:


$ ./fast_align -d -v -o -i /tmp/udhr.kaz-kir.input > /tmp/udhr.kaz-kir.align

$ ./fast_align -d -v -o -r -i /tmp/udhr.kaz-kir.input > /tmp/udhr.kir-kaz.align


Create the wordlist:


$ python3 ~/scripts/ordlist-fra-fastalign.py /tmp/udhr.kaz-kir.input /tmp/udhr.kaz-kir.align /tmp/udhr.kir-kaz.align 


To symmetrise alignments:

$ ./atools -i /tmp/udhr.kaz-kir.align -j /tmp/udhr.kir-kaz.align -c grow-diag-final-and