Class BioCodec

java.lang.Object
opennlp.tools.namefind.BioCodec
All Implemented Interfaces:
SequenceCodec<String>

public class BioCodec extends Object implements SequenceCodec<String>
The default SequenceCodec implementation according to the BIO scheme:
  • B: 'beginning' of a NE
  • I: 'inside', the word is inside a NE
  • O: 'outside', the word is a regular word outside a NE
See also the paper by Roth D. and Ratinov L.: Design Challenges and Misconceptions in Named Entity Recognition.
See Also:
  • Field Details

  • Constructor Details

    • BioCodec

      public BioCodec()
  • Method Details

    • extractNameType

      static String extractNameType(String outcome)
      Extracts the name type from an outcome such as person-start: the text before the last hyphen, provided a non-empty run of ASCII letters, digits, or underscores follows that hyphen and the outcome holds no line terminator.
      Parameters:
      outcome - The outcome label. Must not be null.
      Returns:
      The name type, or null if the outcome has none.
    • isWordChars

      private static boolean isWordChars(String outcome, int from)
      Tests whether the rest of an outcome is a non-empty run of ASCII letters, digits, or underscores.
      Parameters:
      outcome - The outcome label.
      from - The offset the run starts at.
      Returns:
      true if at least one character follows and all are word characters.
    • decode

      public Span[] decode(List<String> c)
      Description copied from interface: SequenceCodec
      Decodes a sequence of objects into Span objects.
      Specified by:
      decode in interface SequenceCodec<String>
      Parameters:
      c - A list of SequenceCodec to decode.
      Returns:
      A Span array encapsulating the decoded elements in c.
    • encode

      public String[] encode(Span[] names, int length)
      Description copied from interface: SequenceCodec
      Encodes Span objects into a sequence of objects.
      Specified by:
      encode in interface SequenceCodec<String>
      Parameters:
      names - A list of elements to encode.
      length - The length to respect.
      Returns:
      An array of SequenceCodec to encode.
    • createSequenceValidator

      public NameFinderSequenceValidator createSequenceValidator()
      Specified by:
      createSequenceValidator in interface SequenceCodec<String>
      Returns:
      A SequenceValidator which can validate a sequence of outcomes.
    • areOutcomesCompatible

      public boolean areOutcomesCompatible(String[] outcomes)
      Description copied from interface: SequenceCodec
      Checks if the outcomes of a model are compatible with this SequenceCodec.
      Specified by:
      areOutcomesCompatible in interface SequenceCodec<String>
      Parameters:
      outcomes - The possible model outcomes.
      Returns:
      true if outcomes are type compatible, false otherwise.