PageRankRanking extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.CONFIG, "Entering " + this.getClass().getSimpleName()); pageRank.initializeFromAnnotationPairIterator( JCasUtil.select(jcas, AnnotationPair.class), weighted ); pageRank.run(); List<TermRank> termRanks = pageRank.getTermRanks(); getContext().getLogger().log(Level.FINE, termRanks.toString()); for (TermRank termRank : termRanks) { addKeyphrase(jcas, termRank); } }  @Override void initialize(UimaContext context); @Override void process(JCas jcas); static final String PARAM_WEIGHTED; }
@Test public void PosFilterTest() throws Exception { Map<String,Double> expectedResults = new HashMap<String,Double>(); expectedResults.put("sentence", 1.6487752080270504); expectedResults.put("second", 0.8508165279819666); expectedResults.put("long", 0.5004082639909833); expectedResults.put("more", 0.5004082639909833); expectedResults.put("necessary", 0.8508165279819666); expectedResults.put("test", 1.6487752080270504); String testDocument = "This is a not so long test sentence. This is a longer second test sentence. More sentences are necessary for the tests."; 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(), createEngineDescription(PageRankRanking.class, PageRankRanking.PARAM_WEIGHTED, false)); AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); int i=0; for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { assertTrue(keyphrase.getKeyphrase(), expectedResults.containsKey(keyphrase.getKeyphrase())); assertEquals(keyphrase.getKeyphrase(), expectedResults.get(keyphrase.getKeyphrase()), keyphrase.getScore(), EPSILON); i++; } assertEquals(10,i); }
@Test public void PosFilterWindowSizeTest() throws Exception { Map<String,Double> expectedResults = new HashMap<String,Double>(); expectedResults.put("sentence", 1.2233253524500909); expectedResults.put("second", 0.9985807508947789); expectedResults.put("long", 0.7780938966551303); expectedResults.put("necessary", 0.7780938966551303); expectedResults.put("more", 0.9985807508947789); expectedResults.put("test", 1.2233253524500909); String testDocument = "This is a not so long test sentence. This is a longer second test sentence. More sentences are necessary for the tests."; AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(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_windowSize5(), createEngineDescription(PageRankRanking.class, PageRankRanking.PARAM_WEIGHTED, false)); AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); int i=0; for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { assertTrue(keyphrase.getKeyphrase(), expectedResults.containsKey(keyphrase.getKeyphrase())); assertEquals(keyphrase.getKeyphrase(), expectedResults.get(keyphrase.getKeyphrase()), keyphrase.getScore(), EPSILON); i++; } assertEquals(8,i); }
@Test public void PosFilterTokenTest() throws Exception { Map<String,Double> expectedResults = new HashMap<String,Double>(); expectedResults.put("test", 1.389844507927117); expectedResults.put("necessary", 1.130446300811737); expectedResults.put("More", 0.9781026497450921); expectedResults.put("tests", 0.6305394317298283); expectedResults.put("long", 0.5437990437678338); expectedResults.put("second", 0.9273103124158457); expectedResults.put("sentences", 1.0462913625399426); expectedResults.put("sentence", 1.3536663910626023); String testDocument = "This is a not so long test sentence. This is a longer second test sentence. More sentences are necessary for the tests."; AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class, StanfordPosTagger.PARAM_LANGUAGE, "en"), AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class), createEngineDescription( PosFilter.class, PosFilter.PARAM_TYPE_TO_REMOVE, Token.class.getName(), PosFilter.PARAM_ADJ, true, PosFilter.PARAM_N, true ), CooccurrenceGraphFactory.getCooccurrenceGraph_token(), createEngineDescription(PageRankRanking.class, PageRankRanking.PARAM_WEIGHTED, false)); AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); int i=0; for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { assertTrue(keyphrase.getKeyphrase(), expectedResults.containsKey(keyphrase.getKeyphrase())); assertEquals(keyphrase.getKeyphrase(), expectedResults.get(keyphrase.getKeyphrase()), keyphrase.getScore(), EPSILON); i++; } assertEquals(10,i); }
@Test public void TestDefaults() throws Exception { String testDocument = "This is a not so long test sentence. This is a longer second test sentence. More sentences are necessary for the tests."; AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class, StanfordPosTagger.PARAM_LANGUAGE, "en"), AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class), createEngineDescription( PosFilter.class, PosFilter.PARAM_TYPE_TO_REMOVE, Token.class.getName() ), CooccurrenceGraphFactory.getCooccurrenceGraph_token(), createEngineDescription( PageRankRanking.class ) ); AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); int i=0; for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { System.out.println("\"" + keyphrase.getKeyphrase() + "\", " + keyphrase.getScore()); i++; } assertEquals(0,i); }
@Test public void UimaTokenTest() throws Exception { Map<String,Double> expectedResults = new HashMap<String,Double>(); expectedResults.put(".", 1.661900603917403); expectedResults.put("test", 1.2836673859058836); expectedResults.put("are", 0.9620982432002869); expectedResults.put("sentences", 0.9431203792298113); expectedResults.put("so", 0.921031990159519); expectedResults.put("long", 0.9051287280811249); expectedResults.put("More", 0.9039247574403875); expectedResults.put("second", 0.8954061167643781); expectedResults.put("This", 0.8825146333163552); expectedResults.put("sentence", 0.8668209606573215); expectedResults.put("is", 0.8927104216342462); expectedResults.put("longer", 0.8981820352527301); expectedResults.put("tests", 0.9039247574403875); expectedResults.put("not", 0.9090578417656192); expectedResults.put("the", 0.9431203792298113); expectedResults.put("for", 0.9620982432002869); expectedResults.put("necessary", 0.9678483350255677); expectedResults.put("a", 1.2974441877788796); String testDocument = "This is a not so long test sentence. This is a longer second test sentence. More sentences are necessary for the tests."; AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class, StanfordPosTagger.PARAM_LANGUAGE, "en"), AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class), CooccurrenceGraphFactory.getCooccurrenceGraph_token(), createEngineDescription(PageRankRanking.class, PageRankRanking.PARAM_WEIGHTED, false)); AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); int i=0; for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { assertTrue(keyphrase.getKeyphrase(), expectedResults.containsKey(keyphrase.getKeyphrase())); assertEquals(keyphrase.getKeyphrase(), expectedResults.get(keyphrase.getKeyphrase()), keyphrase.getScore(), EPSILON); i++; } assertEquals(23,i); }
@Test public void UimaStemTest() throws Exception { Map<String,Double> expectedResults = new HashMap<String,Double>(); expectedResults.put("test", 1.8134305614665536); expectedResults.put(".", 1.4329982193841975); expectedResults.put("so", 0.8740762172963042); expectedResults.put("for", 0.8731390116788602); expectedResults.put("longer", 0.8508521426507418); expectedResults.put("long", 0.8297210900015667); expectedResults.put("are", 0.8259673863961844); expectedResults.put("This", 0.8153284095664003); expectedResults.put("More", 0.7598346171720322); expectedResults.put("second", 0.8199015271228548); expectedResults.put("the", 0.8293347813912294); expectedResults.put("is", 0.8488911967404977); expectedResults.put("necessari", 0.8720856407424997); expectedResults.put("not", 0.8738473387706528); expectedResults.put("a", 1.2438572442186149); expectedResults.put("sentenc", 1.4367346154008103); String testDocument = "This is a not so long test sentence. This is a longer second test sentence. More sentences are necessary for the tests."; AnalysisEngineDescription aggregate = createEngineDescription( createEngineDescription(BreakIteratorSegmenter.class), AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class, StanfordPosTagger.PARAM_LANGUAGE, "en"), AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class), createEngineDescription (SnowballStemmer.class, SnowballStemmer.PARAM_LANGUAGE, "en"), CooccurrenceGraphFactory.getCooccurrenceGraph_stem(), createEngineDescription(PageRankRanking.class, PageRankRanking.PARAM_WEIGHTED, false) ); AnalysisEngine engine = AnalysisEngineFactory.createEngine(aggregate); JCas aJCas = engine.newJCas(); aJCas.setDocumentText(testDocument); engine.process(aJCas); int i=0; for (Keyphrase keyphrase : JCasUtil.select(aJCas, Keyphrase.class)) { assertTrue(keyphrase.getKeyphrase(), expectedResults.containsKey(keyphrase.getKeyphrase())); assertEquals(keyphrase.getKeyphrase(), expectedResults.get(keyphrase.getKeyphrase()), keyphrase.getScore(), EPSILON); i++; } assertEquals(23,i); }