Akron | eb590da | 2022-03-02 18:31:34 +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 $empirist_path = '/euralex/empirist_'; |
| 10 | mkdir $empirist_path . 'cmc'; |
| 11 | mkdir $empirist_path . 'web'; |
| 12 | |
| 13 | my $gold_path = '/euralex/corpus/empirist_gold_'; |
| 14 | |
| 15 | my %tools = ( |
| 16 | waste => sub { |
| 17 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 18 | system 'cat ' . $raw . ' | waste -N -v0 --rcfile=./Waste/waste.rc > ' . $empirist_path . $_[1] . '/waste/' . $_[0], |
| 19 | }, |
| 20 | datok => sub { |
| 21 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 22 | system 'cat ' . $raw . ' | ./Datok/datok tokenize -t ./Datok/testdata/tokenizer.matok - > ' . $empirist_path . $_[1] . '/datok/' . $_[0]; |
| 23 | }, |
| 24 | korap_tokenizer => sub { |
| 25 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 26 | system 'cat ' . $raw . ' | java -jar ./KorAP-Tokenizer/KorAP-Tokenizer.jar -l de > ' . $empirist_path . $_[1] . '/korap_tokenizer/' . $_[0]; |
| 27 | }, |
| 28 | opennlp_simple => sub { |
| 29 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 30 | system 'cat ' . $raw . ' | ./opennlp/bin/opennlp SimpleTokenizer 2> /dev/null | sed "s/\s/\n/g" > ' . $empirist_path . $_[1] . '/opennlp_simple/' . $_[0]; |
| 31 | }, |
| 32 | opennlp_tokenizer => sub { |
| 33 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 34 | 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" > ' . $empirist_path . $_[1] . '/opennlp_tokenizer/' . $_[0]; |
| 35 | }, |
| 36 | tree_tagger => sub { |
| 37 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 38 | system 'cat ' . $raw . ' | perl ./treetagger/cmd/utf8-tokenize.perl -a ./treetagger/lib/german-abbreviations 2> /dev/null > ' . $empirist_path . $_[1] . '/tree_tagger/' . $_[0]; |
| 39 | }, |
| 40 | jtok => sub { |
| 41 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 42 | chdir '/euralex/JTok/bin'; |
| 43 | system 'sh tokenize ' . $raw . ' de | grep "Token: " | perl -CS -pe "s/\s +Token: \"//; s/^(\"?[^\"]*?)\".+?$/\1/g" > ' . $empirist_path . $_[1] . '/jtok/' . $_[0]; |
| 44 | chdir '/euralex'; |
| 45 | }, |
| 46 | syntok => sub { |
| 47 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 48 | system 'python3 -m syntok.tokenizer ' . $raw . ' | sed "s/\s/\n/g" > ' . $empirist_path . $_[1] . '/syntok/' . $_[0]; |
| 49 | }, |
| 50 | somajo => sub { |
| 51 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 52 | system 'somajo-tokenizer ' . $raw . ' 2> /dev/null > ' . $empirist_path . $_[1] . '/somajo/' . $_[0]; |
Akron | b040897 | 2022-03-07 11:36:17 +0100 | [diff] [blame] | 53 | }, |
Akron | 8cb1279 | 2022-03-09 11:34:01 +0100 | [diff] [blame] | 54 | elephant => sub { |
| 55 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 56 | system './elephant-wrapper/bin/tokenize.sh -i ' . $raw . ' UD_German | sed "s/\s/\n/g" > ' . $empirist_path . $_[1] . '/elephant/' . $_[0]; |
| 57 | }, |
| 58 | spacy => sub { |
| 59 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 60 | system 'python3 ./spacy/spacy_tok.py ' . $raw . ' > ' . $empirist_path . $_[1] . '/spacy/' . $_[0]; |
| 61 | }, |
Akron | 325193e | 2022-03-20 11:38:04 +0100 | [diff] [blame^] | 62 | blingfire => sub { |
| 63 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 64 | system 'python3 ./blingfire/blingfire_tok.py ' . $raw . ' | sed "s/\s/\n/g" > ' . $empirist_path . $_[1] . '/blingfire/' . $_[0]; |
| 65 | }, |
Akron | 54fd314 | 2022-03-17 17:45:12 +0100 | [diff] [blame] | 66 | cutter => sub { |
| 67 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 68 | system 'python3 ./cutter/cutter.py nosent ' . $raw . ' > ' . $empirist_path . $_[1] . '/cutter/' . $_[0]; |
| 69 | }, |
Akron | b040897 | 2022-03-07 11:36:17 +0100 | [diff] [blame] | 70 | stanford => sub { |
| 71 | my $raw = $gold_path . $_[1] . '/raw/' . $_[0]; |
| 72 | system 'CLASSPATH=/euralex/stanford-corenlp-4.4.0/* java edu.stanford.nlp.pipeline.StanfordCoreNLP ' . |
| 73 | '-props german -annotators tokenize,ssplit,mwt -tokenize.language=german -file ' . $raw . ' 2> /dev/null'; |
| 74 | system 'perl /euralex/benchmarks/cleanup/stanford.pl ' . $_[0] . '.out > ' . $empirist_path . $_[1] . '/stanford/' . $_[0]; |
| 75 | system 'rm ' . $_[0] . '.out'; |
Akron | eb590da | 2022-03-02 18:31:34 +0100 | [diff] [blame] | 76 | } |
| 77 | ); |
| 78 | |
Akron | 325193e | 2022-03-20 11:38:04 +0100 | [diff] [blame^] | 79 | delete $tools{waste}; |
| 80 | delete $tools{datok}; |
| 81 | delete $tools{korap_tokenizer}; |
| 82 | delete $tools{opennlp_simple}; |
| 83 | delete $tools{opennlp_tokenizer}; |
| 84 | delete $tools{tree_tagger}; |
| 85 | delete $tools{jtok}; |
| 86 | delete $tools{syntok}; |
| 87 | delete $tools{somajo}; |
| 88 | delete $tools{stanford}; |
| 89 | delete $tools{spacy}; |
| 90 | delete $tools{elephant}; |
| 91 | delete $tools{cutter}; |
| 92 | delete $tools{blingfire}; |
Akron | eb590da | 2022-03-02 18:31:34 +0100 | [diff] [blame] | 93 | |
| 94 | # Create project folders |
| 95 | foreach (keys %tools) { |
Akron | 8cb1279 | 2022-03-09 11:34:01 +0100 | [diff] [blame] | 96 | system 'rm -r ' . $empirist_path . 'cmc/' . $_; |
Akron | eb590da | 2022-03-02 18:31:34 +0100 | [diff] [blame] | 97 | mkdir $empirist_path . 'cmc/' . $_; |
Akron | 8cb1279 | 2022-03-09 11:34:01 +0100 | [diff] [blame] | 98 | system 'rm -r ' . $empirist_path . 'web/' . $_; |
Akron | eb590da | 2022-03-02 18:31:34 +0100 | [diff] [blame] | 99 | mkdir $empirist_path . 'web/' . $_; |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | # Run the CMC test suite |
| 104 | my @files = ( |
| 105 | 'cmc_test_blog_comment.txt', |
| 106 | 'cmc_test_professional_chat.txt', |
| 107 | 'cmc_test_social_chat.txt', |
| 108 | 'cmc_test_twitter.txt', |
| 109 | 'cmc_test_whatsapp.txt', |
| 110 | 'cmc_test_wiki_discussion.txt', |
| 111 | ); |
| 112 | |
| 113 | |
| 114 | # Run tokenization |
| 115 | foreach my $file (@files) { |
| 116 | foreach (keys %tools) { |
| 117 | $tools{$_}->($file, 'cmc'); |
| 118 | } |
| 119 | }; |
| 120 | |
| 121 | foreach my $tool (keys %tools) { |
| 122 | print "\n##########\n"; |
| 123 | print "##### $tool - Empirist-CMC\n"; |
| 124 | print "##\n"; |
| 125 | system $cmd . ' -x ' . $gold_path . 'cmc/tokenized/ ' . $empirist_path . 'cmc/' . $tool . '/ 2> /dev/null'; |
| 126 | }; |
| 127 | |
| 128 | |
| 129 | # Run the Web test suite |
| 130 | @files = ( |
| 131 | 'web_test_001.txt', |
| 132 | 'web_test_002.txt', |
| 133 | 'web_test_003.txt', |
| 134 | 'web_test_004.txt', |
| 135 | 'web_test_005.txt', |
| 136 | 'web_test_006.txt', |
| 137 | 'web_test_007.txt', |
| 138 | 'web_test_008.txt', |
| 139 | 'web_test_009.txt', |
| 140 | 'web_test_010.txt', |
| 141 | 'web_test_011.txt', |
| 142 | 'web_test_012.txt' |
| 143 | ); |
| 144 | |
| 145 | # Run tokenization |
| 146 | foreach my $file (@files) { |
| 147 | foreach (keys %tools) { |
| 148 | $tools{$_}->($file, 'web'); |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | foreach my $tool (keys %tools) { |
| 153 | print "\n##########\n"; |
| 154 | print "##### $tool - Empirist-Web\n"; |
| 155 | print "##\n"; |
| 156 | system $cmd . ' -x ' . $gold_path . 'web/tokenized/ ' . $empirist_path . 'web/' . $tool . '/ 2> /dev/null'; |
| 157 | }; |