Akron | ed9baf0 | 2019-01-22 17:03:25 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use utf8; |
| 5 | use Test::More; |
| 6 | use JSON::XS; |
| 7 | |
| 8 | use File::Basename 'dirname'; |
| 9 | use File::Spec::Functions 'catdir'; |
| 10 | |
| 11 | sub _t2h { |
| 12 | my $string = shift; |
| 13 | $string =~ s/^\[\(\d+?-\d+?\)(.+?)\]$/$1/; |
| 14 | my %hash = (); |
| 15 | foreach (split(qr!\|!, $string)) { |
| 16 | $hash{$_} = 1; |
| 17 | }; |
| 18 | return \%hash; |
| 19 | }; |
| 20 | |
| 21 | use_ok('KorAP::XML::Krill'); |
| 22 | |
| 23 | my $path = catdir(dirname(__FILE__), 'corpus/WPD/00001'); |
| 24 | ok(my $doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document'); |
| 25 | like($doc->path, qr!\Q$path\E/$!, 'Path'); |
| 26 | ok($doc->parse, 'Parse document'); |
| 27 | is($doc->text_sigle, 'WPD/AAA/00001', 'ID'); |
| 28 | |
| 29 | |
| 30 | # Get tokens |
| 31 | use_ok('KorAP::XML::Tokenizer'); |
| 32 | |
| 33 | # Get tokenization |
| 34 | ok(my $tokens = KorAP::XML::Tokenizer->new( |
| 35 | path => $doc->path, |
| 36 | doc => $doc, |
| 37 | foundry => 'OpenNLP', |
| 38 | layer => 'Tokens', |
| 39 | name => 'tokens' |
| 40 | ), 'New Tokenizer'); |
| 41 | ok($tokens->parse, 'Parse'); |
| 42 | |
| 43 | like($tokens->stream->pos(12)->to_string, qr/s:Vokal/); |
| 44 | like($tokens->stream->pos(13)->to_string, qr/s:Der/); |
| 45 | |
| 46 | |
| 47 | # Get tokenization with non word tokens |
| 48 | ok($tokens = KorAP::XML::Tokenizer->new( |
| 49 | path => $doc->path, |
| 50 | doc => $doc, |
| 51 | foundry => 'OpenNLP', |
| 52 | layer => 'Tokens', |
| 53 | name => 'tokens', |
| 54 | non_word_tokens => 1 |
| 55 | ), 'New Tokenizer'); |
| 56 | ok($tokens->parse, 'Parse'); |
| 57 | |
| 58 | like($tokens->stream->pos(12)->to_string, qr/s:Vokal/); |
| 59 | like($tokens->stream->pos(13)->to_string, qr/s:\./); |
| 60 | like($tokens->stream->pos(14)->to_string, qr/s:Der/); |
| 61 | |
| 62 | |
| 63 | done_testing; |
| 64 | |
| 65 | __END__ |