@Test public void testReader() throws Exception { CollectionReader reader = CollectionReaderFactory.createReader(FolderwiseDataReader.class, FolderwiseDataReader.PARAM_SOURCE_LOCATION, "src/test/resources/folderwise", FolderwiseDataReader.PARAM_PATTERNS, "*.txt"); List<String> readDocuments = new ArrayList<>(); List<String> readOutcomes = new ArrayList<>(); while (reader.hasNext()) { JCas emptyCas = JCasFactory.createJCas(); reader.getNext(emptyCas.getCas()); readDocuments.add(JCasUtil.selectSingle(emptyCas, TextClassificationTarget.class) .getCoveredText()); readOutcomes.add( JCasUtil.selectSingle(emptyCas, TextClassificationOutcome.class).getOutcome()); } assertEquals(5, readDocuments.size()); assertEquals("This is a really odd test tweet :-) #test #nonsense", readDocuments.get(0)); assertEquals("it's raining all day and i don't care", readDocuments.get(1)); assertEquals("This is another really odd test tweet :-) #moreTests #randomness", readDocuments.get(2)); assertEquals("dkpro tc is a wonderful tool to classify tweets #LoveIt #MachineLearning", readDocuments.get(3)); assertEquals("Not even close to Friday :( #IHateMonday", readDocuments.get(4)); assertEquals(5, readOutcomes.size()); assertEquals("neutral", readOutcomes.get(0)); assertEquals("neutral", readOutcomes.get(1)); assertEquals("neutral", readOutcomes.get(2)); assertEquals("emotional", readOutcomes.get(3)); assertEquals("emotional", readOutcomes.get(4)); }
@Override public void getNext(JCas aJCas) throws IOException, CollectionException { Resource currentFile = nextFile(); DocumentMetaData metaData = new DocumentMetaData(aJCas); metaData.setDocumentTitle(currentFile.getResource().getFile().getName()); metaData.setDocumentId(currentFile.getResource().getFile().getName()); metaData.addToIndexes(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(currentFile.getInputStream(), "utf-8"))) { StringBuilder buffer = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } String text = buffer.toString().trim(); text = performAdditionalTextOperation(text); setTextClassificationTarget(aJCas, currentFile, 0, text.length()); setTextClassificationOutcome(aJCas, currentFile, 0, text.length()); aJCas.setDocumentText(text.trim()); } }
FolderwiseDataReader extends JCasResourceCollectionReader_ImplBase { @Override public void getNext(JCas aJCas) throws IOException, CollectionException { Resource currentFile = nextFile(); DocumentMetaData metaData = new DocumentMetaData(aJCas); metaData.setDocumentTitle(currentFile.getResource().getFile().getName()); metaData.setDocumentId(currentFile.getResource().getFile().getName()); metaData.addToIndexes(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(currentFile.getInputStream(), "utf-8"))) { StringBuilder buffer = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } String text = buffer.toString().trim(); text = performAdditionalTextOperation(text); setTextClassificationTarget(aJCas, currentFile, 0, text.length()); setTextClassificationOutcome(aJCas, currentFile, 0, text.length()); aJCas.setDocumentText(text.trim()); } } }
FolderwiseDataReader extends JCasResourceCollectionReader_ImplBase { @Override public void getNext(JCas aJCas) throws IOException, CollectionException { Resource currentFile = nextFile(); DocumentMetaData metaData = new DocumentMetaData(aJCas); metaData.setDocumentTitle(currentFile.getResource().getFile().getName()); metaData.setDocumentId(currentFile.getResource().getFile().getName()); metaData.addToIndexes(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(currentFile.getInputStream(), "utf-8"))) { StringBuilder buffer = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } String text = buffer.toString().trim(); text = performAdditionalTextOperation(text); setTextClassificationTarget(aJCas, currentFile, 0, text.length()); setTextClassificationOutcome(aJCas, currentFile, 0, text.length()); aJCas.setDocumentText(text.trim()); } }  }
FolderwiseDataReader extends JCasResourceCollectionReader_ImplBase { @Override public void getNext(JCas aJCas) throws IOException, CollectionException { Resource currentFile = nextFile(); DocumentMetaData metaData = new DocumentMetaData(aJCas); metaData.setDocumentTitle(currentFile.getResource().getFile().getName()); metaData.setDocumentId(currentFile.getResource().getFile().getName()); metaData.addToIndexes(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(currentFile.getInputStream(), "utf-8"))) { StringBuilder buffer = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } String text = buffer.toString().trim(); text = performAdditionalTextOperation(text); setTextClassificationTarget(aJCas, currentFile, 0, text.length()); setTextClassificationOutcome(aJCas, currentFile, 0, text.length()); aJCas.setDocumentText(text.trim()); } }  @Override void getNext(JCas aJCas); }
FolderwiseDataReader extends JCasResourceCollectionReader_ImplBase { @Override public void getNext(JCas aJCas) throws IOException, CollectionException { Resource currentFile = nextFile(); DocumentMetaData metaData = new DocumentMetaData(aJCas); metaData.setDocumentTitle(currentFile.getResource().getFile().getName()); metaData.setDocumentId(currentFile.getResource().getFile().getName()); metaData.addToIndexes(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(currentFile.getInputStream(), "utf-8"))) { StringBuilder buffer = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } String text = buffer.toString().trim(); text = performAdditionalTextOperation(text); setTextClassificationTarget(aJCas, currentFile, 0, text.length()); setTextClassificationOutcome(aJCas, currentFile, 0, text.length()); aJCas.setDocumentText(text.trim()); } }  @Override void getNext(JCas aJCas); static final String PARAM_ANNOTATE_TC_BACKEND_ANNOTATIONS; }