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