Remove MultiTerm->add() in favor of MultiTerm->add_by_term()

Change-Id: I1df0ed2a545ded204bafad7ca01bec0ce54a94fc
diff --git a/lib/KorAP/XML/Index/MultiTerm.pm b/lib/KorAP/XML/Index/MultiTerm.pm
index 0111bee..db75a38 100644
--- a/lib/KorAP/XML/Index/MultiTerm.pm
+++ b/lib/KorAP/XML/Index/MultiTerm.pm
@@ -18,51 +18,12 @@
   PAYLOAD        => 8,
 };
 
+
+# Construct a multiterm object by passing a term
 sub new {
-  my $self = bless [], shift;
-
-  # TODO:
-  #   Deprecate!
-  for (my $i = 0; $i < scalar @_; $i+=2) {
-    if ($_[$i] eq 'term') {
-      $self->[TERM] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'p_start') {
-      $self->[P_START] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'p_end') {
-      $self->[P_END] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'payload') {
-      $self->[PAYLOAD] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'store_offsets') {
-      $self->store_offsets($_[$i+1]);
-    }
-    elsif ($_[$i] eq 'o_start') {
-      $self->[O_START] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'o_end') {
-      $self->[O_END] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'pti') {
-      $self->[PTI] = $_[$i+1];
-    }
-    elsif ($_[$i] eq 'tui') {
-      $self->[TUI] = $_[$i+1];
-    };
-  };
-  $self;
-};
-
-sub new_from_term {
   bless [$_[1]], $_[0];
 };
 
-sub new_blank {
-  bless [], shift;
-}
-
 sub set_payload {
   return $_[0]->[PAYLOAD] = $_[1];
 };
diff --git a/lib/KorAP/XML/Index/MultiTermToken.pm b/lib/KorAP/XML/Index/MultiTermToken.pm
index a8085d5..35f7d7a 100644
--- a/lib/KorAP/XML/Index/MultiTermToken.pm
+++ b/lib/KorAP/XML/Index/MultiTermToken.pm
@@ -21,29 +21,8 @@
   bless [[]], shift;
 };
 
-
-sub add {
-  my $self = shift;
-
-  my $mt;
-  unless (blessed $_[0]) {
-    if (@_ == 1) {
-      $mt = KorAP::XML::Index::MultiTerm->new_blank;
-      $mt->set_term($_[0]);
-    }
-    else {
-      $mt = KorAP::XML::Index::MultiTerm->new(@_);
-    };
-  }
-  else {
-    $mt = $_[0];
-  };
-  push(@{$self->[MT]}, $mt);
-  $mt;
-};
-
 sub add_by_term {
-  my $mt = KorAP::XML::Index::MultiTerm->new_from_term($_[1]);
+  my $mt = KorAP::XML::Index::MultiTerm->new($_[1]);
   push(@{$_[0]->[MT]}, $mt);
   $mt;
 };
diff --git a/lib/KorAP/XML/Index/MultiTermTokenStream.pm b/lib/KorAP/XML/Index/MultiTermTokenStream.pm
index 0ec97c7..c34b63d 100644
--- a/lib/KorAP/XML/Index/MultiTermTokenStream.pm
+++ b/lib/KorAP/XML/Index/MultiTermTokenStream.pm
@@ -49,24 +49,22 @@
 
     my $tui = $self->tui($unit->get_p_start);
 
-    return $mtt->add(
-      term => '<>:' . $term,
-      o_start => $unit->get_o_start,
-      o_end   => $unit->get_o_end,
-      p_start => $unit->get_p_start,
-      p_end   => $unit->get_p_end,
-      pti => 64,
-      payload => '<b>0<s>' . $tui,
-      tui => $tui
-    );
-
+    my $mt = $mtt->add_by_term('<>:' . $term);
+    $mt->set_o_start($unit->get_o_start);
+    $mt->set_o_end($unit->get_o_end);
+    $mt->set_p_start($unit->get_p_start);
+    $mt->set_p_end($unit->get_p_end);
+    $mt->set_pti(64);
+    $mt->set_payload('<b>0<s>' . $tui);
+    $mt->set_tui($tui);
+    return $mt;
   };
 };
 
 sub add_meta {
   my $self = shift;
   my $pos_0 = $self->pos(0) or return;
-  my $mt = $pos_0->add('-:' . shift);
+  my $mt = $pos_0->add_by_term('-:' . shift);
   $mt->set_payload(shift);
   $mt->set_stored_offsets(0);
 };
diff --git a/lib/KorAP/XML/Tokenizer.pm b/lib/KorAP/XML/Tokenizer.pm
index ad38f20..6b5176a 100644
--- a/lib/KorAP/XML/Tokenizer.pm
+++ b/lib/KorAP/XML/Tokenizer.pm
@@ -236,6 +236,8 @@
   my $self = shift;
   my $mtts = $self->stream or return;
 
+  my $mt;
+
   foreach my $mtt (@{$mtts->multi_term_tokens}) {
     my $o_start = $mtt->o_start;
     my $o_end = $mtt->o_end;
@@ -254,29 +256,23 @@
     while ($s =~ /(a+)[^a]/g) {
       my $from = $-[1];
       my $to = $+[1];
-      $mtt->add(
-        term => 'i^1:' . substr($os, $from, $from + $to),
-        o_start => $from + $o_start,
-        o_end => $to + $o_start
-      ) unless $to - $from == $l;
+      $mt = $mtt->add_by_term('i^1:' . substr($os, $from, $from + $to));
+      $mt->set_o_start($from + $o_start);
+      $mt->set_o_end($to + $o_start) unless $to - $from == $l;
     };
     while ($s =~ /(0+)[^0]/g) {
       my $from = $-[1];
       my $to = $+[1];
-      $mtt->add(
-        term => 'i^2:' . substr($os, $from, $from + $to),
-        o_start => $from + $o_start,
-        o_end => $to + $o_start
-      ) unless $to - $from == $l;
+      $mt = $mtt->add_by_term('i^2:' . substr($os, $from, $from + $to));
+      $mt->set_o_start($from + $o_start);
+      $mt->set_o_end($to + $o_start) unless $to - $from == $l;
     };
     while ($s =~ /(#)/g) {
       my $from = $-[1];
       my $to = $+[1];
-      $mtt->add(
-        term => 'i^3:' . substr($os, $from, $from + $to),
-        o_start => $from + $o_start,
-        o_end => $to + $o_start
-      ) unless $to - $from == $l;
+      $mt = $mtt->add_by_term('i^3:' . substr($os, $from, $from + $to));
+      $mt->set_o_start($from + $o_start);
+      $mt->set_o_end($to + $o_start) unless $to - $from == $l;
     };
   };
 
@@ -770,12 +766,10 @@
     cb => sub {
       my ($stream, $span) = @_;
       my $mtt = $stream->pos($span->get_p_start);
-      $mtt->add(
-        term    => '<>:s',
-        o_start => $span->get_o_start,
-        o_end   => $span->get_o_end,
-        p_end   => $span->get_p_end
-      );
+      my $mt = $mtt->add_by_term('<>:s');
+      $mt->set_o_start($span->get_o_start);
+      $mt->set_o_end($span->get_o_end);
+      $mt->set_p_end($span->get_p_end);
     }
   );
 
@@ -803,9 +797,7 @@
 
       # syntax
       if ((my $found = $content->at('f[name="pos"]')) && ($found = $found->text)) {
-        $mtt->add(
-          term => 'cnx_syn:' . $found
-        );
+        $mtt->add_by_term('cnx_syn:' . $found);
       };
     });