Class Annotator<F,T extends Comparable<T>>

java.lang.Object
org.coordinatekit.crf.annotator.Annotator<F,T>
Type Parameters:
F - the feature type carried by the tagger and the per-token entries
T - the tag type

@NullMarked public final class Annotator<F,T extends Comparable<T>> extends Object
Orchestrates an interactive annotation session over an input file of one-sequence-per-line text.

Each non-blank input line is tokenized and presented through the configured TaggingInterface. When the user accepts a sequence, the resulting tokens, tags, and the excluded character runs the tokenizer dropped around them are appended to the output XML file as a <crf:Sequence> element and flushed immediately, so a crash leaves a valid (or recoverable) document with every confirmed sequence intact. The captured excluded runs make the written sequence losslessly reconstructable: TrainingSequence.surface() reproduces the original line exactly. Re-running against the same output file skips any input line whose tokenization matches one already present in the output, compared by a 64-bit content fingerprint of the token list (content-match resume).

When a CrfTagger is configured it is the authoritative source of tokens and excluded runs. Each line is tagged once, the tagger's tokenization is used as written, and its suggested tags are always shown. When no tagger is configured the Tokenizer splits each line instead and the user tags every token starting from TagProvider.startingTag(). At least one of the two must be present.

The "Sequence N of M" counters reported through AnnotatorSequence use a stable denominator: M is the total number of non-blank input lines, including lines already present in the output (so "of M" does not drift between sessions). N is the position of the shown sequence within that input — the number of lines auto-skipped so far plus the number presented so far — so resuming after 50 skipped lines shows the next sequence as "51 of M".

Instances are constructed via the nested Annotator.Builder.

See Also:
  • Method Details

    • builder

      public static <F, T extends Comparable<T>> Annotator.Builder<F,T> builder()
      Returns a new builder for Annotator.
      Type Parameters:
      F - the feature type carried by the tagger and the per-token entries
      T - the tag type
      Returns:
      a new builder with no values set
    • annotate

      public void annotate(Path inputFile, Path outputFile) throws IOException
      Annotates the input file, appending accepted sequences to the output file.

      Walks inputFile line-by-line, skipping blank lines and any line whose token list is already present in outputFile. Each remaining line is tokenized by the configured Tokenizer, built into an AnnotatorSequence, and presented via the configured TaggingInterface. On ACCEPT the tokens, the user-chosen tags, and the tokenizer's excluded runs are written and flushed to the output file. On SKIP the line is left unwritten and will be re-presented on the next run. On EXIT the writer is closed and this method returns.

      A one-line "Resumed: skipped K of N input lines already present in output." message is written to the configured Terminal once per call — either immediately before the first presentation, or after the input is exhausted if no presentation occurred.

      Parameters:
      inputFile - the file to read input lines from, UTF-8 encoded, one sequence per line
      outputFile - the XML training-data file to append accepted sequences to
      Throws:
      IOException - if reading the input, reading the existing output, or writing the output fails