@Test public void process() throws UIMAException, IOException { final CollectionReader reader = createReader( createReaderDescription(TextReader.class, TextReader.PARAM_SOURCE_LOCATION, "src/test/resources/keyphrase/evaluator", TextReader.PARAM_PATTERNS, TextReader.INCLUDE_PREFIX + "*.txt", TextReader.PARAM_LANGUAGE, "en")); final AnalysisEngine analysisEngine = createEngine(createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class), AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class), createEngineDescription(CandidateAnnotator.class, CandidateAnnotator.PARAM_FEATURE_PATH, N.class.getName(), CandidateAnnotator.PARAM_RESOLVE_OVERLAPS, false), createEngineDescription(TfRanking.class), createEngineDescription(KeyphraseWriter.class, KeyphraseWriter.PARAM_SHOULD_WRITE_DOCUMENT, false, KeyphraseWriter.PARAM_WRITE_TO_FILE, false))); final StringBuilder actual = new StringBuilder(); final StringBuilderOutputStream fout = new StringBuilderOutputStream(actual); final MultiOutputStream multiOut = new MultiOutputStream(System.out, fout); final PrintStream stdout = new PrintStream(multiOut); System.setOut(stdout); SimplePipeline.runPipeline(reader, analysisEngine); final String[] lines = actual.toString().split(LINE_SEPARATOR); actual.delete(0, actual.length()); for (int i = 1; i < lines.length; ++i) { actual.append(lines[i]); } final String expected = "text 1.0"; Assert.assertThat(actual.toString(), CoreMatchers.is(expected)); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.INFO, "Processing document: " + DocumentMetaData.get(jcas).getDocumentId()); getContext().getLogger().log(Level.INFO, "N: "+n); this.jcas = jcas; StringBuilder sb = new StringBuilder(); if (shouldWriteDocument) { DocumentMetaData metaData = DocumentMetaData.get(jcas); sb.append("----------Document------------"); sb.append(LF); sb.append(metaData.getDocumentId()); sb.append(LF); sb.append(jcas.getDocumentText()); sb.append(LF); } if(writeToFile){ file = new File(fileName+"_"+DocumentMetaData.get(jcas).getDocumentTitle()); } sb.append("----------Keyphrases------------"); sb.append(LF); List<Keyphrase> keyphrases = filterAndSortKeyphrases(); int iterateTo = Math.min(keyphrases.size(), this.n); for (int i=0; i<iterateTo; i++) { Keyphrase keyphrase = keyphrases.get(i); String line = keyphrase.getKeyphrase() + " " + keyphrase.getScore(); sb.append(line); sb.append(LF); if(writeToFile){ try { FileUtils.writeStringToFile(file, line+LF, "UTF-8",true); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } getContext().getLogger().setOutputStream(System.out); getContext().getLogger().log(Level.INFO, sb.toString()); }
KeyphraseWriter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.INFO, "Processing document: " + DocumentMetaData.get(jcas).getDocumentId()); getContext().getLogger().log(Level.INFO, "N: "+n); this.jcas = jcas; StringBuilder sb = new StringBuilder(); if (shouldWriteDocument) { DocumentMetaData metaData = DocumentMetaData.get(jcas); sb.append("----------Document------------"); sb.append(LF); sb.append(metaData.getDocumentId()); sb.append(LF); sb.append(jcas.getDocumentText()); sb.append(LF); } if(writeToFile){ file = new File(fileName+"_"+DocumentMetaData.get(jcas).getDocumentTitle()); } sb.append("----------Keyphrases------------"); sb.append(LF); List<Keyphrase> keyphrases = filterAndSortKeyphrases(); int iterateTo = Math.min(keyphrases.size(), this.n); for (int i=0; i<iterateTo; i++) { Keyphrase keyphrase = keyphrases.get(i); String line = keyphrase.getKeyphrase() + " " + keyphrase.getScore(); sb.append(line); sb.append(LF); if(writeToFile){ try { FileUtils.writeStringToFile(file, line+LF, "UTF-8",true); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } getContext().getLogger().setOutputStream(System.out); getContext().getLogger().log(Level.INFO, sb.toString()); } }
KeyphraseWriter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.INFO, "Processing document: " + DocumentMetaData.get(jcas).getDocumentId()); getContext().getLogger().log(Level.INFO, "N: "+n); this.jcas = jcas; StringBuilder sb = new StringBuilder(); if (shouldWriteDocument) { DocumentMetaData metaData = DocumentMetaData.get(jcas); sb.append("----------Document------------"); sb.append(LF); sb.append(metaData.getDocumentId()); sb.append(LF); sb.append(jcas.getDocumentText()); sb.append(LF); } if(writeToFile){ file = new File(fileName+"_"+DocumentMetaData.get(jcas).getDocumentTitle()); } sb.append("----------Keyphrases------------"); sb.append(LF); List<Keyphrase> keyphrases = filterAndSortKeyphrases(); int iterateTo = Math.min(keyphrases.size(), this.n); for (int i=0; i<iterateTo; i++) { Keyphrase keyphrase = keyphrases.get(i); String line = keyphrase.getKeyphrase() + " " + keyphrase.getScore(); sb.append(line); sb.append(LF); if(writeToFile){ try { FileUtils.writeStringToFile(file, line+LF, "UTF-8",true); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } getContext().getLogger().setOutputStream(System.out); getContext().getLogger().log(Level.INFO, sb.toString()); }  }
KeyphraseWriter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.INFO, "Processing document: " + DocumentMetaData.get(jcas).getDocumentId()); getContext().getLogger().log(Level.INFO, "N: "+n); this.jcas = jcas; StringBuilder sb = new StringBuilder(); if (shouldWriteDocument) { DocumentMetaData metaData = DocumentMetaData.get(jcas); sb.append("----------Document------------"); sb.append(LF); sb.append(metaData.getDocumentId()); sb.append(LF); sb.append(jcas.getDocumentText()); sb.append(LF); } if(writeToFile){ file = new File(fileName+"_"+DocumentMetaData.get(jcas).getDocumentTitle()); } sb.append("----------Keyphrases------------"); sb.append(LF); List<Keyphrase> keyphrases = filterAndSortKeyphrases(); int iterateTo = Math.min(keyphrases.size(), this.n); for (int i=0; i<iterateTo; i++) { Keyphrase keyphrase = keyphrases.get(i); String line = keyphrase.getKeyphrase() + " " + keyphrase.getScore(); sb.append(line); sb.append(LF); if(writeToFile){ try { FileUtils.writeStringToFile(file, line+LF, "UTF-8",true); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } getContext().getLogger().setOutputStream(System.out); getContext().getLogger().log(Level.INFO, sb.toString()); }  @Override void initialize(UimaContext context); @Override void process(JCas jcas); }
KeyphraseWriter extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.INFO, "Processing document: " + DocumentMetaData.get(jcas).getDocumentId()); getContext().getLogger().log(Level.INFO, "N: "+n); this.jcas = jcas; StringBuilder sb = new StringBuilder(); if (shouldWriteDocument) { DocumentMetaData metaData = DocumentMetaData.get(jcas); sb.append("----------Document------------"); sb.append(LF); sb.append(metaData.getDocumentId()); sb.append(LF); sb.append(jcas.getDocumentText()); sb.append(LF); } if(writeToFile){ file = new File(fileName+"_"+DocumentMetaData.get(jcas).getDocumentTitle()); } sb.append("----------Keyphrases------------"); sb.append(LF); List<Keyphrase> keyphrases = filterAndSortKeyphrases(); int iterateTo = Math.min(keyphrases.size(), this.n); for (int i=0; i<iterateTo; i++) { Keyphrase keyphrase = keyphrases.get(i); String line = keyphrase.getKeyphrase() + " " + keyphrase.getScore(); sb.append(line); sb.append(LF); if(writeToFile){ try { FileUtils.writeStringToFile(file, line+LF, "UTF-8",true); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } getContext().getLogger().setOutputStream(System.out); getContext().getLogger().log(Level.INFO, sb.toString()); }  @Override void initialize(UimaContext context); @Override void process(JCas jcas); static final String PARAM_N; static final String PARAM_LOWERCASE; static final String PARAM_REMOVE_CONTAINED; static final String PARAM_SHOULD_WRITE_DOCUMENT; static final String PARAM_WRITE_TO_FILE; static final String PARAM_FILE_NAME; }