Package opennlp.tools.formats.masc
Class MascIdentifiers
java.lang.Object
opennlp.tools.formats.masc.MascIdentifiers
Parses MASC identifier and anchor attributes; lists are separated by
XML whitespace.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringThe prefix of a named entity node identifier, as inne-n7.(package private) static final StringThe prefix of a Penn token node identifier, as inpenn-n7.(package private) static final StringThe prefix of a segmentation region identifier, as inseg-r7.private static final char[]The characters of XML whitespace. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static IllegalArgumentExceptionDescribes an identifier that is notprefixfollowed by ASCII digits.(package private) static SpanparseAnchors(String anchors) Parses the two ordered, nonnegative offsets of a contiguous text region, each written in ASCII digits only, asparseId(String, String)reads an identifier number.private static intparseAsciiInt(String text, int from) Parses the ASCII digits fromfromto the end oftextas a nonnegativeint.(package private) static intParses the number of an identifier that starts withprefixand continues with one or more ASCII digits only.(package private) static int[]Parses an XML whitespace separated list of identifiers asparseId(String, String)does.
-
Field Details
-
NAMED_ENTITY_ID_PREFIX
The prefix of a named entity node identifier, as inne-n7.- See Also:
-
PENN_TOKEN_ID_PREFIX
The prefix of a Penn token node identifier, as inpenn-n7.- See Also:
-
REGION_ID_PREFIX
The prefix of a segmentation region identifier, as inseg-r7.- See Also:
-
XML_WHITESPACE
private static final char[] XML_WHITESPACEThe characters of XML whitespace.
-
-
Constructor Details
-
MascIdentifiers
private MascIdentifiers()
-
-
Method Details
-
parseId
Parses the number of an identifier that starts withprefixand continues with one or more ASCII digits only.- Parameters:
id- The identifier, such aspenn-n7.prefix- The expected prefix, such asPENN_TOKEN_ID_PREFIX.- Returns:
- The number after the prefix.
- Throws:
IllegalArgumentException- Thrown ifidisnull, does not start withprefix, is not followed by digits only, or the number does not fit anint.
-
invalidId
Describes an identifier that is notprefixfollowed by ASCII digits.- Parameters:
id- The rejected identifier.prefix- The expected prefix.cause- The underlying error, ornull.- Returns:
- The exception to throw.
-
parseIds
Parses an XML whitespace separated list of identifiers asparseId(String, String)does.- Parameters:
ids- The identifiers, such asseg-r1 seg-r2.prefix- The expected prefix of each identifier.- Returns:
- The numbers in order.
- Throws:
IllegalArgumentException- Thrown ifidsisnull, names no identifier, or contains one thatparseId(String, String)rejects.
-
parseAnchors
Parses the two ordered, nonnegative offsets of a contiguous text region, each written in ASCII digits only, asparseId(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 anint, or reversed.
-
parseAsciiInt
Parses the ASCII digits fromfromto the end oftextas a nonnegativeint. 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 atfromor the digits do not reach the end oftext.NumberFormatException- Thrown if the number does not fit anint.
-