GlossOverlapComparator extends GlossBasedComparator { @Override public double getSimilarity(Set<Entity> entities1, Set<Entity> entities2) throws LexicalSemanticResourceException, SimilarityException { if (entities1.size() == 0 || entities2.size() == 0) { if (entities1.size() == 0) { logger.debug("First entity set is empty."); } else { logger.debug("Second entity set is empty."); } return GlossBasedComparator.NOT_FOUND; } List<Double> relatednessValues = new ArrayList<Double>(); for (Entity e1 : entities1) { for (Entity e2 : entities2) { relatednessValues.add( getSimilarity(e1, e2) ); } } return Collections.max(relatednessValues); } GlossOverlapComparator(LexicalSemanticResource lexSemResource, boolean usePseudoGlosses); @Override double getSimilarity(Set<Entity> entities1, Set<Entity> entities2); @Override double getSimilarity(Entity e1, Entity e2); @Override String getName();  }
@Ignore("MySQL server with Wikipedia data not available") @Test public void testGlossOverlapWikipedia() throws Exception { LexSemResourceComparator comparator = new GlossOverlapComparator(wikiResource, false); Set<Entity> entitiesAuto = wikiResource.getEntity("Automobile"); Set<Entity> entitiesTruck = wikiResource.getEntity("Truck"); assertTrue("Auto", entitiesAuto.size() > 0); assertTrue("Truck", entitiesTruck.size() > 0); assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); assertEquals(0.2931, comparator.getSimilarity(entitiesAuto, entitiesTruck), epsilon); }
@Ignore("Currently deactivated as Wiktionary resource data is not for API version is not available.") @Test public void testGlossOverlapWiktionary() throws LexicalSemanticResourceException, SimilarityException { LexSemResourceComparator comparator = new GlossOverlapComparator(wktResource, false); Set<Entity> entities1 = wktResource.getEntity("Bayern"); Set<Entity> entities2 = wktResource.getEntity("Deutschland"); assertTrue("Bayern", entities1.size() > 0); assertTrue("Deutschland", entities2.size() > 0); assertEquals(1.0, comparator.getSimilarity(entities1, entities1), epsilon); assertEquals(0.22222, comparator.getSimilarity(entities1, entities2), epsilon); }
@Test @Ignore("TODO for some reason the leskComparator gloss is from the disambiguation page - need to discover why") public void comparisonWithJwplImplementationTest() throws LexicalSemanticResourceException, WikiException, SimilarityException { wikiResource.setIsCaseSensitive(true); LexSemResourceComparator glossOverlapComparator = new GlossOverlapComparator(wikiResource, false); String term1 = "Automobile"; String term2 = "Truck"; Set<Entity> entitiesAuto = wikiResource.getEntity(term1); Set<Entity> entitiesTruck = wikiResource.getEntity(term2); LeskComparator leskComparator = new LeskFirstComparator(wiki); leskComparator.setUseCache(false); assertEquals(glossOverlapComparator.getSimilarity(entitiesAuto, entitiesTruck), leskComparator.getSimilarity(term1, term2), epsilon); wikiResource.setIsCaseSensitive(false); }