WiktionaryResource extends AbstractResource { public Set<String> getRelatedLexemes(String lexeme, PoS pos, String sense, LexicalRelation lexicalRelation) throws LexicalSemanticResourceException { Map<String,String> lexemeMap = new HashMap<String,String>(); lexemeMap.put(lexeme, sense); Entity entity = this.getEntity(lexemeMap, pos); if (entity == null) { return Collections.emptySet(); } Set<String> relatedWords = new HashSet<String>(); Set<WordEntry> words = WiktionaryUtils.entityToWords(wkt, entity); for (WordEntry word : words) { if (lexicalRelation.equals(LexicalRelation.antonymy)) { relatedWords.addAll(word.getAllRelatedWords(RelationType.ANTONYM)); } else if (lexicalRelation.equals(LexicalRelation.synonymy)) { relatedWords.addAll(word.getAllRelatedWords(RelationType.SYNONYM)); } } return relatedWords; } WiktionaryResource(
    		Language language,
    		String wiktionaryDirectory); @Override void setIsCaseSensitive(boolean isCaseSensitive); @Override boolean getIsCaseSensitive(); boolean containsLexeme(String lexeme); boolean containsEntity(Entity entity); Set<Entity> getEntity(String lexeme); Set<Entity> getEntity(String lexeme, PoS pos); Set<Entity> getEntity(String lexeme, PoS pos, String sense); Set<Entity> getParents(Entity entity); Set<Entity> getChildren(Entity entity); int getNumberOfEntities(); Iterable<Entity> getEntities(); @Override Set<Entity> getNeighbors(Entity entity); String getResourceName(); String getResourceVersion(); int getShortestPathLength(Entity firstEntity, Entity secondEntity); String getGloss(Entity entity); Set<Entity> getRelatedEntities(Entity entity, SemanticRelation semanticRelation); Set<String> getRelatedLexemes(String lexeme, PoS pos, String sense, LexicalRelation lexicalRelation); @Override Entity getRoot(); @Override Entity getRoot(PoS pos); @Override Entity getMostFrequentEntity(String lexeme); @Override Entity getMostFrequentEntity(String lexeme, PoS pos);  }
@Test public void testGetRelatedLexemes() throws Exception { Set<String> expectedAntonyms = new HashSet<String>(); expectedAntonyms.add("rot"); expectedAntonyms.add("gelb"); expectedAntonyms.add("blau"); Set<String> expectedSynonyms = new HashSet<String>(); expectedSynonyms.add("orangen"); expectedSynonyms.add("orangefarben"); expectedSynonyms.add("orangefarbig"); expectedSynonyms.add("antiquiert"); expectedSynonyms.add("gelbrot"); expectedSynonyms.add("rotgelb"); Set<String> antonyms; wiktionaryGerman.setIsCaseSensitive(false); antonyms = wiktionaryGerman.getRelatedLexemes("orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.antonymy); assertEquals(expectedAntonyms.size(), antonyms.size()); int i = 0; for (String antonym : antonyms) { assertTrue(antonym, expectedAntonyms.contains(antonym)); i++; } assertEquals(3, i); antonyms = wiktionaryGerman.getRelatedLexemes("Orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.antonymy); assertEquals(expectedAntonyms.size(), antonyms.size()); i = 0; for (String antonym : antonyms) { assertTrue(antonym, expectedAntonyms.contains(antonym)); i++; } assertEquals(3, i); Set<String> synonyms = wiktionaryGerman.getRelatedLexemes("orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.synonymy); assertEquals(expectedSynonyms.size(), synonyms.size()); int j = 0; for (String synonym : synonyms) { assertTrue(synonym, expectedSynonyms.contains(synonym)); j++; } assertEquals(6, j); synonyms = wiktionaryGerman.getRelatedLexemes("Orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.synonymy); assertEquals(expectedSynonyms.size(), synonyms.size()); j = 0; for (String synonym : synonyms) { assertTrue(synonym, expectedSynonyms.contains(synonym)); j++; } assertEquals(6, j); wiktionaryGerman.setIsCaseSensitive(true); antonyms = wiktionaryGerman.getRelatedLexemes("orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.antonymy); assertEquals(expectedAntonyms.size(), antonyms.size()); i = 0; for (String antonym : antonyms) { assertTrue(antonym, expectedAntonyms.contains(antonym)); i++; } assertEquals(3, i); antonyms = wiktionaryGerman.getRelatedLexemes("Orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.antonymy); assertEquals(0, antonyms.size()); synonyms = wiktionaryGerman.getRelatedLexemes("orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.synonymy); assertEquals(expectedSynonyms.size(), synonyms.size()); j = 0; for (String synonym : synonyms) { assertTrue(synonym, expectedSynonyms.contains(synonym)); j++; } assertEquals(6, j); synonyms = wiktionaryGerman.getRelatedLexemes("Orange", PoS.adj, Entity.UNKNOWN_SENSE, LexicalRelation.synonymy); assertEquals(0, synonyms.size()); }