Akron | 1924bbe | 2016-06-22 16:05:41 +0200 | [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 | my $path = catdir(dirname(__FILE__), '../corpus/REI/BNG/00128'); |
| 20 | |
| 21 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 22 | ok($doc->parse, 'Parse document'); |
| 23 | |
| 24 | is($doc->text_sigle, 'REI/BNG/00128', 'Correct text sigle'); |
| 25 | is($doc->doc_sigle, 'REI/BNG', 'Correct document sigle'); |
| 26 | is($doc->corpus_sigle, 'REI', 'Correct corpus sigle'); |
| 27 | |
| 28 | my $meta = $doc->meta; |
| 29 | is($meta->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title'); |
| 30 | is($meta->{sub_title}, 'Rede im Deutschen Bundestag am 14.06.2002', 'SubTitle'); |
| 31 | is($meta->{author}, 'Nachtwei, Winfried', 'Author'); |
| 32 | ok(!$meta->{editor}, 'Editor'); |
| 33 | is($meta->{pub_place}, 'Berlin', 'PubPlace'); |
| 34 | ok(!$meta->{publisher}, 'Publisher'); |
| 35 | |
| 36 | ok(!$meta->{text_type}, 'No Text Type'); |
| 37 | ok(!$meta->{text_type_art}, 'No Text Type Art'); |
| 38 | ok(!$meta->{text_type_ref}, 'No Text Type Ref'); |
| 39 | ok(!$meta->{text_domain}, 'No Text Domain'); |
| 40 | ok(!$meta->{text_column}, 'No Text Column'); |
| 41 | |
| 42 | is($meta->{text_class}->[0], 'politik', 'Correct Text Class'); |
| 43 | is($meta->{text_class}->[1], 'inland', 'Correct Text Class'); |
| 44 | ok(!$meta->{text_class}->[2], 'Correct Text Class'); |
| 45 | |
| 46 | is($meta->{pub_date}, '20020614', 'Creation date'); |
| 47 | is($meta->{creation_date}, '20020614', 'Creation date'); |
| 48 | is($meta->{availability}, 'CC-BY-SA', 'License'); |
| 49 | ok(!$meta->{pages}, 'Pages'); |
| 50 | |
| 51 | ok(!$meta->{file_edition_statement}, 'File Statement'); |
| 52 | ok(!$meta->{bibl_edition_statement}, 'Bibl Statement'); |
| 53 | |
| 54 | is($meta->{reference} . "\n", <<'REF', 'Reference'); |
| 55 | Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar] |
| 56 | REF |
| 57 | is($meta->{language}, 'de', 'Language'); |
| 58 | |
| 59 | is($meta->{corpus_title}, 'Reden und Interviews', 'Correct Corpus title'); |
| 60 | ok(!$meta->{corpus_sub_title}, 'Correct Corpus sub title'); |
| 61 | ok(!$meta->{corpus_author}, 'Correct Corpus author'); |
| 62 | ok(!$meta->{corpus_editor}, 'Correct Corpus editor'); |
| 63 | |
| 64 | is($meta->{doc_title}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title'); |
| 65 | ok(!$meta->{doc_sub_title}, 'Correct Doc sub title'); |
| 66 | ok(!$meta->{doc_author}, 'Correct Doc author'); |
| 67 | ok(!$meta->{doc_editor}, 'Correct doc editor'); |
| 68 | |
| 69 | # Tokenization |
| 70 | use_ok('KorAP::XML::Tokenizer'); |
| 71 | |
| 72 | my ($token_base_foundry, $token_base_layer) = (qw/Base tokens_conservative/); |
| 73 | |
| 74 | # Get tokenization |
| 75 | my $tokens = KorAP::XML::Tokenizer->new( |
| 76 | path => $doc->path, |
| 77 | doc => $doc, |
| 78 | foundry => $token_base_foundry, |
| 79 | layer => $token_base_layer, |
| 80 | name => 'tokens' |
| 81 | ); |
| 82 | |
| 83 | ok($tokens, 'Token Object is fine'); |
| 84 | ok($tokens->parse, 'Token parsing is fine'); |
| 85 | |
| 86 | my $output = decode_json( $tokens->to_json ); |
| 87 | |
| 88 | is(substr($output->{data}->{text}, 0, 100), 'Winfried Nachtwei, Friedensgutachten der führenden Friedensforschungsinstitute 14. Juni 2002 Vizeprä', 'Primary Data'); |
| 89 | |
| 90 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 91 | is($output->{data}->{tokenSource}, 'base#tokens_conservative', 'tokenSource'); |
| 92 | is($output->{version}, '0.03', 'version'); |
| 93 | |
| 94 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 95 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 96 | is($output->{data}->{stream}->[0]->[4], 's:Winfried', 'data'); |
| 97 | |
| 98 | is($output->{textSigle}, 'REI/BNG/00128', 'Correct text sigle'); |
| 99 | is($output->{docSigle}, 'REI/BNG', 'Correct document sigle'); |
| 100 | is($output->{corpusSigle}, 'REI', 'Correct corpus sigle'); |
| 101 | |
| 102 | is($output->{title}, 'Friedensgutachten der führenden Friedensforschungsinstitute', 'Title'); |
| 103 | is($output->{subTitle}, 'Rede im Deutschen Bundestag am 14.06.2002', 'Correct SubTitle'); |
| 104 | is($output->{author}, 'Nachtwei, Winfried', 'Author'); |
| 105 | ok(!exists $output->{editor}, 'Publisher'); |
| 106 | |
| 107 | is($output->{pubPlace}, 'Berlin', 'PubPlace'); |
| 108 | ok(!exists $output->{publisher}, 'Publisher'); |
| 109 | |
| 110 | ok(!exists $output->{textType}, 'Correct Text Type'); |
| 111 | ok(!exists $output->{textTypeArt}, 'Correct Text Type Art'); |
| 112 | ok(!exists $output->{textTypeRef}, 'Correct Text Type Ref'); |
| 113 | ok(!exists $output->{textDomain}, 'Correct Text Domain'); |
| 114 | |
| 115 | is($output->{creationDate}, '20020614', 'Creation date'); |
| 116 | is($output->{availability}, 'CC-BY-SA', 'License'); |
| 117 | |
| 118 | ok(!exists $output->{pages}, 'Pages'); |
| 119 | ok(!exists $output->{fileEditionStatement}, 'File Statement'); |
| 120 | ok(!exists $output->{biblEditionStatement}, 'Bibl Statement'); |
| 121 | |
| 122 | is($output->{reference} . "\n", <<'REF', 'Reference'); |
| 123 | Nachtwei, Winfried: Friedensgutachten der führenden Friedensforschungsinstitute. Rede im Deutschen Bundestag am 14.06.2002, Hrsg: Bundestagsfraktion Bündnis 90/DIE GRÜNEN [Ausführliche Zitierung nicht verfügbar] |
| 124 | REF |
| 125 | is($output->{language}, 'de', 'Language'); |
| 126 | |
| 127 | is($output->{corpusTitle}, 'Reden und Interviews', 'Correct Corpus title'); |
| 128 | ok(!exists $output->{corpusSubTitle}, 'Correct Corpus sub title'); |
| 129 | ok(!exists $output->{corpusAuthor}, 'Correct Corpus author'); |
| 130 | ok(!exists $output->{corpusEditor}, 'Correct Corpus editor'); |
| 131 | |
| 132 | is($output->{docTitle}, 'Reden der Bundestagsfraktion Bündnis 90/DIE GRÜNEN, (2002-2006)', 'Correct Doc title'); |
| 133 | ok(!exists $output->{docSubTitle}, 'Correct Doc sub title'); |
| 134 | ok(!exists $output->{docAuthor}, 'Correct Doc author'); |
| 135 | ok(!exists $output->{docEditor}, 'Correct doc editor'); |
| 136 | |
| 137 | ## Base |
| 138 | $tokens->add('Base', 'Sentences'); |
| 139 | $tokens->add('Base', 'Paragraphs'); |
| 140 | |
| 141 | $output = decode_json( $tokens->to_json ); |
| 142 | |
| 143 | is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries'); |
| 144 | is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos'); |
| 145 | my $first_token = join('||', @{$output->{data}->{stream}->[0]}); |
| 146 | like($first_token, qr/s:Winfried/, 'data'); |
| 147 | like($first_token, qr/_0\$<i>0<i>8/, 'data'); |
| 148 | |
| 149 | |
| 150 | done_testing; |
| 151 | __END__ |