Marc Kupietz | bb739b0 | 2020-09-22 16:49:34 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Test::Script; |
Marc Kupietz | 79ba1e5 | 2021-02-12 17:26:54 +0100 | [diff] [blame^] | 5 | use Test::TempDir::Tiny; |
| 6 | use File::Copy; |
Marc Kupietz | bb739b0 | 2020-09-22 16:49:34 +0200 | [diff] [blame] | 7 | |
| 8 | script_runs([ 'script/korapxml2conllu', '-h' ], { exit => 255 }); |
| 9 | script_stderr_like "Description", "Can print help message"; |
| 10 | |
| 11 | for my $morpho_fname (glob("t/data/*\.*\.zip")) { |
| 12 | my $base_fname = $morpho_fname =~ s/(.*)\..*\.zip/$1.zip/r; |
| 13 | die "cannot find $base_fname" if (!-e $base_fname); |
| 14 | |
Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 15 | my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.morpho.conllu/r; |
Marc Kupietz | bb739b0 | 2020-09-22 16:49:34 +0200 | [diff] [blame] | 16 | die "cannot find $conllu_fname" if (!-e $conllu_fname); |
| 17 | |
| 18 | my $expected; |
| 19 | open(my $fh, '<', $conllu_fname) or die "cannot open file $conllu_fname"; { |
| 20 | local $/; |
| 21 | $expected = <$fh>; |
| 22 | } |
| 23 | close($fh); |
Marc Kupietz | 13994d1 | 2021-02-12 17:25:36 +0100 | [diff] [blame] | 24 | script_runs([ 'script/korapxml2conllu', $morpho_fname ], "Runs korapxml2conllu with pos and lemma annotated input"); |
Marc Kupietz | bb739b0 | 2020-09-22 16:49:34 +0200 | [diff] [blame] | 25 | script_stdout_is $expected, "Converts $morpho_fname correctly"; |
| 26 | } |
Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 27 | |
| 28 | for my $base_fname (glob("t/data/*\.zip")) { |
Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 29 | my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.conllu/r; |
Marc Kupietz | 628893e | 2021-02-12 15:50:29 +0100 | [diff] [blame] | 30 | next if (!-e $conllu_fname); |
Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 31 | |
| 32 | my $expected; |
| 33 | open(my $fh, '<', $conllu_fname) or die "cannot open file $conllu_fname"; { |
| 34 | local $/; |
| 35 | $expected = <$fh>; |
| 36 | } |
| 37 | close($fh); |
Marc Kupietz | 13994d1 | 2021-02-12 17:25:36 +0100 | [diff] [blame] | 38 | script_runs([ 'script/korapxml2conllu', $base_fname ], "Runs korapxml2conllu with base input"); |
| 39 | script_stdout_is $expected, "Converts $base_fname correctly to CoNLL-U"; |
Marc Kupietz | d845583 | 2021-02-11 17:30:29 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Marc Kupietz | 79ba1e5 | 2021-02-12 17:26:54 +0100 | [diff] [blame^] | 42 | my $test_tempdir = tempdir(); |
| 43 | my $expected; |
| 44 | open(my $fh, '<', "t/data/goe.morpho.conllu"); { |
| 45 | local $/; |
| 46 | $expected = <$fh>; |
| 47 | } |
| 48 | close($fh); |
| 49 | |
| 50 | my $zipfile = "$test_tempdir/goe.tree_tagger.zip"; |
| 51 | my $zipcontent; |
| 52 | script_runs([ 'script/conllu2korapxml', "t/data/goe.morpho.conllu" ], {stdout => \$zipcontent}, |
| 53 | "Converts t/data/goe.morpho.conllu to KorAP-XML zip"); |
| 54 | open(my $fh, ">", $zipfile) or fail("cannot open file $zipfile for writing"); |
| 55 | print $fh $zipcontent; |
| 56 | close($fh); |
| 57 | |
| 58 | copy("t/data/goe.zip", $test_tempdir); |
| 59 | script_runs([ 'script/korapxml2conllu', "$test_tempdir/goe.tree_tagger.zip" ], |
| 60 | "Converts $test_tempdir/goe.tree_tagger.zip to CoNLL-U"); |
| 61 | script_stdout_is $expected, "Full round trip: Converts goe.morpho.conllu to KorAP-XML and back to CoNLL-U correctly"; |
| 62 | |
| 63 | done_testing; |