Akron | 54c5221 | 2022-03-07 18:56:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | # Comparison path |
| 6 | my $cmd = '/euralex/corpus/empirist_gold_cmc/tools/compare_tokenization.perl'; |
| 7 | |
| 8 | # Output path |
| 9 | my $ud_path = '/euralex/ud_tokens'; |
| 10 | mkdir $ud_path; |
| 11 | |
| 12 | my $base = 'de_gsd-ud-train.conllu'; |
| 13 | |
| 14 | # Split files |
| 15 | chdir '/euralex/corpus/'; |
| 16 | system 'perl /euralex/benchmarks/cleanup/split_conllu.pl /euralex/corpus/' . $base; |
| 17 | chdir '/euralex'; |
| 18 | |
| 19 | my $gold = '/euralex/corpus/' . $base . '.split'; |
| 20 | my $raw = '/euralex/corpus/' . $base . '.raw'; |
| 21 | |
| 22 | my %tools = ( |
| 23 | waste => sub { |
| 24 | system 'cat ' . $raw . ' | waste -N -v0 --rcfile=./Waste/waste.rc > ' . $ud_path . '/waste/' . $base; |
| 25 | }, |
| 26 | datok => sub { |
| 27 | system 'cat ' . $raw . ' | ./Datok/datok tokenize -t ./Datok/testdata/tokenizer.matok - > ' . $ud_path . '/datok/' . $base; |
| 28 | }, |
| 29 | korap_tokenizer => sub { |
| 30 | system 'cat ' . $raw . ' | java -jar ./KorAP-Tokenizer/KorAP-Tokenizer.jar -l de > ' . $ud_path . '/korap_tokenizer/' . $base; |
| 31 | }, |
| 32 | opennlp_simple => sub { |
| 33 | system 'cat ' . $raw . ' | ./opennlp/bin/opennlp SimpleTokenizer 2> /dev/null | sed "s/\s/\n/g" > ' . $ud_path . '/opennlp_simple/' . $base; |
| 34 | }, |
| 35 | opennlp_tokenizer => sub { |
| 36 | system 'cat ' . $raw . ' | ./opennlp/bin/opennlp TokenizerME ./opennlp/models/opennlp-de-ud-gsd-tokens-1.0-1.9.3.bin 2> /dev/null | sed "s/\s/\n/g" > ' . $ud_path . '/opennlp_tokenizer/' . $base; |
| 37 | }, |
| 38 | tree_tagger => sub { |
| 39 | system 'cat ' . $raw . ' | perl ./treetagger/cmd/utf8-tokenize.perl -a ./treetagger/lib/german-abbreviations 2> /dev/null > ' . $ud_path . '/tree_tagger/' . $base; |
| 40 | }, |
| 41 | jtok => sub { |
| 42 | chdir '/euralex/JTok/bin'; |
| 43 | system 'sh tokenize ' . $raw . ' de | grep "Token: " | perl -CS -pe "s/\s +Token: \"//; s/^(\"?[^\"]*?)\".+?$/\1/g" > ' . $ud_path . '/jtok/' . $base; |
| 44 | chdir '/euralex'; |
| 45 | }, |
| 46 | syntok => sub { |
| 47 | system 'python3 -m syntok.tokenizer ' . $raw . ' | sed "s/\s/\n/g" > ' . $ud_path . '/syntok/' . $base; |
| 48 | }, |
Akron | 8cb1279 | 2022-03-09 11:34:01 +0100 | [diff] [blame] | 49 | elephant => sub { |
| 50 | system './elephant-wrapper/bin/tokenize.sh -i ' . $raw . ' UD_German | sed "s/\s/\n/g" > ' . $ud_path . '/elephant/' . $base; |
| 51 | }, |
| 52 | spacy => sub { |
| 53 | system 'python3 ./spacy/spacy_tok.py ' . $raw . ' > ' . $ud_path . '/spacy/' . $base; |
| 54 | }, |
Akron | 54fd314 | 2022-03-17 17:45:12 +0100 | [diff] [blame] | 55 | cutter => sub { |
| 56 | system 'python3 ./cutter/cutter.py nosent ' . $raw . ' > ' . $ud_path . '/cutter/' . $base; |
| 57 | }, |
Akron | 54c5221 | 2022-03-07 18:56:21 +0100 | [diff] [blame] | 58 | somajo => sub { |
| 59 | system 'somajo-tokenizer ' . $raw . ' 2> /dev/null > ' . $ud_path . '/somajo/' . $base; |
| 60 | }, |
| 61 | stanford => sub { |
| 62 | system 'CLASSPATH=/euralex/stanford-corenlp-4.4.0/* java edu.stanford.nlp.pipeline.StanfordCoreNLP ' . |
| 63 | '-props german -annotators tokenize,ssplit,mwt -tokenize.language=german -file ' . $raw . ' 2> /dev/null'; |
| 64 | system 'perl /euralex/benchmarks/cleanup/stanford.pl ' . $base . '.raw.out > ' . $ud_path . '/stanford/' . $base; |
| 65 | system 'rm ' . $base . '.raw.out'; |
| 66 | } |
| 67 | ); |
| 68 | |
Akron | b4570d2 | 2022-03-09 11:34:59 +0100 | [diff] [blame] | 69 | # delete $tools{waste}; |
| 70 | # delete $tools{datok}; |
| 71 | # delete $tools{korap_tokenizer}; |
| 72 | # delete $tools{opennlp_simple}; |
| 73 | # delete $tools{opennlp_tokenizer}; |
| 74 | # delete $tools{tree_tagger}; |
| 75 | # delete $tools{jtok}; |
| 76 | # delete $tools{syntok}; |
| 77 | # delete $tools{somajo}; |
| 78 | # delete $tools{stanford}; |
Akron | 8cb1279 | 2022-03-09 11:34:01 +0100 | [diff] [blame] | 79 | # delete $tools{elephant}; |
| 80 | # delete $tools{spacy}; |
Akron | 54fd314 | 2022-03-17 17:45:12 +0100 | [diff] [blame] | 81 | # delete $tools{cutter}; |
Akron | 54c5221 | 2022-03-07 18:56:21 +0100 | [diff] [blame] | 82 | |
| 83 | # Create project folders |
| 84 | foreach (keys %tools) { |
| 85 | mkdir $ud_path . '/' . $_; |
| 86 | }; |
| 87 | |
| 88 | # Run tokenization |
| 89 | foreach (keys %tools) { |
| 90 | $tools{$_}->(); |
| 91 | }; |
| 92 | |
| 93 | foreach my $tool (keys %tools) { |
| 94 | print "\n##########\n"; |
| 95 | print "##### $tool - UD\n"; |
| 96 | print "##\n"; |
| 97 | system $cmd . ' -x ' . $gold . ' ' . $ud_path . '/' . $tool . '/' . $base . ' 2> /dev/null'; |
| 98 | }; |