Akron | c388150 | 2017-01-20 14:36:37 +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 DRuKoLa-Files |
| 20 | |
| 21 | # New |
| 22 | # BBU/BLOG/83709_a_82384 |
| 23 | my $path = catdir(dirname(__FILE__), '../corpus/BBU/BLOG/83709_a_82384'); |
| 24 | |
| 25 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 26 | ok($doc->parse, 'Parse document'); |
| 27 | |
| 28 | is($doc->text_sigle, 'BBU/BLOG/83709_a_82384', 'Correct text sigle'); |
| 29 | is($doc->doc_sigle, 'BBU/BLOG', 'Correct document sigle'); |
| 30 | is($doc->corpus_sigle, 'BBU', 'Correct corpus sigle'); |
| 31 | |
| 32 | my $meta = $doc->meta; |
| 33 | is($meta->{title}, 'Schimbă vorba', 'Title'); |
| 34 | is($meta->{pub_place}, 'URL:http://www.bucurenci.ro', 'PubPlace'); |
| 35 | is($meta->{pub_date}, '20131005', 'Creation Date'); |
| 36 | ok(!$meta->{sub_title}, 'SubTitle'); |
| 37 | is($meta->{author}, 'Dragoș Bucurenci', 'Author'); |
| 38 | |
| 39 | ok(!$meta->{publisher}, 'Publisher'); |
| 40 | ok(!$meta->{editor}, 'Editor'); |
| 41 | #is($meta->{text_type}, 'Autobiographie', 'Correct Text Type'); |
| 42 | ok(!$meta->{text_type_art}, 'Correct Text Type Art'); |
| 43 | # is($meta->{text_type_ref}, '', 'Correct Text Type Ref'); |
| 44 | ok(!$meta->{text_column}, 'Correct Text Column'); |
| 45 | ok(!$meta->{text_domain}, 'Correct Text Domain'); |
| 46 | ok(!$meta->{creation_date}, 'Creation Date'); |
| 47 | |
| 48 | ok(!$meta->{pages}, 'Pages'); |
| 49 | ok(!$meta->{file_edition_statement}, 'File Ed Statement'); |
| 50 | ok(!$meta->{bibl_edition_statement}, 'Bibl Ed Statement'); |
| 51 | ok(!$meta->{reference}, 'Reference'); |
| 52 | is($meta->{language}, 'ro', 'Language'); |
| 53 | |
| 54 | #is($meta->{corpus_title}, 'Goethes Werke', 'Correct Corpus title'); |
| 55 | ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title'); |
| 56 | #is($meta->{corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author'); |
| 57 | #is($meta->{corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor'); |
| 58 | |
| 59 | #is($meta->{doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', |
| 60 | # 'Correct Doc title'); |
| 61 | ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title'); |
| 62 | ok(!$meta->{doc_author}, 'Correct Doc author'); |
| 63 | ok(!$meta->{doc_editor}, 'Correct Doc editor'); |
| 64 | |
| 65 | # Tokenization |
| 66 | use_ok('KorAP::XML::Tokenizer'); |
| 67 | |
| 68 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/); |
| 69 | |
| 70 | # Get tokenization |
| 71 | my $tokens = KorAP::XML::Tokenizer->new( |
| 72 | path => $doc->path, |
| 73 | doc => $doc, |
| 74 | foundry => $token_base_foundry, |
| 75 | layer => $token_base_layer, |
| 76 | name => 'tokens' |
| 77 | ); |
| 78 | ok($tokens, 'Token Object is fine'); |
| 79 | ok($tokens->parse, 'Token parsing is fine'); |
| 80 | |
| 81 | my $output = decode_json( $tokens->to_json ); |
| 82 | |
| 83 | ## Base |
| 84 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'); |
| 85 | ok($tokens->add('DRuKoLa', 'Morpho'), 'Add Drukola'); |
| 86 | |
| 87 | $output = $tokens->to_data; |
| 88 | |
| 89 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs drukola drukola/morpho', 'Foundries'); |
| 90 | |
| 91 | is($output->{data}->{layerInfos}, 'dereko/s=spans drukola/l=tokens drukola/m=tokens drukola/p=tokens', 'layerInfos'); |
| 92 | |
| 93 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 94 | |
| 95 | like($token, qr!drukola/l:la!, 'data'); |
| 96 | like($token, qr!drukola/m:msd:Sp!, 'data'); |
| 97 | like($token, qr!drukola/p:ADPOSITION!, 'data'); |
| 98 | |
| 99 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 100 | |
| 101 | like($token, qr!i:vorba!, 'data'); |
| 102 | like($token, qr!drukola/l:vorbă!, 'data'); |
| 103 | like($token, qr!drukola/m:case:Ncfsry!, 'data'); |
| 104 | like($token, qr!drukola/m:definiteness:yes!, 'data'); |
| 105 | like($token, qr!drukola/m:gender:feminine!, 'data'); |
| 106 | like($token, qr!drukola/p:NOUN!, 'data'); |
| 107 | |
| 108 | done_testing; |
| 109 | __END__ |