JiangConrathComparator extends PathBasedComparator { @Override public double getSimilarity(Entity e1, Entity e2) throws SimilarityException, LexicalSemanticResourceException { if (e1.equals(e2)) { return 1.0; } double relatedness = NOT_FOUND; try { Entity lcs = getEntityGraph().getLCS(this.root, e1, e2); if (lcs == null) { return NO_LCS; } double iicLcs = getEntityGraph().getIntrinsicInformationContent(lcs); double iicE1 = getEntityGraph().getIntrinsicInformationContent(e1); double iicE2 = getEntityGraph().getIntrinsicInformationContent(e2); relatedness = (2 - iicE1 - iicE2 + 2*iicLcs) / 2; } catch (UnsupportedOperationException e) { throw new SimilarityException(e); } return relatedness; } JiangConrathComparator(LexicalSemanticResource lexSemResource);  JiangConrathComparator(LexicalSemanticResource lexSemResource, Entity root); @Override double getSimilarity(Entity e1, Entity e2);  }
@Ignore("There seems to be something wrong with the test database. Error: No category with name Anime-influenced_animatio_(non-commercial) was found.") @Test public void testJiangConrathWikipediaCategory() throws Exception { LexicalSemanticResource wikiResource = ResourceFactory.getInstance().get("wikipedia_category", "test"); LexSemResourceComparator comparator = new JiangConrathComparator(wikiResource); assertEquals("JiangConrathComparator", comparator.getName()); Set<Entity> entitiesAqua = wikiResource.getEntity("AQUA"); Set<Entity> entitiesSir = wikiResource.getEntity("SIR"); Set<Entity> entitiesTk = wikiResource.getEntity("Telecooperation"); assertTrue("AQUA", entitiesAqua.size() > 0); assertTrue("SIR", entitiesSir.size() > 0); assertTrue("Tk", entitiesTk.size() > 0); assertEquals(1.0, comparator.getSimilarity(entitiesAqua, entitiesAqua), epsilon); double iicLcs = 1 - (Math.log(3)/Math.log(16)); assertEquals( iicLcs, comparator.getSimilarity(entitiesAqua, entitiesSir), epsilon); assertEquals(0.5, comparator.getSimilarity(entitiesAqua, entitiesTk), epsilon); }
@Test public void testJiangConrathWordnet() throws Exception { Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); LexicalSemanticResource wordnet = ResourceFactory.getInstance().get("wordnet3", "en"); wordnet.setIsCaseSensitive(false); LexSemResourceComparator comparator = new JiangConrathComparator(wordnet, wordnet.getRoot()); assertEquals("JiangConrathComparator", comparator.getName()); Set<Entity> entitiesEntity = wordnet.getEntity("entity"); Set<Entity> entitiesCar = wordnet.getEntity("car"); assertTrue("entity", entitiesEntity.size() > 0); assertTrue("car", entitiesCar.size() > 0); assertEquals(1.0, comparator.getSimilarity(entitiesEntity, entitiesEntity), epsilon); assertEquals(0.66515, comparator.getSimilarity(entitiesEntity, entitiesCar), epsilon); }
@Ignore("The original GermaNet API is not Apache licensed.") @Test public void testJiangConrathGermaNet() throws Exception { LexicalSemanticResource germaNet = ResourceFactory.getInstance().get("germanet", "de"); LexSemResourceComparator comparator = new JiangConrathComparator(germaNet, germaNet.getRoot()); assertEquals("JiangConrathComparator", comparator.getName()); Set<Entity> entitiesEntity = germaNet.getEntity("Entität"); Set<Entity> entitiesAuto = germaNet.getEntity("Auto"); assertTrue("Entität", entitiesEntity.size() > 0); assertTrue("Auto", entitiesAuto.size() > 0); assertEquals(1.0, comparator.getSimilarity(entitiesEntity, entitiesEntity), epsilon); assertEquals(0.74965, comparator.getSimilarity(entitiesEntity, entitiesAuto), epsilon); }