Package opennlp.tools.formats.leipzig
Class LeipzigLanguageSampleStream
java.lang.Object
opennlp.tools.formats.leipzig.LeipzigLanguageSampleStream
- All Implemented Interfaces:
AutoCloseable,ObjectStream<LanguageSample>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe number of leading file name characters that form the ISO 639-3 language code.private final Randomprivate ObjectStream<LanguageSample> private final File[]private final int -
Constructor Summary
ConstructorsConstructorDescriptionLeipzigLanguageSampleStream(File leipzigFolder, int sentencesPerSample, int samplesPerLanguage) Initializes aLeipzigLanguageSampleStream. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanhasLanguageCodePrefix(String fileName) Tests whether the first 3 characters of a file name are ASCII lower case letters,atoz, as the language code of a Leipzig file is.read()Returns the nextObjectStreamobject.voidreset()Repositions the stream at the beginning and the previously seen object sequence will be repeated exactly.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface opennlp.tools.util.ObjectStream
close
-
Field Details
-
LANG_CODE_LENGTH
private static final int LANG_CODE_LENGTHThe number of leading file name characters that form the ISO 639-3 language code.- See Also:
-
sentencesPerSample
private final int sentencesPerSample -
langSampleCounts
-
sentencesFiles
-
sentencesFilesIt
-
sampleStream
-
random
-
-
Constructor Details
-
LeipzigLanguageSampleStream
public LeipzigLanguageSampleStream(File leipzigFolder, int sentencesPerSample, int samplesPerLanguage) throws IOException Initializes aLeipzigLanguageSampleStream.- Parameters:
leipzigFolder- Thedirectorywhich contains files to process.sentencesPerSample- The number of sentences per sample.samplesPerLanguage- The number of samples per language to process at maximum.- Throws:
IOException- Thrown if IO errors occurred.
-
-
Method Details
-
hasLanguageCodePrefix
Tests whether the first 3 characters of a file name are ASCII lower case letters,atoz, as the language code of a Leipzig file is.- Parameters:
fileName- The file name. Must not benull.- Returns:
trueif the file name starts with a language code.
-
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<LanguageSample>- Returns:
- The next object or
nullto signal that the stream is exhausted. - Throws:
IOException- Thrown if there is an error during reading.
-
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<LanguageSample>- Throws:
IOException- Thrown if there is an error during resetting the stream.
-