@Test public void evaluateCollocation(){ new MockUp<LikelihoodCollocationScorer>(){ @Mock double getLogLikelihood(Long total, Long tokenOne, Long tokenTwo, Long colloc, List<TreeMap<String, Object>> output) { return 1.0; } }; double expected = 10.0; double actual = target.evaluateCollocation(nGram, new ArrayList<TreeMap<String, Object>>()); Assert.assertEquals(expected, actual, 1e-4); }
public double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output) { if(nGram.getLength() == 1) return 0; if(nGram.getLength() == 2) return likelihoodBigram(nGram, output) - parameterSet.threshold; if(nGram.getLength() > 2) { double score = 0; for (int i = 0; i < nGram.getLength() - 2; ++i) { score += likelihoodTrigram(nGram.getSubNGram(i, 3), output) - parameterSet.threshold; score += likelihoodBigram(nGram.getSubNGram(i, 2), output) - parameterSet.threshold; } score += likelihoodBigram(nGram.getSubNGram(nGram.getLength()-2, 2), output) - parameterSet.threshold; return score; } return 0; }
LikelihoodCollocationScorer implements ICollocationScorer { public double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output) { if(nGram.getLength() == 1) return 0; if(nGram.getLength() == 2) return likelihoodBigram(nGram, output) - parameterSet.threshold; if(nGram.getLength() > 2) { double score = 0; for (int i = 0; i < nGram.getLength() - 2; ++i) { score += likelihoodTrigram(nGram.getSubNGram(i, 3), output) - parameterSet.threshold; score += likelihoodBigram(nGram.getSubNGram(i, 2), output) - parameterSet.threshold; } score += likelihoodBigram(nGram.getSubNGram(nGram.getLength()-2, 2), output) - parameterSet.threshold; return score; } return 0; } }
LikelihoodCollocationScorer implements ICollocationScorer { public double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output) { if(nGram.getLength() == 1) return 0; if(nGram.getLength() == 2) return likelihoodBigram(nGram, output) - parameterSet.threshold; if(nGram.getLength() > 2) { double score = 0; for (int i = 0; i < nGram.getLength() - 2; ++i) { score += likelihoodTrigram(nGram.getSubNGram(i, 3), output) - parameterSet.threshold; score += likelihoodBigram(nGram.getSubNGram(i, 2), output) - parameterSet.threshold; } score += likelihoodBigram(nGram.getSubNGram(nGram.getLength()-2, 2), output) - parameterSet.threshold; return score; } return 0; } LikelihoodCollocationScorer(HashMap<String, Long> frequencyMap,
                                       HashMap<NGramField, Long> totalFrequencies,
                                       ScorerParameterSet parameterSet); }
LikelihoodCollocationScorer implements ICollocationScorer { public double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output) { if(nGram.getLength() == 1) return 0; if(nGram.getLength() == 2) return likelihoodBigram(nGram, output) - parameterSet.threshold; if(nGram.getLength() > 2) { double score = 0; for (int i = 0; i < nGram.getLength() - 2; ++i) { score += likelihoodTrigram(nGram.getSubNGram(i, 3), output) - parameterSet.threshold; score += likelihoodBigram(nGram.getSubNGram(i, 2), output) - parameterSet.threshold; } score += likelihoodBigram(nGram.getSubNGram(nGram.getLength()-2, 2), output) - parameterSet.threshold; return score; } return 0; } LikelihoodCollocationScorer(HashMap<String, Long> frequencyMap,
                                       HashMap<NGramField, Long> totalFrequencies,
                                       ScorerParameterSet parameterSet); double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output); }
LikelihoodCollocationScorer implements ICollocationScorer { public double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output) { if(nGram.getLength() == 1) return 0; if(nGram.getLength() == 2) return likelihoodBigram(nGram, output) - parameterSet.threshold; if(nGram.getLength() > 2) { double score = 0; for (int i = 0; i < nGram.getLength() - 2; ++i) { score += likelihoodTrigram(nGram.getSubNGram(i, 3), output) - parameterSet.threshold; score += likelihoodBigram(nGram.getSubNGram(i, 2), output) - parameterSet.threshold; } score += likelihoodBigram(nGram.getSubNGram(nGram.getLength()-2, 2), output) - parameterSet.threshold; return score; } return 0; } LikelihoodCollocationScorer(HashMap<String, Long> frequencyMap,
                                       HashMap<NGramField, Long> totalFrequencies,
                                       ScorerParameterSet parameterSet); double evaluateCollocation(NGram nGram, List<TreeMap<String,Object>> output);  }