WordNetResource extends AbstractResource { @Override public Set<Entity> getEntity(String lexeme) throws LexicalSemanticResourceException { Set<Synset> synsets = WordNetUtils.toSynset(dict, lexeme, isCaseSensitive); return WordNetUtils.synsetsToEntities(synsets); } WordNetResource();  WordNetResource(String wordNetPropertiesFile); @Override boolean containsLexeme(String lexeme); @Override boolean containsEntity(Entity entity); @Override Set<Entity> getEntity(String lexeme); @Override Set<Entity> getEntity(String lexeme, PoS pos); @Override Set<Entity> getEntity(String lexeme, PoS pos, String sense); Set<Entity> getEntity(String lexeme, PoS pos, int sense); @Override Set<Entity> getParents(Entity entity); @Override int getNumberOfEntities(); @Override Iterable<Entity> getEntities(); @Override Set<Entity> getChildren(Entity entity); @Override String getResourceName(); @Override String getResourceVersion(); @Override int getShortestPathLength(Entity firstEntity, Entity secondEntity); @Override String getGloss(Entity entity); @Override Set<String> getRelatedLexemes(String lexeme, PoS pos, String sense, LexicalRelation lexicalRelation); @Override Set<Entity> getRelatedEntities(Entity entity, SemanticRelation semanticRelation); Set<Entity> getRelatedEntitiesByName(Entity entity, String semanticRelation); @Override Entity getRoot(); @Override Entity getRoot(PoS pos); @Override Entity getMostFrequentEntity(String lexeme); @Override Entity getMostFrequentEntity(String lexeme, PoS pos); Dictionary getDict();  }
@Test public void testGetEntity() throws LexicalSemanticResourceException { wordnet.setIsCaseSensitive(false); Set<String> expectedResults = new HashSet<String>(); expectedResults.add("tree#1145163|---v"); expectedResults.add("tree#1616293|---v"); expectedResults.add("shoetree#319111|tree#319111|---v"); expectedResults.add("corner#1934205|tree#1934205|---v"); expectedResults.add("tree#13104059|---n"); expectedResults.add("tree#13912260|tree diagram#13912260|---n"); expectedResults.add("Sir Herbert Beerbohm Tree#11348160|Tree#11348160|---n"); Set<Entity> entities = wordnet.getEntity("tree"); assertEquals(7, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); } wordnet.setIsCaseSensitive(true); entities = wordnet.getEntity("Tree"); assertEquals(entities.size(), 0); }
@Test @Ignore("this fails due to a bug in the WordNet API, it returns not only automotive_vehicle, " + "but also any other synset containing automotive or vehicle - See Bug 160") public void testGetEntitySpecialCases() throws LexicalSemanticResourceException { wordnet.setIsCaseSensitive(false); Set<String> expectedResults = new HashSet<String>(); expectedResults.add("automotive_vehicle#3791235|motor_vehicle#3791235|---n"); Set<Entity> entities = wordnet.getEntity("automotive_vehicle"); assertEquals(1, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); } wordnet.setIsCaseSensitive(true); entities = wordnet.getEntity("automotive_vehicle"); assertEquals(3, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); } }
@Test public void testGetEntityPos() throws LexicalSemanticResourceException { wordnet.setIsCaseSensitive(false); Set<String> expectedResults = new HashSet<String>(); expectedResults.add("tree#13104059|---n"); expectedResults.add("tree#13912260|tree diagram#13912260|---n"); expectedResults.add("Sir Herbert Beerbohm Tree#11348160|Tree#11348160|---n"); Set<Entity> entities = wordnet.getEntity("tree", PoS.n); assertEquals(3, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); } entities = wordnet.getEntity("Tree", PoS.n); assertEquals(3, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); } wordnet.setIsCaseSensitive(true); expectedResults = new HashSet<String>(); expectedResults.add("tree#13104059|---n"); expectedResults.add("tree#13912260|tree diagram#13912260|---n"); expectedResults.add("Sir Herbert Beerbohm Tree#11348160|Tree#11348160|---n"); entities = wordnet.getEntity("tree", PoS.n); assertEquals(3, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); } entities = wordnet.getEntity("Tree", PoS.n); }
@Test public void testGetEntityPosSense() throws LexicalSemanticResourceException { wordnet.setIsCaseSensitive(false); Set<String> expectedResults = new HashSet<String>(); expectedResults.add("tree#13912260|tree diagram#13912260|---n"); Map<String, String> treeLexemes = new HashMap<String, String>(); treeLexemes.put("tree", "13912260"); treeLexemes.put("tree diagram", "13912260"); Entity treeEntity = new Entity(treeLexemes, PoS.n); Set<Entity> entities = wordnet.getEntity("tree", PoS.n, "13912260"); assertEquals(1, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); assertEquals(0, entity.compareTo(treeEntity)); } entities = wordnet.getEntity("Tree", PoS.n, "13912260"); assertEquals(1, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); assertEquals(0, entity.compareTo(treeEntity)); } wordnet.setIsCaseSensitive(true); entities = wordnet.getEntity("tree", PoS.n, "13912260"); assertEquals(1, entities.size()); for (Entity entity : entities) { assertTrue(entity.getId(), expectedResults.contains(entity.getId())); assertEquals(0, entity.compareTo(treeEntity)); } entities = wordnet.getEntity("Tree", PoS.n, "13912260"); assertEquals(0, entities.size()); }
@Test public void testHyponymMap() throws Exception { wordnet.setIsCaseSensitive(false); EntityGraph eg = EntityGraphManager.getEntityGraph(wordnet, EntityGraphType.JGraphT, new File("target/test-output/getEntityGraph")); eg.getIntrinsicInformationContent(wordnet.getEntity("tree").iterator().next()); }