Package opennlp.tools.formats.conllu
Class ConlluStream
java.lang.Object
opennlp.tools.formats.conllu.ConlluStream
- All Implemented Interfaces:
AutoCloseable,ObjectStream<ConlluSentence>
The CoNNL-U Format is specified
here.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordThe token range a multiword token line covers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final intprivate static final intprivate static final charprivate final ObjectStream<String> private static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes theObjectStreamand releases all allocated resources.private StringextractTextLang(String firstPart) Returns the two or three lowercase ASCII letters aftertext_, or an empty string.private ConlluWordLinemergeAnnotation(ConlluWordLine contraction, List<ConlluWordLine> expandedParts) Merges token level annotations.(package private) ConlluStream.MultiwordRangeParses a multiword token id of the formstart-end, where both sides are ASCII digit runs without a leading zero and the range does not run backwards.private List<ConlluWordLine> Merges the word lines of each multiword token range into the range line and removes them.read()Returns the nextObjectStreamobject.voidreset()Repositions the stream at the beginning and the previously seen object sequence will be repeated exactly.
-
Field Details
-
TEXT_LANG_PREFIX
- See Also:
-
LANG_CODE_MIN_LENGTH
private static final int LANG_CODE_MIN_LENGTH- See Also:
-
LANG_CODE_MAX_LENGTH
private static final int LANG_CODE_MAX_LENGTH- See Also:
-
MULTIWORD_SEPARATOR
private static final char MULTIWORD_SEPARATOR- See Also:
-
INVALID_MULTIWORD_ID
- See Also:
-
BACKWARDS_MULTIWORD_ID
- See Also:
-
sentenceStream
-
-
Constructor Details
-
ConlluStream
Initializes aConlluStream.- Parameters:
in- TheInputStreamFactoryto use. Characters will be interpreted in UTF-8.- Throws:
IOException- Thrown if IO errors occurred during initialization.
-
-
Method Details
-
read
Description copied from interface:ObjectStreamReturns the nextObjectStreamobject. Calling this method repeatedly until it returnsnullwill return each object from the underlying source exactly once.- Specified by:
readin interfaceObjectStream<ConlluSentence>- Returns:
- The next object or
nullto signal that the stream is exhausted. - Throws:
IOException- Thrown if there is an error during reading.
-
postProcessContractions
private List<ConlluWordLine> postProcessContractions(List<ConlluWordLine> lines) throws InvalidFormatException Merges the word lines of each multiword token range into the range line and removes them.- Parameters:
lines- The word lines of one sentence.- Returns:
- The lines with each range merged.
- Throws:
InvalidFormatException- Thrown if a multiword token id is malformed, or a range names a word id that has no line.
-
mergeAnnotation
private ConlluWordLine mergeAnnotation(ConlluWordLine contraction, List<ConlluWordLine> expandedParts) Merges token level annotations.- Parameters:
contraction- The line that receives the annotation.expandedParts- The lines to get annotation.- Returns:
- The
merged line.
-
addTextLang
private Map<Locale,String> addTextLang(String firstPart, String secondPart, Map<Locale, String> textLang) throws InvalidFormatException- Throws:
InvalidFormatException
-
parseContractionRange
Parses a multiword token id of the formstart-end, where both sides are ASCII digit runs without a leading zero and the range does not run backwards.- Parameters:
id- The token id, which holds a hyphen.- Returns:
- The range.
- Throws:
InvalidFormatException- If the id is not two such digit runs joined by one hyphen, if a side does not fit an int, or if the end is less than the start.
-
extractTextLang
Returns the two or three lowercase ASCII letters aftertext_, or an empty string. Three letters are taken when three follow; the firsttext_with at least two letters after it counts.- Parameters:
firstPart- The comment key.- Returns:
- The language code, or an empty string if there is none.
-
close
Description copied from interface:ObjectStreamCloses theObjectStreamand releases all allocated resources. After close was called, it's not allowed to callObjectStream.read()orObjectStream.reset().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceObjectStream<ConlluSentence>- Throws:
IOException- Thrown if there is an error during closing the stream.
-
reset
Description copied from interface:ObjectStreamRepositions the stream at the beginning and the previously seen object sequence will be repeated exactly. This method can be used to re-read the stream if multiple passes over the objects are required.The implementation of this method is optional.
- Specified by:
resetin interfaceObjectStream<ConlluSentence>- Throws:
IOException- Thrown if there is an error during resetting the stream.UnsupportedOperationException- Thrown if thereset()is not supported. By default, this is the case.
-