Class BundledUnicodeData
java.lang.Object
opennlp.tools.util.normalizer.BundledUnicodeData
Loads the line-based data files bundled with OpenNLP, such as the Unicode Character Database
extracts and the project-authored emoji tables.
A load failure surfaces from every accessor call that triggers a load: an
IllegalStateException for a missing resource, an UncheckedIOException for a
resource that cannot be read, and the parser's IllegalArgumentException for malformed
data. A BundledUnicodeData.Lazy holder does not cache a failed load, so a later call tries again.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classHolds data that is loaded on the first call toBundledUnicodeData.Lazy.get().static interfaceReceives one line of a data file.static interfaceParses a bundled data stream. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidforEachContentLine(InputStream in, BundledUnicodeData.LineConsumer consumer) Reads the content lines of a UTF-8 data file in the Unicode Character Database layout and closes the stream.static voidforEachLine(InputStream in, Charset charset, BundledUnicodeData.LineConsumer consumer) Reads every line ofinand closes it.static <T> Tload(Class<?> owner, String resource, String description, BundledUnicodeData.Parser<T> parser) Opens a resource next toownerand parses it.
-
Method Details
-
load
public static <T> T load(Class<?> owner, String resource, String description, BundledUnicodeData.Parser<T> parser) Opens a resource next toownerand parses it.- Type Parameters:
T- The type of the parsed data.- Parameters:
owner- The class the resource name is resolved against. Must not benull.resource- The resource name. Must not benull.description- The kind of data, used in error messages, for example"Word_Break". Must not benull.parser- Parses the opened stream. Must not benull.- Returns:
- The parsed data.
- Throws:
IllegalArgumentException- Thrown if an argument isnull, or rethrown fromparserfor malformed data.IllegalStateException- Thrown if the resource is missing.UncheckedIOException- Thrown if the resource cannot be read.
-
forEachLine
public static void forEachLine(InputStream in, Charset charset, BundledUnicodeData.LineConsumer consumer) throws IOException Reads every line ofinand closes it.- Parameters:
in- The stream to read. Must not benull.charset- The encoding ofin. Must not benull.consumer- Receives each line with its number. Must not benull.- Throws:
IOException- Thrown if readinginfails.IllegalArgumentException- Thrown if an argument isnull.
-
forEachContentLine
public static void forEachContentLine(InputStream in, BundledUnicodeData.LineConsumer consumer) throws IOException Reads the content lines of a UTF-8 data file in the Unicode Character Database layout and closes the stream. Each line is passed without its#comment and surrounding whitespace; lines that are empty after that are skipped but still counted.- Parameters:
in- The stream to read. Must not benull.consumer- Receives each non-empty content line with its number. Must not benull.- Throws:
IOException- Thrown if readinginfails.IllegalArgumentException- Thrown if an argument isnull.
-