Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame^] | 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 11 | use Benchmark qw/:hireswallclock/; |
| 12 | |
| 13 | my $t = Benchmark->new; |
| 14 | |
| 15 | use utf8; |
| 16 | use lib 'lib', '../lib'; |
| 17 | |
| 18 | use File::Basename 'dirname'; |
| 19 | use File::Spec::Functions 'catdir'; |
| 20 | |
| 21 | use_ok('KorAP::XML::Krill'); |
| 22 | |
| 23 | # This will Check Goethe-Files without base annotations! |
| 24 | |
| 25 | # GOE/AGA/03828 |
| 26 | my $path = catdir(dirname(__FILE__), '../corpus/GOE2/AGA/03828'); |
| 27 | |
| 28 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 29 | ok($doc->parse, 'Parse document'); |
| 30 | |
| 31 | is($doc->text_sigle, 'GOE/AGA/03828', 'Correct text sigle'); |
| 32 | is($doc->doc_sigle, 'GOE/AGA', 'Correct document sigle'); |
| 33 | is($doc->corpus_sigle, 'GOE', 'Correct corpus sigle'); |
| 34 | |
| 35 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 36 | is($meta->{T_title}, 'Autobiographische Einzelheiten', 'Title'); |
| 37 | is($meta->{S_pub_place}, 'München', 'PubPlace'); |
| 38 | is($meta->{D_pub_date}, '19820000', 'Creation Date'); |
| 39 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 40 | is($meta->{T_author}, 'Goethe, Johann Wolfgang von', 'Author'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 41 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 42 | is($meta->{A_publisher}, 'Verlag C. H. Beck', 'Publisher'); |
| 43 | ok(!$meta->{A_editor}, 'Publisher'); |
| 44 | is($meta->{S_text_type}, 'Autobiographie', 'Correct Text Type'); |
| 45 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 46 | ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref'); |
| 47 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 48 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 49 | is($meta->{D_creation_date}, '18200000', 'Creation Date'); |
| 50 | is($meta->{S_availability}, 'QAO-NC', 'License'); |
| 51 | is($meta->{A_src_pages}, '529-547', 'Pages'); |
| 52 | ok(!$meta->{A_file_edition_statement}, 'File Ed Statement'); |
| 53 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 54 | is($meta->{A_reference} . "\n", <<'REF', 'Author'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 55 | Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547 |
| 56 | REF |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 57 | is($meta->{S_language}, 'de', 'Language'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 58 | |
| 59 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 60 | is($meta->{T_corpus_title}, 'Goethes Werke', 'Correct Corpus title'); |
| 61 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 62 | is($meta->{T_corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author'); |
| 63 | is($meta->{A_corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 64 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 65 | is($meta->{T_doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 66 | 'Correct Doc title'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 67 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 68 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 69 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 70 | |
| 71 | # Tokenization |
| 72 | use_ok('KorAP::XML::Tokenizer'); |
| 73 | |
| 74 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/); |
| 75 | |
| 76 | # Get tokenization |
| 77 | my $tokens = KorAP::XML::Tokenizer->new( |
| 78 | path => $doc->path, |
| 79 | doc => $doc, |
| 80 | foundry => $token_base_foundry, |
| 81 | layer => $token_base_layer, |
| 82 | name => 'tokens' |
| 83 | ); |
| 84 | ok($tokens, 'Token Object is fine'); |
| 85 | ok($tokens->parse, 'Token parsing is fine'); |
| 86 | |
| 87 | my $output = decode_json( $tokens->to_json ); |
| 88 | |
| 89 | is(substr($output->{data}->{text}, 0, 100), 'Autobiographische einzelheiten Selbstschilderung (1) immer tätiger, nach innen und außen fortwirkend', 'Primary Data'); |
| 90 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 91 | is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource'); |
| 92 | is($output->{version}, '0.03', 'version'); |
| 93 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 94 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 95 | is($output->{data}->{stream}->[0]->[4], 's:Autobiographische', 'data'); |
| 96 | |
| 97 | is($output->{textSigle}, 'GOE/AGA/03828', 'Correct text sigle'); |
| 98 | is($output->{docSigle}, 'GOE/AGA', 'Correct document sigle'); |
| 99 | is($output->{corpusSigle}, 'GOE', 'Correct corpus sigle'); |
| 100 | |
| 101 | is($output->{author}, 'Goethe, Johann Wolfgang von', 'Author'); |
| 102 | is($output->{pubPlace}, 'München', 'PubPlace'); |
| 103 | is($output->{pubDate}, '19820000', 'Creation Date'); |
| 104 | is($output->{title}, 'Autobiographische Einzelheiten', 'Title'); |
| 105 | ok(!exists $output->{subTitle}, 'subTitle'); |
| 106 | |
| 107 | is($output->{publisher}, 'Verlag C. H. Beck', 'Publisher'); |
| 108 | ok(!exists $output->{editor}, 'Editor'); |
| 109 | is($output->{textType}, 'Autobiographie', 'Correct Text Type'); |
| 110 | ok(!exists $output->{textTypeArt}, 'Correct Text Type'); |
| 111 | ok(!exists $output->{textTypeRef}, 'Correct Text Type'); |
| 112 | ok(!exists $output->{textColumn}, 'Correct Text Type'); |
| 113 | ok(!exists $output->{textDomain}, 'Correct Text Type'); |
| 114 | is($output->{creationDate}, '18200000', 'Creation Date'); |
| 115 | is($output->{availability}, 'QAO-NC', 'License'); |
Akron | 08d5445 | 2017-02-16 23:19:49 +0100 | [diff] [blame] | 116 | is($output->{srcPages}, '529-547', 'Pages'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 117 | ok(!exists $output->{fileEditionStatement}, 'Correct Text Type'); |
| 118 | ok(!exists $output->{biblEditionStatement}, 'Correct Text Type'); |
| 119 | is($output->{reference} . "\n", <<'REF', 'Author'); |
| 120 | Goethe, Johann Wolfgang von: Autobiographische Einzelheiten, (Geschrieben bis 1832), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 10, Autobiographische Schriften II, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 529-547 |
| 121 | REF |
| 122 | is($output->{language}, 'de', 'Language'); |
| 123 | |
| 124 | is($output->{corpusTitle}, 'Goethes Werke', 'Correct Corpus title'); |
| 125 | ok(!exists $output->{corpusSubTitle}, 'Correct Text Type'); |
| 126 | is($output->{corpusAuthor}, 'Goethe, Johann Wolfgang von', 'Correct Corpus title'); |
| 127 | is($output->{corpusEditor}, 'Trunz, Erich', 'Editor'); |
| 128 | |
| 129 | is($output->{docTitle}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'Correct Corpus title'); |
| 130 | ok(!exists $output->{docSubTitle}, 'Correct Text Type'); |
| 131 | ok(!exists $output->{docAuthor}, 'Correct Text Type'); |
| 132 | ok(!exists $output->{docEditor}, 'Correct Text Type'); |
| 133 | |
| 134 | ## Base |
Akron | 3c11964 | 2017-02-10 14:54:08 +0100 | [diff] [blame] | 135 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs_pagebreaks'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 136 | |
| 137 | $output = $tokens->to_data; |
| 138 | |
Akron | 3c11964 | 2017-02-10 14:54:08 +0100 | [diff] [blame] | 139 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs_pagebreaks', 'Foundries'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 140 | is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos'); |
| 141 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 142 | like($first_token, qr/s:Autobiographische/, 'data'); |
| 143 | like($first_token, qr/_0\$<i>0<i>17/, 'data'); |
| 144 | like($first_token, qr!<>:dereko/s:s\$<b>64<i>0<i>30<i>2<b>4!, 'data'); |
Akron | dec4312 | 2020-03-03 11:22:25 +0100 | [diff] [blame] | 145 | like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35242<i>5234<b>0!, 'data'); |
Akron | d35d2d3 | 2017-02-13 16:57:42 +0100 | [diff] [blame] | 146 | # like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35250<i>5233<b>0!, 'data'); |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 147 | like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>30<i>2<b>2!, 'data'); |
| 148 | like($first_token, qr!-:base\/paragraphs\$\<i\>14!, 'data'); |
| 149 | like($first_token, qr!-:base\/sentences\$\<i\>215!, 'data'); |
| 150 | |
Akron | d35d2d3 | 2017-02-13 16:57:42 +0100 | [diff] [blame] | 151 | is($output->{data}->{stream}->[378]->[-1], '~:base/s:pb$<i>530<i>2469', 'Pagebreaks'); |
Akron | 3c11964 | 2017-02-10 14:54:08 +0100 | [diff] [blame] | 152 | |
Akron | 3741f8b | 2016-12-21 19:55:21 +0100 | [diff] [blame] | 153 | # Check paragraph |
| 154 | $first_token = join('||', @{$output->{data}->{stream}->[4]}); |
| 155 | like($first_token, qr/s:immer/, 'data'); |
| 156 | like($first_token, qr!<>:base\/s:s\$<b>64<i>53<i>254<i>32<b>2!, 'data'); |
| 157 | like($first_token, qr!<>:dereko\/s:s\$<b>64<i>53<i>254<i>32<b>5<s>1!, 'data'); |
| 158 | like($first_token, qr!<>:base/s:p\$\<b>64<i>53<i>3299<i>504<b>1!, 'data'); |
| 159 | like($first_token, qr!<>:dereko/s:p\$\<b>64<i>53<i>3299<i>504<b>4!, 'data'); |
| 160 | |
| 161 | $first_token = join('||', @{$output->{data}->{stream}->[180]}); |
| 162 | like($first_token, qr/i:geschäften/, 'data'); |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 163 | |
Akron | b2f1ab8 | 2017-02-22 19:13:15 +0100 | [diff] [blame] | 164 | ## MarMoT |
| 165 | ok($tokens->add('MarMoT', 'Morpho'), 'Add marmot'); |
| 166 | |
| 167 | $output = $tokens->to_data; |
| 168 | |
| 169 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs_pagebreaks marmot marmot/morpho', 'Foundries'); |
| 170 | |
| 171 | is($output->{data}->{layerInfos}, 'dereko/s=spans marmot/m=tokens marmot/p=tokens', 'layerInfos'); |
| 172 | $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 173 | like($first_token, qr!marmot/m:case:nom!, 'Marmot case'); |
| 174 | like($first_token, qr!marmot/m:degree:pos!, 'Marmot degree'); |
| 175 | like($first_token, qr!marmot/m:gender:fem!, 'Marmot gender'); |
| 176 | like($first_token, qr!marmot/m:number:pl!, 'Marmot number'); |
| 177 | like($first_token, qr!marmot/p:ADJA!, 'Marmot part of speech'); |
| 178 | |
Akron | 53167fd | 2016-12-21 15:01:01 +0100 | [diff] [blame] | 179 | done_testing; |
| 180 | __END__ |