Class MascIdentifiers

java.lang.Object
opennlp.tools.formats.masc.MascIdentifiers

final class MascIdentifiers extends Object
Parses MASC identifier and anchor attributes; lists are separated by XML whitespace.
  • Field Details

    • NAMED_ENTITY_ID_PREFIX

      static final String NAMED_ENTITY_ID_PREFIX
      The prefix of a named entity node identifier, as in ne-n7.
      See Also:
    • PENN_TOKEN_ID_PREFIX

      static final String PENN_TOKEN_ID_PREFIX
      The prefix of a Penn token node identifier, as in penn-n7.
      See Also:
    • REGION_ID_PREFIX

      static final String REGION_ID_PREFIX
      The prefix of a segmentation region identifier, as in seg-r7.
      See Also:
    • XML_WHITESPACE

      private static final char[] XML_WHITESPACE
      The characters of XML whitespace.
  • Constructor Details

    • MascIdentifiers

      private MascIdentifiers()
  • Method Details

    • parseId

      static int parseId(String id, String prefix)
      Parses the number of an identifier that starts with prefix and continues with one or more ASCII digits only.
      Parameters:
      id - The identifier, such as penn-n7.
      prefix - The expected prefix, such as PENN_TOKEN_ID_PREFIX.
      Returns:
      The number after the prefix.
      Throws:
      IllegalArgumentException - Thrown if id is null, does not start with prefix, is not followed by digits only, or the number does not fit an int.
    • invalidId

      private static IllegalArgumentException invalidId(String id, String prefix, Throwable cause)
      Describes an identifier that is not prefix followed by ASCII digits.
      Parameters:
      id - The rejected identifier.
      prefix - The expected prefix.
      cause - The underlying error, or null.
      Returns:
      The exception to throw.
    • parseIds

      static int[] parseIds(String ids, String prefix)
      Parses an XML whitespace separated list of identifiers as parseId(String, String) does.
      Parameters:
      ids - The identifiers, such as seg-r1 seg-r2.
      prefix - The expected prefix of each identifier.
      Returns:
      The numbers in order.
      Throws:
      IllegalArgumentException - Thrown if ids is null, names no identifier, or contains one that parseId(String, String) rejects.
    • parseAnchors

      static Span parseAnchors(String anchors)
      Parses the two ordered, nonnegative offsets of a contiguous text region, each written in ASCII digits only, as parseId(String, String) reads an identifier number.
      Parameters:
      anchors - The XML whitespace separated offsets.
      Returns:
      The region span.
      Throws:
      IllegalArgumentException - Thrown if the anchors are missing, not two, not ASCII digits, too large for an int, or reversed.
    • parseAsciiInt

      private static int parseAsciiInt(String text, int from)
      Parses the ASCII digits from from to the end of text as a nonnegative int. A sign and digits of other scripts are not accepted.
      Parameters:
      text - The text holding the digits.
      from - The index of the first digit.
      Returns:
      The number.
      Throws:
      IllegalArgumentException - Thrown if there is no digit at from or the digits do not reach the end of text.
      NumberFormatException - Thrown if the number does not fit an int.