public Set<String> getRelatedLexemes(String lexeme, PoS pos, String sense, LexicalRelation lexicalRelation) throws LexicalSemanticResourceException { Entity entity = WikipediaArticleUtils.lexemeToEntity(wiki, lexeme, isCaseSensitive); Set<String> relatedLexemes = new HashSet<String>(); if (entity == null) { return relatedLexemes; } if (lexicalRelation.equals(LexicalRelation.antonymy)) { logger.warn("Wikipedia contains no antonymy information. Returning empty set."); } else if (lexicalRelation.equals(LexicalRelation.synonymy)) { for (String synonym : entity.getLexemes()) { String plainSynonym = WikipediaArticleUtils.plainString(synonym); if (!plainSynonym.equals(lexeme)) { relatedLexemes.add(plainSynonym); } } } return relatedLexemes; }
if (lexicalRelation.equals(LexicalRelation.synonymy)) {
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; }
private PointerTargetNodeList getNodeListByRelation(Synset synset, LexicalRelation lexicalRelation) throws LexicalSemanticResourceException { try { if (lexicalRelation.equals(LexicalRelation.antonymy)) { return PointerUtils.getAntonyms(synset); } else if (lexicalRelation.equals(LexicalRelation.synonymy)) { return PointerUtils.getSynonyms(synset); } } catch (NullPointerException e) { // silently catch that - I do not know why JWNL throws that exception here } catch (JWNLException e) { throw new LexicalSemanticResourceException(e); } return null; }