PathLengthComparator extends PathBasedComparator { @Override public double getSimilarity(Entity e1, Entity e2) throws SimilarityException, LexicalSemanticResourceException { if (e1.equals(e2)) { return 0.0; } double distance = getShortestPathLength(e1, e2); if (convertToRelatedness) { return (diameter - distance) / diameter; } else { return distance; } } PathLengthComparator(LexicalSemanticResource lexSemResource);  PathLengthComparator(LexicalSemanticResource lexSemResource,	boolean convertToRelatedness); @Override double getSimilarity(Entity e1, Entity e2); @Override boolean isDistanceMeasure();  }
@Test @Ignore("WiktionaryResource.getParents() is not implemented.") public void testWiktionary() throws Exception { LexSemResourceComparator comparator = new PathLengthComparator(wiktionary); Set<Entity> entitiesFahrzeug = wiktionary.getEntity("Fahrzeug"); Set<Entity> entitiesAuto = wiktionary.getEntity("Auto"); Set<Entity> entitiesGarten = wiktionary.getEntity("Garten"); Set<Entity> entitiesEmpty = new HashSet<Entity>(); Set<Entity> entitiesUnknown = new HashSet<Entity>(); entitiesUnknown.add(new Entity("humbelgrmpfh")); assertEquals(0.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesFahrzeug), epsilon); assertEquals(3.0, comparator.getSimilarity(entitiesAuto, entitiesGarten), epsilon); assertEquals(PathLengthComparator.NOT_FOUND, comparator.getSimilarity(entitiesAuto, entitiesEmpty), epsilon); assertEquals(PathLengthComparator.NOT_FOUND, comparator.getSimilarity(entitiesAuto, entitiesUnknown), epsilon); assertEquals(comparator.getSimilarity(entitiesFahrzeug, entitiesAuto), comparator.getSimilarity(entitiesAuto, entitiesFahrzeug), epsilon); }
@Ignore("The original GermaNet API is not Apache licensed.") @Test public void testGermaNetUsingResourceLoader() throws Exception { LexSemResourceComparator comparator = new PathLengthComparator(germanet); Set<Entity> entitiesAuto = germanet.getEntity("Auto", PoS.n); Set<Entity> entitiesBagger = germanet.getEntity("Bagger", PoS.n); Set<Entity> entitiesSchnell = germanet.getEntity("schnell", PoS.adj); assertEquals(0.0, comparator.getSimilarity(entitiesAuto, entitiesAuto), epsilon); assertEquals(1.0, comparator.getSimilarity(entitiesAuto, entitiesBagger), epsilon); assertEquals(6.0, comparator.getSimilarity(entitiesAuto, entitiesSchnell), epsilon); }
@Test public void testWordNet() throws Exception { Assume.assumeTrue(Runtime.getRuntime().maxMemory() > 1000000000); LexSemResourceComparator comparator = new PathLengthComparator(wordnet); Set<Entity> entitiesTree = wordnet.getEntity("tree", PoS.n); Set<Entity> entitiesPlant = wordnet.getEntity("plant", PoS.n); Set<Entity> entitiesFast = wordnet.getEntity("fast", PoS.adj); assertEquals(0.0, comparator.getSimilarity(entitiesTree, entitiesTree), epsilon); assertEquals(2.0, comparator.getSimilarity(entitiesTree, entitiesPlant), epsilon); assertEquals(PathLengthComparator.NOT_FOUND, comparator.getSimilarity(entitiesTree, entitiesFast), epsilon); }