Class MascDocumentStream
java.lang.Object
opennlp.tools.formats.masc.MascDocumentStream
- All Implemented Interfaces:
AutoCloseable, ObjectStream<MascDocument>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA helper class to parse the header (.hdr) files. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Iterator<MascDocument> private final List<MascDocument> private static final org.slf4j.Loggerprivate final SAXParser -
Constructor Summary
ConstructorsConstructorDescriptionMascDocumentStream(File mascCorpusDirectory) MascDocumentStream(File mascCorpusDirectory, boolean searchRecursive, FileFilter fileFilter) Creates a MascDocumentStream to read the documents from a given directory. -
Method Summary
Modifier and TypeMethodDescriptioncheckAnnotations(String path) Check that all annotation files mentioned in the header are presentvoidclose()Remove the corpus from the memory.read()Return the next document.voidreset()Reset the reading of all documents to the first sentence.
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
documents
-
documentIterator
-
saxParser
-
-
Constructor Details
-
MascDocumentStream
- Throws:
IOException
-
MascDocumentStream
public MascDocumentStream(File mascCorpusDirectory, boolean searchRecursive, FileFilter fileFilter) throws IOException Creates a MascDocumentStream to read the documents from a given directory. Works iff all annotation files mentioned in the headers are present.- Parameters:
mascCorpusDirectory- the directory containing all the MASC filessearchRecursive- whether the search should go through subdirectoriesfileFilter- a custom file filter to filter out some files or null to accept anything- Throws:
IOException- if any stage of the stream creation fails
-
-
Method Details
-
checkAnnotations
Check that all annotation files mentioned in the header are present- Parameters:
path- The path to header- Throws:
IOException- If corpus integrity is violated
-
reset
public void reset()Reset the reading of all documents to the first sentence. Reset the corpus to the first document.- Specified by:
resetin interfaceObjectStream<MascDocument>
-
read
Return the next document. Client needs to check if this document has the necessary annotations.- Specified by:
readin interfaceObjectStream<MascDocument>- Returns:
- A corpus document with all its annotations.
- Throws:
IOException- if anything goes wrong.
-
close
public void close()Remove the corpus from the memory.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceObjectStream<MascDocument>
-