blob: 7197beade2f87d609ddb8dd743fea21ab35978aa [file] [log] [blame]
Akronca9dbb32016-01-05 20:54:34 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use utf8;
5use Test::More;
6use Scalar::Util qw/weaken/;
7use Data::Dumper;
8
9use_ok('KorAP::Document');
10
11use File::Basename 'dirname';
12use File::Spec::Functions 'catdir';
13
14my $path = catdir(dirname(__FILE__), 'corpus', 'doc', 'text');
15
16ok(my $doc = KorAP::Document->new(
17 path => $path . '/'
18), 'Load Korap::Document');
19
20like($doc->path, qr!$path/$!, 'Path');
21ok($doc->parse, 'Parse document');
22
23ok($doc->primary->data, 'Primary data in existence');
24is($doc->primary->data_length, 129, 'Data length');
25
26use_ok('KorAP::Tokenizer');
27
28ok(my $tokens = KorAP::Tokenizer->new(
29 path => $doc->path,
30 doc => $doc,
31 foundry => 'OpenNLP',
32 layer => 'Tokens',
33 name => 'tokens'
34), 'New Tokenizer');
35
36ok($tokens->parse, 'Parse');
37
38ok($tokens->add('XIP', 'Constituency'), 'Add Structure');
39
40my $data = $tokens->to_data->{data};
41like($data->{foundries}, qr!xip/constituency!, 'data');
42like($data->{layerInfos}, qr!xip/c=spans!, 'data');
43
44# The length includes the punct - but that doesn't matter
45is($data->{stream}->[0]->[1], '<>:xip/c:PREP$<b>64<i>0<i>3<i>1<b>3', 'Prep phrase');
46is($data->{stream}->[0]->[2], '<>:xip/c:PP$<b>64<i>0<i>30<i>4<b>2', 'pp phrase');
47is($data->{stream}->[0]->[3], '<>:xip/c:TOP$<b>64<i>0<i>129<i>17<b>0', 'top phrase');
48is($data->{stream}->[0]->[4], '<>:xip/c:MC$<b>64<i>0<i>129<i>17<b>1', 'mc phrase');
49
50is($data->{stream}->[-1]->[0], '<>:xip/c:VERB$<b>64<i>124<i>128<i>18<b>4', 'Noun phrase');
51
52done_testing;
53
54__END__
55
56
57
58