@Test public final void test() throws ResourceInitializationException, AnalysisEngineProcessException { final String testDocument = "This is a not so long test sentence. This is a longer second " + "test sentence. More sentences are necessary for the tests."; final AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(de.tudarmstadt.ukp.dkpro.core.tokit.BreakIteratorSegmenter.class), AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class, StanfordPosTagger.PARAM_LANGUAGE, "en"), AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class), createEngineDescription(PosFilter.class, PosFilter.PARAM_TYPE_TO_REMOVE, Lemma.class.getName(), PosFilter.PARAM_ADJ, true, PosFilter.PARAM_N, true), CooccurrenceGraphFactory.getCooccurrenceGraph_lemma(), NodeDegreeRankingFactory.getNodeDegreeRanking_weighted()); final AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); final JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); final String[] expectedArray = new String[] { "More", "second", "test", "sentence", "necessary", "long" }; final Set<String> expectedKeyphr = new HashSet<String>(); for (String string : expectedArray) { expectedKeyphr.add(string); } final Set<String> resultKeyphr = new HashSet<String>(); final Map<String, Double> map = new HashMap<String, Double>(); for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { resultKeyphr.add(keyphrase.getCoveredText()); map.put(keyphrase.getCoveredText(), keyphrase.getScore()); } Assert.assertThat(resultKeyphr, CoreMatchers.is(expectedKeyphr)); final ValueComparator valueComparator = new ValueComparator(map); final TreeMap<String, Double> sortedMap = new TreeMap<String, Double>(valueComparator); sortedMap.putAll(map); final Set<String> orderedSet = sortedMap.keySet(); final String[] orderedArray = orderedSet.toArray(new String[orderedSet.size()]); Assert.assertThat(orderedArray[0], CoreMatchers.is("sentence")); Assert.assertThat(orderedArray[1], CoreMatchers.is("test")); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.CONFIG, "Entering " + this.getClass().getSimpleName()); this.jcas = jcas; initializeDataStructures(); String documentText = jcas.getDocumentText().toLowerCase(); for (String term : termMap.keySet()) { int termId = termMap.get(term); double score; if (weighted) { score = getWeightedScore(termId, scoreMap); } else { score = getUnweightedScore(termId, scoreMap); } if (!documentText.contains(term.toLowerCase())) { getContext().getLogger().log(Level.WARNING, "Document text does not contain keyphrase: " + term.toLowerCase()); continue; } int[] offset = offsetMap.get(termId); Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setScore(score); keyphrase.setBegin(offset[0]); keyphrase.setEnd(offset[1]); keyphrase.setKeyphrase(term); keyphrase.addToIndexes(); } }
NodeDegreeRanking extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.CONFIG, "Entering " + this.getClass().getSimpleName()); this.jcas = jcas; initializeDataStructures(); String documentText = jcas.getDocumentText().toLowerCase(); for (String term : termMap.keySet()) { int termId = termMap.get(term); double score; if (weighted) { score = getWeightedScore(termId, scoreMap); } else { score = getUnweightedScore(termId, scoreMap); } if (!documentText.contains(term.toLowerCase())) { getContext().getLogger().log(Level.WARNING, "Document text does not contain keyphrase: " + term.toLowerCase()); continue; } int[] offset = offsetMap.get(termId); Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setScore(score); keyphrase.setBegin(offset[0]); keyphrase.setEnd(offset[1]); keyphrase.setKeyphrase(term); keyphrase.addToIndexes(); } } }
NodeDegreeRanking extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.CONFIG, "Entering " + this.getClass().getSimpleName()); this.jcas = jcas; initializeDataStructures(); String documentText = jcas.getDocumentText().toLowerCase(); for (String term : termMap.keySet()) { int termId = termMap.get(term); double score; if (weighted) { score = getWeightedScore(termId, scoreMap); } else { score = getUnweightedScore(termId, scoreMap); } if (!documentText.contains(term.toLowerCase())) { getContext().getLogger().log(Level.WARNING, "Document text does not contain keyphrase: " + term.toLowerCase()); continue; } int[] offset = offsetMap.get(termId); Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setScore(score); keyphrase.setBegin(offset[0]); keyphrase.setEnd(offset[1]); keyphrase.setKeyphrase(term); keyphrase.addToIndexes(); } }  }
NodeDegreeRanking extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.CONFIG, "Entering " + this.getClass().getSimpleName()); this.jcas = jcas; initializeDataStructures(); String documentText = jcas.getDocumentText().toLowerCase(); for (String term : termMap.keySet()) { int termId = termMap.get(term); double score; if (weighted) { score = getWeightedScore(termId, scoreMap); } else { score = getUnweightedScore(termId, scoreMap); } if (!documentText.contains(term.toLowerCase())) { getContext().getLogger().log(Level.WARNING, "Document text does not contain keyphrase: " + term.toLowerCase()); continue; } int[] offset = offsetMap.get(termId); Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setScore(score); keyphrase.setBegin(offset[0]); keyphrase.setEnd(offset[1]); keyphrase.setKeyphrase(term); keyphrase.addToIndexes(); } }  @Override void process(JCas jcas); }
NodeDegreeRanking extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.CONFIG, "Entering " + this.getClass().getSimpleName()); this.jcas = jcas; initializeDataStructures(); String documentText = jcas.getDocumentText().toLowerCase(); for (String term : termMap.keySet()) { int termId = termMap.get(term); double score; if (weighted) { score = getWeightedScore(termId, scoreMap); } else { score = getUnweightedScore(termId, scoreMap); } if (!documentText.contains(term.toLowerCase())) { getContext().getLogger().log(Level.WARNING, "Document text does not contain keyphrase: " + term.toLowerCase()); continue; } int[] offset = offsetMap.get(termId); Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setScore(score); keyphrase.setBegin(offset[0]); keyphrase.setEnd(offset[1]); keyphrase.setKeyphrase(term); keyphrase.addToIndexes(); } }  @Override void process(JCas jcas); static final String PARAM_WEIGHTED; }