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; |
| 32 | is($meta->{title}, 'Autobiographische Einzelheiten', 'Title'); |
| 33 | is($meta->{pub_place}, 'München', 'PubPlace'); |
| 34 | is($meta->{pub_date}, '19820000', 'Creation Date'); |
| 35 | ok(!$meta->{sub_title}, 'SubTitle'); |
| 36 | is($meta->{author}, 'Goethe, Johann Wolfgang von', 'Author'); |
| 37 | |
| 38 | is($meta->{publisher}, 'Verlag C. H. Beck', 'Publisher'); |
| 39 | ok(!$meta->{editor}, 'Publisher'); |
| 40 | is($meta->{text_type}, 'Autobiographie', 'Correct Text Type'); |
| 41 | ok(!$meta->{text_type_art}, 'Correct Text Type Art'); |
| 42 | ok(!$meta->{text_type_ref}, 'Correct Text Type Ref'); |
| 43 | ok(!$meta->{text_column}, 'Correct Text Column'); |
| 44 | ok(!$meta->{text_domain}, 'Correct Text Domain'); |
| 45 | is($meta->{creation_date}, '18200000', 'Creation Date'); |
| 46 | is($meta->{availability}, 'QAO-NC', 'License'); |
| 47 | is($meta->{pages}, '529-547', 'Pages'); |
| 48 | ok(!$meta->{file_edition_statement}, 'File Ed Statement'); |
| 49 | ok(!$meta->{bibl_edition_statement}, 'Bibl Ed Statement'); |
| 50 | is($meta->{reference} . "\n", <<'REF', 'Author'); |
| 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 |
| 53 | is($meta->{language}, 'de', 'Language'); |
| 54 | |
| 55 | |
| 56 | is($meta->{corpus_title}, 'Goethes Werke', 'Correct Corpus title'); |
| 57 | ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title'); |
| 58 | is($meta->{corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author'); |
| 59 | is($meta->{corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor'); |
| 60 | |
| 61 | is($meta->{doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', |
| 62 | 'Correct Doc title'); |
| 63 | ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title'); |
| 64 | ok(!$meta->{doc_author}, 'Correct Doc author'); |
| 65 | ok(!$meta->{doc_editor}, 'Correct Doc editor'); |
| 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'); |
| 112 | is($output->{pages}, '529-547', 'Pages'); |
| 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 |
| 131 | $tokens->add('DeReKo', 'Structure'); |
| 132 | |
| 133 | $output = $tokens->to_data; |
| 134 | |
| 135 | is($output->{data}->{foundries}, 'dereko dereko/structure', 'Foundries'); |
| 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'); |
| 141 | #like($first_token, qr!<>:base/s:s\$<b>64<i>0<i>30<i>2<b>4!, 'data'); |
| 142 | #like($first_token, qr!<>:base\/s:t\$<b>64<i>0<i>35199<i>5226<b>0!, 'data'); |
| 143 | |
| 144 | done_testing; |
| 145 | __END__ |