Nils Diewald | f03c680 | 2014-07-21 16:39:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | # source ~/perl5/perlbrew/etc/bashrc |
| 3 | # perlbrew switch perl-blead@korap |
| 4 | use strict; |
| 5 | use warnings; |
| 6 | use utf8; |
| 7 | use Test::More; |
| 8 | use Benchmark ':hireswallclock'; |
| 9 | use lib 'lib', '../lib'; |
| 10 | use Scalar::Util qw/weaken/; |
| 11 | |
| 12 | use File::Basename 'dirname'; |
| 13 | use File::Spec::Functions 'catdir'; |
| 14 | |
| 15 | use_ok('KorAP::Document'); |
| 16 | |
| 17 | my $path = catdir(dirname(__FILE__), 'artificial'); |
| 18 | ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document'); |
| 19 | is($doc->path, $path . '/', 'Path'); |
| 20 | ok($doc->parse, 'Parse document'); |
| 21 | |
| 22 | sub new_tokenizer { |
| 23 | my $x = $doc; |
| 24 | weaken $x; |
| 25 | return KorAP::Tokenizer->new( |
| 26 | path => $x->path, |
| 27 | doc => $x, |
| 28 | foundry => 'OpenNLP', |
| 29 | layer => 'Tokens', |
| 30 | name => 'tokens' |
| 31 | ) |
| 32 | }; |
| 33 | |
| 34 | is($doc->primary->data, |
| 35 | 'Zum letzten kulturellen Anlass lädt die Leitung des Schulheimes Hofbergli ein, '. |
| 36 | 'bevor der Betrieb Ende Schuljahr eingestellt wird.', 'Primary data'); |
| 37 | |
| 38 | is($doc->primary->data_length, 129, 'Primary data length'); |
| 39 | |
| 40 | is($doc->primary->data(0,3), 'Zum', 'Get primary data'); |
| 41 | |
| 42 | # Get tokens |
| 43 | use_ok('KorAP::Tokenizer'); |
| 44 | # Get tokenization |
| 45 | ok(my $tokens = KorAP::Tokenizer->new( |
| 46 | path => $doc->path, |
| 47 | doc => $doc, |
| 48 | foundry => 'OpenNLP', |
| 49 | layer => 'Tokens', |
| 50 | name => 'tokens' |
| 51 | ), 'New Tokenizer'); |
| 52 | ok($tokens->parse, 'Parse'); |
| 53 | |
| 54 | ok($tokens->add_subtokens, 'Add subtokens'); |
| 55 | |
| 56 | # diag $tokens->to_string; |
| 57 | |
| 58 | #foreach (@{$tokens->stream->multi_term_tokens}) { |
| 59 | # print $_; |
| 60 | #}; |
| 61 | |
| 62 | done_testing; |
| 63 | |
| 64 | |
| 65 | __END__ |