@Test public void test() throws InvalidXMLException, ResourceInitializationException, AnalysisEngineProcessException, IOException { String testDocument = "example sentence funny. second example. hdjdl"; final AnalysisEngineDescription ranker = createEngineDescription( TfBackgroundIdfRanking.class); bindResource(ranker, TfBackgroundIdfRanking.FREQUENCY_COUNT_RESOURCE, Web1TFrequencyCountResource.class, Web1TFrequencyCountResource.PARAM_MIN_NGRAM_LEVEL, "1", Web1TFrequencyCountResource.PARAM_MAX_NGRAM_LEVEL, "3", Web1TFrequencyCountResource.PARAM_INDEX_PATH, "src/test/resources/jweb1t"); final AnalysisEngine rankerAE = AnalysisEngineFactory.createEngine(ranker); JCas jcas = setup(testDocument, rankerAE); rankerAE.process(jcas); int n=0; boolean exampleContained = false; boolean secondContained = false; boolean hdjdlContained = false; for (Keyphrase keyphrase : JCasUtil.select(jcas, Keyphrase.class)) { n++; if (keyphrase.getCoveredText().equals("example")) { assertEquals(2.0 / Math.log(2.0), keyphrase.getScore(), EPSILON); exampleContained = true; } else if (keyphrase.getCoveredText().equals("second")) { assertEquals(1.0 / Math.log(4.0), keyphrase.getScore(), EPSILON); secondContained = true; } else if (keyphrase.getCoveredText().equals("hdjdl")) { assertEquals(0.0, keyphrase.getScore(), EPSILON); hdjdlContained = true; } } assertEquals(4, n); assertTrue(exampleContained); assertTrue(secondContained); assertTrue(hdjdlContained); }
protected double getScore(Keyphrase keyphrase) throws AnalysisEngineProcessException{ double tfScore = termFrequencies.getCount(keyphrase.getKeyphrase()); try { final Long frequency = frequencyProvider.getFrequency(keyphrase.getKeyphrase()); if(frequency <= 0) { return 0.0d; } else { return (tfScore/Math.log(1+frequency)); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
TfBackgroundIdfRanking extends TfRanking { protected double getScore(Keyphrase keyphrase) throws AnalysisEngineProcessException{ double tfScore = termFrequencies.getCount(keyphrase.getKeyphrase()); try { final Long frequency = frequencyProvider.getFrequency(keyphrase.getKeyphrase()); if(frequency <= 0) { return 0.0d; } else { return (tfScore/Math.log(1+frequency)); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } }
TfBackgroundIdfRanking extends TfRanking { protected double getScore(Keyphrase keyphrase) throws AnalysisEngineProcessException{ double tfScore = termFrequencies.getCount(keyphrase.getKeyphrase()); try { final Long frequency = frequencyProvider.getFrequency(keyphrase.getKeyphrase()); if(frequency <= 0) { return 0.0d; } else { return (tfScore/Math.log(1+frequency)); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }  }
TfBackgroundIdfRanking extends TfRanking { protected double getScore(Keyphrase keyphrase) throws AnalysisEngineProcessException{ double tfScore = termFrequencies.getCount(keyphrase.getKeyphrase()); try { final Long frequency = frequencyProvider.getFrequency(keyphrase.getKeyphrase()); if(frequency <= 0) { return 0.0d; } else { return (tfScore/Math.log(1+frequency)); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }   }
TfBackgroundIdfRanking extends TfRanking { protected double getScore(Keyphrase keyphrase) throws AnalysisEngineProcessException{ double tfScore = termFrequencies.getCount(keyphrase.getKeyphrase()); try { final Long frequency = frequencyProvider.getFrequency(keyphrase.getKeyphrase()); if(frequency <= 0) { return 0.0d; } else { return (tfScore/Math.log(1+frequency)); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }   static final String FREQUENCY_COUNT_RESOURCE; }