WikipediaBasedComparator extends TextSimilarityMeasureBase { @Override public double getSimilarity(String term1, String term2) throws SimilarityException { return this.wikipediaComparator.getSimilarity(term1, term2); } WikipediaBasedComparator(Wikipedia wikipedia, WikipediaBasedRelatednessMeasure measure);  WikipediaBasedComparator(Wikipedia wikipedia, WikipediaBasedRelatednessMeasure measure, boolean useCache); @Override String getName(); @Override double getSimilarity(String term1, String term2); @Override double getSimilarity(Collection<String> terms1, Collection<String> terms2); static final double NO_PATH; }
@Test @Ignore public void testLinMeasure() throws Exception { TermSimilarityMeasure lc = new WikipediaBasedComparator(wiki, WikipediaBasedRelatednessMeasure.Lin, false); String token1 = "TK3"; String token2 = "TK3"; double relatednessBest = lc.getSimilarity(token1, token2); assertEquals(1.0, relatednessBest, epsilon); token1 = "Iryna Gurevych"; token2 = "UKP"; relatednessBest = lc.getSimilarity(token1, token2); assertEquals(0.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Unconnected page"; relatednessBest = lc.getSimilarity(token1, token2); assertEquals(-3.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Net_Centric_Systems"; relatednessBest = lc.getSimilarity(token1, token2); assertEquals(1.0, relatednessBest, epsilon); token1 = "AQUA"; token2 = "UKP"; relatednessBest = lc.getSimilarity(token1, token2); assertEquals(0.3155, relatednessBest, epsilon); }
@Test @Ignore public void testPathLengthMeasure() throws Exception { TermSimilarityMeasure plc = new WikipediaBasedComparator(wiki, WikipediaBasedRelatednessMeasure.PathLength, false); String token1 = "TK3"; String token2 = "TK3"; double relatednessBest = plc.getSimilarity(token1, token2); assertEquals(0.0, relatednessBest, epsilon); token1 = "Iryna Gurevych"; token2 = "UKP"; relatednessBest = plc.getSimilarity(token1, token2); assertEquals(5.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Unconnected page"; relatednessBest = plc.getSimilarity(token1, token2); assertEquals(-3.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Net_Centric_Systems"; relatednessBest = plc.getSimilarity(token1, token2); assertEquals(0.0, relatednessBest, epsilon); token1 = "UKP"; token2 = "Natural Language Processing for Ambient Intelligence"; relatednessBest = plc.getSimilarity(token1, token2); assertEquals(4.0, relatednessBest, epsilon); }
@Test @Ignore public void testResnikMeasure() throws Exception { TermSimilarityMeasure rc = new WikipediaBasedComparator(wiki, WikipediaBasedRelatednessMeasure.Resnik, false); String token1 = "TK3"; String token2 = "TK3"; double relatednessBest = rc.getSimilarity(token1, token2); assertEquals(1.0, relatednessBest, epsilon); token1 = "Iryna Gurevych"; token2 = "UKP"; relatednessBest = rc.getSimilarity(token1, token2); assertEquals(0.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Unconnected page"; relatednessBest = rc.getSimilarity(token1, token2); assertEquals(-3.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Net_Centric_Systems"; relatednessBest = rc.getSimilarity(token1, token2); assertEquals(1.0, relatednessBest, epsilon); }
@Test @Ignore public void testWuPalmerMeasure() throws Exception { TermSimilarityMeasure wpc = new WikipediaBasedComparator(wiki, WikipediaBasedRelatednessMeasure.WuPalmer, false); String token1 = "TK3"; String token2 = "TK3"; double relatednessBest = wpc.getSimilarity(token1, token2); assertEquals(1.0, relatednessBest, epsilon); token1 = "Iryna Gurevych"; token2 = "UKP"; relatednessBest = wpc.getSimilarity(token1, token2); assertEquals(0.0, relatednessBest, epsilon); token1 = "UKP"; token2 = "Natural Language Processing for Ambient Intelligence"; relatednessBest = wpc.getSimilarity(token1, token2); assertEquals(0.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Unconnected page"; relatednessBest = wpc.getSimilarity(token1, token2); assertEquals(-3.0, relatednessBest, epsilon); token1 = "NCS"; token2 = "Net_Centric_Systems"; relatednessBest = wpc.getSimilarity(token1, token2); assertEquals(1.0, relatednessBest, epsilon); }