Example Collection Reader - apache/ctakes GitHub Wiki
Example Collection Reader
// Extend AbstractFileTreeReader, which does a lot of work for you.classExampleReaderextendsAbstractFileTreeReader {
// Only one method needs to be implemented.protectedvoidreadFile( JCasjCas, Filefile ) throwsIOException {
// Read the file, building a document using only lines preceded by "Text:".StringdocumentText;
try ( Stream<String> textStream = Files.lines( file.toPath() ) ) {
documentText = textStream.filter( line -> line.startsWith( "Text:" ) )
.map( line -> line.substring( 5 ).trim() )
.collect( Collectors.joining( "\n" ) );
}
// JCasBuilder can attempt to create document metadata based upon the file.getJCasBuilder( file ).setDocText( documentText )
.populate( jCas );
}
}