WordNetResource extends AbstractResource { @Override public Set<String> getRelatedLexemes(String lexeme, PoS pos, String sense, LexicalRelation lexicalRelation) throws LexicalSemanticResourceException { Set<String> relatedLexemes = new HashSet<String>(); if (sense.length() < 7) { return relatedLexemes; } for (POS gnPos : WordNetUtils.mapPos(pos)) { Synset synset = null; try { try { if(isCaseSensitive){ synset = WordNetUtils.toSynset(dict, lexeme, pos, sense, isCaseSensitive); }else{ synset = dict.getSynsetAt(gnPos, new Long(sense)); } } catch (NullPointerException e) { continue; } if (synset == null) { continue; } PointerTargetNodeList nodeList = getNodeListByRelation(synset, lexicalRelation); if (nodeList != null) { for (Object node : nodeList) { PointerTargetNode ptNode = (PointerTargetNode) (node); Synset nodeSynset = ptNode.getSynset(); List<Word> synsetWords = nodeSynset.getWords(); for (Word synsetWord : synsetWords) { if (!synsetWord.getLemma().equals(lexeme)) { relatedLexemes.add(synsetWord.getLemma()); } } } } if (lexicalRelation.equals(LexicalRelation.synonymy)) { List<Word> directSynonymWords = synset.getWords(); for (Word synsetWord : directSynonymWords) { if (!synsetWord.getLemma().equals(lexeme)) { relatedLexemes.add(synsetWord.getLemma()); } } } } catch (NumberFormatException e) { throw new LexicalSemanticResourceException(e); } catch (JWNLException e) { throw new LexicalSemanticResourceException(e); } } return relatedLexemes; } 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 testGetLexicalRelations() throws LexicalSemanticResourceException { wordnet.setIsCaseSensitive(false); Set<String> expectedAntonyms = new HashSet<String>(); expectedAntonyms.add("cool"); Set<String> expectedSynonyms = new HashSet<String>(); expectedSynonyms.add("fond"); expectedSynonyms.add("affectionate"); expectedSynonyms.add("warm"); expectedSynonyms.add("loving"); expectedSynonyms.add("tender"); Set<String> antonyms = wordnet.getRelatedLexemes("warm", PoS.adj, "2530861", LexicalRelation.antonymy); assertEquals(1, antonyms.size()); for (String antonym : antonyms) { assertTrue(antonym, expectedAntonyms.contains(antonym)); } Set<String> synonyms = wordnet.getRelatedLexemes("lovesome", PoS.adj, "1464700", LexicalRelation.synonymy); assertEquals(5, synonyms.size()); for (String synonym : synonyms) { assertTrue(synonym, expectedSynonyms.contains(synonym)); } wordnet.setIsCaseSensitive(true); antonyms = wordnet.getRelatedLexemes("warm", PoS.adj, "2530861", LexicalRelation.antonymy); assertEquals(1, antonyms.size()); for (String antonym : antonyms) { assertTrue(antonym, expectedAntonyms.contains(antonym)); } antonyms = wordnet.getRelatedLexemes("Warm", PoS.adj, "2530861", LexicalRelation.antonymy); assertEquals(0, antonyms.size()); synonyms = wordnet.getRelatedLexemes("lovesome", PoS.adj, "1464700", LexicalRelation.synonymy); assertEquals(5, synonyms.size()); for (String synonym : synonyms) { assertTrue(synonym, expectedSynonyms.contains(synonym)); } synonyms = wordnet.getRelatedLexemes("Lovesome", PoS.adj, "1464700", LexicalRelation.synonymy); assertEquals(synonyms.size(), 0); }