blob: 877a7dc8f028d14eba925174609a17f0486fbe84 [file] [log] [blame]
Marc Kupietzbb739b02020-09-22 16:49:34 +02001use strict;
2use warnings;
Akron46f2c232021-02-12 17:21:39 +01003use Test::More tests => 10;
Marc Kupietzbb739b02020-09-22 16:49:34 +02004use Test::Script;
Marc Kupietz79ba1e52021-02-12 17:26:54 +01005use Test::TempDir::Tiny;
6use File::Copy;
Marc Kupietzbb739b02020-09-22 16:49:34 +02007
8script_runs([ 'script/korapxml2conllu', '-h' ], { exit => 255 });
9script_stderr_like "Description", "Can print help message";
10
11for my $morpho_fname (glob("t/data/*\.*\.zip")) {
12 my $base_fname = $morpho_fname =~ s/(.*)\..*\.zip/$1.zip/r;
Akron46f2c232021-02-12 17:21:39 +010013 if (!-e $base_fname) {
14 fail("cannot find $base_fname");
15 next;
16 };
Marc Kupietzbb739b02020-09-22 16:49:34 +020017
Marc Kupietzd8455832021-02-11 17:30:29 +010018 my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.morpho.conllu/r;
Akron46f2c232021-02-12 17:21:39 +010019 if (!-e $conllu_fname) {
20 fail("cannot find $conllu_fname");
21 next;
22 };
Marc Kupietzbb739b02020-09-22 16:49:34 +020023
24 my $expected;
Akron46f2c232021-02-12 17:21:39 +010025 if (open(my $fh, '<', $conllu_fname)) {
Marc Kupietzbb739b02020-09-22 16:49:34 +020026 local $/;
27 $expected = <$fh>;
Akron46f2c232021-02-12 17:21:39 +010028 close($fh);
29 } else {
30 fail("cannot open file $conllu_fname");
31 next;
Marc Kupietzbb739b02020-09-22 16:49:34 +020032 }
Marc Kupietz13994d12021-02-12 17:25:36 +010033 script_runs([ 'script/korapxml2conllu', $morpho_fname ], "Runs korapxml2conllu with pos and lemma annotated input");
Marc Kupietzbb739b02020-09-22 16:49:34 +020034 script_stdout_is $expected, "Converts $morpho_fname correctly";
35}
Marc Kupietzd8455832021-02-11 17:30:29 +010036
37for my $base_fname (glob("t/data/*\.zip")) {
Marc Kupietzd8455832021-02-11 17:30:29 +010038 my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.conllu/r;
Marc Kupietz628893e2021-02-12 15:50:29 +010039 next if (!-e $conllu_fname);
Marc Kupietzd8455832021-02-11 17:30:29 +010040
41 my $expected;
Akron46f2c232021-02-12 17:21:39 +010042 if (open(my $fh, '<', $conllu_fname)) {
Marc Kupietzd8455832021-02-11 17:30:29 +010043 local $/;
44 $expected = <$fh>;
Akron46f2c232021-02-12 17:21:39 +010045 close($fh);
46 } else {
47 fail("cannot open file $conllu_fname");
48 next;
Marc Kupietzd8455832021-02-11 17:30:29 +010049 }
Marc Kupietz13994d12021-02-12 17:25:36 +010050 script_runs([ 'script/korapxml2conllu', $base_fname ], "Runs korapxml2conllu with base input");
51 script_stdout_is $expected, "Converts $base_fname correctly to CoNLL-U";
Marc Kupietzd8455832021-02-11 17:30:29 +010052}
53
Marc Kupietz79ba1e52021-02-12 17:26:54 +010054my $test_tempdir = tempdir();
55my $expected;
Akron46f2c232021-02-12 17:21:39 +010056my $conllu_fname = "t/data/goe.morpho.conllu";
57if(open(my $fh, '<', $conllu_fname )) {
Marc Kupietz79ba1e52021-02-12 17:26:54 +010058 local $/;
59 $expected = <$fh>;
Akron46f2c232021-02-12 17:21:39 +010060 close($fh);
61} else {
62 fail("cannot open file $conllu_fname");
63 }
64
65ok(length($expected) > 100, 'Output is not empty');
Marc Kupietz79ba1e52021-02-12 17:26:54 +010066
67my $zipfile = "$test_tempdir/goe.tree_tagger.zip";
68my $zipcontent;
69script_runs([ 'script/conllu2korapxml', "t/data/goe.morpho.conllu" ], {stdout => \$zipcontent},
70 "Converts t/data/goe.morpho.conllu to KorAP-XML zip");
71open(my $fh, ">", $zipfile) or fail("cannot open file $zipfile for writing");
72print $fh $zipcontent;
73close($fh);
Marc Kupietz79ba1e52021-02-12 17:26:54 +010074copy("t/data/goe.zip", $test_tempdir);
75script_runs([ 'script/korapxml2conllu', "$test_tempdir/goe.tree_tagger.zip" ],
76 "Converts $test_tempdir/goe.tree_tagger.zip to CoNLL-U");
77script_stdout_is $expected, "Full round trip: Converts goe.morpho.conllu to KorAP-XML and back to CoNLL-U correctly";
Marc Kupietz79ba1e52021-02-12 17:26:54 +010078done_testing;