Check annotation data in forward index
diff --git a/lib/Krawfish/Index/Forward/Annotation.pm b/lib/Krawfish/Index/Forward/Annotation.pm
index fda029e..395be52 100644
--- a/lib/Krawfish/Index/Forward/Annotation.pm
+++ b/lib/Krawfish/Index/Forward/Annotation.pm
@@ -35,6 +35,10 @@
};
+sub type {
+ $_[0]->{term}->term_type;
+};
+
sub term_id {
$_[0]->{term_id};
};
diff --git a/lib/Krawfish/Index/Forward/Doc.pm b/lib/Krawfish/Index/Forward/Doc.pm
index 85015a8..7b1eeac 100644
--- a/lib/Krawfish/Index/Forward/Doc.pm
+++ b/lib/Krawfish/Index/Forward/Doc.pm
@@ -52,11 +52,14 @@
foreach (@sorted_annotations) {
push @data, $_->foundry_id;
push @data, $_->layer_id;
+ push @data, $_->type;
push @data, $_->term_id;
push @data, [@{$_->data}];
};
- push @data, $start_marker; # Point to previous subtoken
+ push @data, 'EOA';
+
+ push @data, $start_marker -1; # Point to previous subtoken
if (DEBUG) {
print_log('fwd_doc', "Set start marker at $start_marker from " .
$data[$start_marker] . " to " . $#data);
@@ -76,6 +79,8 @@
};
};
+ push @data, 'EOF';
+
bless \@data, $class;
};
diff --git a/lib/Krawfish/Index/Forward/Pointer.pm b/lib/Krawfish/Index/Forward/Pointer.pm
index 69fbe8a..fdb2055 100644
--- a/lib/Krawfish/Index/Forward/Pointer.pm
+++ b/lib/Krawfish/Index/Forward/Pointer.pm
@@ -20,11 +20,6 @@
# ->pos # The current subtoken position
#
# ->current # The current subtoken object
-# ->preceding_data # The whitespace data before the subtoken
-# ->subterm_id # The current subterm identifier
-# ->annotations # Get all annotations as terms
-# ->annotations(foundry_id)
-# ->annotations(foundry_id, layer_id)
sub new {
@@ -112,7 +107,8 @@
$self->{current} = Krawfish::Posting::Forward->new(
term_id => $doc->[$pos++],
preceding_data => $doc->[$pos++],
- pos => $pos
+ pos => $pos,
+ stream => $doc
);
$self->{pos} = $pos;
@@ -156,4 +152,30 @@
};
+sub prev {
+ my $self = shift;
+
+ # Not initialized
+ return if !defined $self->{doc};
+ return if !defined $self->{prev};
+
+ # Get document
+ my $doc = $self->{doc};
+
+ # Get next token from data
+ $self->{pos} = $self->{prev};
+ $self->{prev} = $doc->[$self->{pos}++];
+ $self->{next} = $doc->[$self->{pos}++];
+
+ if (DEBUG) {
+ print_log('fwd_point', "Previous subtoken at " . $self->{prev});
+ print_log('fwd_point', "Next subtoken at " . $self->{next});
+ };
+
+ $self->{current} = undef;
+ return 1;
+};
+
+
+
1;
diff --git a/lib/Krawfish/Posting/Forward.pm b/lib/Krawfish/Posting/Forward.pm
index 90a7088..6848f45 100644
--- a/lib/Krawfish/Posting/Forward.pm
+++ b/lib/Krawfish/Posting/Forward.pm
@@ -2,6 +2,14 @@
use strict;
use warnings;
+# API:
+# ->preceding_data # The whitespace data before the subtoken
+# ->subterm_id # The current subterm identifier
+# ->annotations # Get all annotations as terms
+# ->annotations(
+# foundry # TODO: Think of more complex options!
+# )
+
sub new {
my $class = shift;
bless {@_}, $class;
@@ -19,6 +27,31 @@
$_[0]->{preceding_data} // '';
};
+sub pos {
+ $_[0]->{pos};
+};
+
+sub stream {
+ $_[0]->{stream};
+};
+
+
+sub annotations {
+ my $self = shift;
+
+ my @anno = ();
+
+ my $list = $self->stream;
+ while ($list->[$self->{pos}] ne 'EOA') {
+ $self->{pos} += 3; # skip foundry_id, layer_id, type
+ my $anno_id = $list->[$self->{pos}++];
+ my $data = $list->[$self->{pos}++];
+
+ push @anno, [$anno_id, $data];
+ };
+
+ return @anno;
+};
sub to_string {
my $str = '[' . $_[0]->doc_id . ':#' . $_[0]->term_id;
diff --git a/t/index/forward_stream.t b/t/index/forward_stream.t
index 4f6ce95..075972f 100644
--- a/t/index/forward_stream.t
+++ b/t/index/forward_stream.t
@@ -86,10 +86,16 @@
is($fwd->current->preceding_data, '-', 'Get term id');
is($index->dict->term_by_term_id(14), '*Leiter', 'Get term by term id');
+ok($fwd->prev, 'Go to first subtoken');
+is($fwd->current->term_id, 12, 'Get term id');
+is($fwd->current->term_id, 12, 'Get term id');
+is($fwd->current->preceding_data, ' ', 'Get term id');
+is($index->dict->term_by_term_id(12), '*Bau', 'Get term by term id');
+ok(my @anno = $fwd->current->annotations, 'Get annotations');
+is($anno[0]->[0], 13, 'Annotation');
+is($index->dict->term_by_term_id($anno[0]->[0]), 'akron=Bau-Leiter', 'Annotation');
-diag 'Test forward index!';
-
done_testing;
__END__