Add and test term-to-element and element-to-term relation
Change-Id: I55e562a5295f40617b41786c8758557a72e9537d
diff --git a/t/real/goethe.t b/t/real/goethe.t
index eeefb39..770f70e 100644
--- a/t/real/goethe.t
+++ b/t/real/goethe.t
@@ -129,7 +129,7 @@
$tokens->add('Base', 'Sentences');
$tokens->add('Base', 'Paragraphs');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
is($output->{data}->{foundries}, 'base base/paragraphs base/sentences', 'Foundries');
is($output->{data}->{layerInfos}, 'base/s=spans', 'layerInfos');
@@ -151,7 +151,7 @@
like($first_token, qr!<>:opennlp/s:s\$<b>64<i>0<i>254<i>32!, 'data');
$tokens->add('OpenNLP', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
is($output->{data}->{foundries},
'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences',
'Foundries');
@@ -161,7 +161,7 @@
## Treetagger
$tokens->add('TreeTagger', 'Sentences');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
is($output->{data}->{foundries},
'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/sentences',
'Foundries');
@@ -170,7 +170,7 @@
like($first_token, qr!<>:tt/s:s\$<b>64<i>0<i>179<i>21<b>0!, 'data');
$tokens->add('TreeTagger', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
is($output->{data}->{foundries},
'base base/paragraphs base/sentences opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
'Foundries');
@@ -184,7 +184,7 @@
## CoreNLP
$tokens->add('CoreNLP', 'NamedEntities');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
is($output->{data}->{foundries},
'base base/paragraphs base/sentences corenlp corenlp/namedentities opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences',
'Foundries');
@@ -206,14 +206,14 @@
like($first_token, qr!<>:corenlp/s:s\$<b>64<i>0<i>254<i>32<b>0!, 'data');
$tokens->add('CoreNLP', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!corenlp/morpho!, 'Foundries');
like($output->{data}->{layerInfos}, qr!corenlp/p=tokens!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
like($first_token, qr!corenlp/p:ADJA!, 'data');
$tokens->add('CoreNLP', 'Constituency');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!corenlp/constituency!, 'Foundries');
like($output->{data}->{layerInfos}, qr!corenlp/c=spans!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
@@ -230,7 +230,7 @@
## Glemm
$tokens->add('Glemm', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!glemm/morpho!, 'Foundries');
like($output->{data}->{layerInfos}, qr!glemm/l=tokens!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
@@ -242,14 +242,14 @@
## Connexor
$tokens->add('Connexor', 'Sentences');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!connexor/sentences!, 'Foundries');
like($output->{data}->{layerInfos}, qr!cnx/s=spans!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
like($first_token, qr!<>:cnx/s:s\$<b>64<i>0<i>179<i>21<b>0!, 'data');
$tokens->add('Connexor', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!connexor/morpho!, 'Foundries');
like($output->{data}->{layerInfos}, qr!cnx/p=tokens!, 'layerInfos');
like($output->{data}->{layerInfos}, qr!cnx/l=tokens!, 'layerInfos');
@@ -259,14 +259,14 @@
like($first_token, qr!cnx/p:A!, 'data');
$tokens->add('Connexor', 'Phrase');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!connexor/phrase!, 'Foundries');
like($output->{data}->{layerInfos}, qr!cnx/c=spans!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
like($first_token, qr!<>:cnx/c:np\$<b>64<i>0<i>30<i>2!, 'data');
$tokens->add('Connexor', 'Syntax');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!connexor/syntax!, 'Foundries');
like($output->{data}->{layerInfos}, qr!cnx/syn=tokens!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
@@ -274,7 +274,7 @@
## Mate
$tokens->add('Mate', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!mate/morpho!, 'Foundries');
like($output->{data}->{layerInfos}, qr!mate/p=tokens!, 'layerInfos');
like($output->{data}->{layerInfos}, qr!mate/l=tokens!, 'layerInfos');
@@ -286,18 +286,16 @@
like($first_token, qr!mate/m:number:pl!, 'data');
like($first_token, qr!mate/m:gender:\*!, 'data');
-# diag "No test for mate dependency";
-
## XIP
$tokens->add('XIP', 'Sentences');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!xip/sentences!, 'Foundries');
like($output->{data}->{layerInfos}, qr!xip/s=spans!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
like($first_token, qr!<>:xip/s:s\$<b>64<i>0<i>179<i>21!, 'data');
$tokens->add('XIP', 'Morpho');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!xip/morpho!, 'Foundries');
like($output->{data}->{layerInfos}, qr!xip/l=tokens!, 'layerInfos');
like($output->{data}->{layerInfos}, qr!xip/p=tokens!, 'layerInfos');
@@ -305,7 +303,7 @@
like($first_token, qr!<>:xip/s:s\$<b>64<i>0<i>179<i>21!, 'data');
$tokens->add('XIP', 'Constituency');
-$output = decode_json( $tokens->to_json );
+$output = $tokens->to_data;
like($output->{data}->{foundries}, qr!xip/constituency!, 'Foundries');
like($output->{data}->{layerInfos}, qr!xip/c=spans!, 'layerInfos');
$first_token = join('||', @{$output->{data}->{stream}->[0]});
@@ -314,9 +312,10 @@
like($first_token, qr!<>:xip/c:ADJ\$<b>64<i>0<i>17<i>1<b>3!, 'data');
like($first_token, qr!<>:xip/c:TOP\$<b>64<i>0<i>179<i>21<b>0!, 'data');
+# diag "No test for mate dependency";
# diag "No test for xip dependency";
-# print timestr(timediff(Benchmark->new, $t));
+# diag timestr(timediff(Benchmark->new, $t));
done_testing;
__END__
diff --git a/t/real/wpd.t b/t/real/wpd.t
new file mode 100644
index 0000000..c3ddc7b
--- /dev/null
+++ b/t/real/wpd.t
@@ -0,0 +1,86 @@
+use strict;
+use warnings;
+use Test::More;
+use Data::Dumper;
+use JSON::XS;
+
+use Benchmark qw/:hireswallclock/;
+
+my $t = Benchmark->new;
+
+use utf8;
+use lib 'lib', '../lib';
+
+use File::Basename 'dirname';
+use File::Spec::Functions 'catdir';
+
+use_ok('KorAP::XML::Krill');
+
+# GOE/AGA/03828
+my $path = catdir(dirname(__FILE__), '../corpus/WPD/00001');
+# my $path = '/home/ndiewald/Repositories/korap/KorAP-sandbox/KorAP-lucene-indexer/t/GOE/AGA/03828';
+
+ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
+ok($doc->parse, 'Parse document');
+
+is($doc->text_sigle, 'WPD_AAA.00001', 'Correct text sigle');
+is($doc->doc_sigle, 'WPD_AAA', 'Correct document sigle');
+is($doc->corpus_sigle, 'WPD', 'Correct corpus sigle');
+
+is($doc->title, 'A', 'Title');
+is($doc->pub_place, 'URL:http://de.wikipedia.org', 'PubPlace');
+is($doc->pub_date, '20050328', 'Creation Date');
+ok(!$doc->sub_title, 'SubTitle');
+is($doc->author, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author');
+
+ok(!$doc->doc_title, 'Correct Doc title');
+ok(!$doc->doc_sub_title, 'Correct Doc Sub title');
+ok(!$doc->doc_author, 'Correct Doc author');
+ok(!$doc->doc_editor, 'Correct Doc editor');
+
+ok(!$doc->corpus_title, 'Correct Corpus title');
+ok(!$doc->corpus_sub_title, 'Correct Corpus Sub title');
+
+# Tokenization
+use_ok('KorAP::XML::Tokenizer');
+
+my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/);
+
+# Get tokenization
+my $tokens = KorAP::XML::Tokenizer->new(
+ path => $doc->path,
+ doc => $doc,
+ foundry => $token_base_foundry,
+ layer => $token_base_layer,
+ name => 'tokens'
+);
+ok($tokens, 'Token Object is fine');
+ok($tokens->parse, 'Token parsing is fine');
+
+my $output = $tokens->to_data;
+
+is(substr($output->{data}->{text}, 0, 100), 'A bzw. a ist der erste Buchstabe des lateinischen Alphabets und ein Vokal. Der Buchstabe A hat in de', 'Primary Data');
+is($output->{data}->{name}, 'tokens', 'tokenName');
+is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource');
+
+is($output->{version}, '0.03', 'version');
+is($output->{data}->{foundries}, '', 'Foundries');
+is($output->{data}->{layerInfos}, '', 'layerInfos');
+is($output->{data}->{stream}->[0]->[4], 's:A', 'data');
+
+$tokens->add('Mate', 'Dependency');
+
+my $stream = $tokens->to_data->{data}->{stream};
+
+is($stream->[77]->[0], '<:mate/d:--$<b>34<i>78<i>78<s>1<s>1', 'element to term');
+is($stream->[77]->[1], '<>:mate/d:&&&$<b>64<i>498<i>499<i>78<b>0<s>1', 'element to term');
+is($stream->[78]->[0], '>:mate/d:--$<b>33<i>77<i>78<s>1<s>1', 'term to element');
+is($stream->[78]->[3], 'mate/d:&&&$<b>128<s>1', 'Node');
+
+
+done_testing;
+__END__
+
+
+
+