/** * return the synsets that are either the semantically related synsets, or the synsets containing * the lexically related words. If the relation is semantic, these synsets can be from 1 to * #chainingLength WN steps away from the given synset. * * @param lemma * @param synset * @param relation * @param chainingLength is the size of transitive relation chaining to be performed on the * retrieved rules. E.g. if chainingLength = 3, then every hypernym/hyponym, merornym and * holonym query will return rules with words related up to the 3rd degree (that's 1st, 2nd or * 3rd) from the original term. Queries on non transitive relations are unaffected by this * parameter. Must be positive. * @return * @throws WordNetException */ private Set<Synset> getSemanticOrLexicalNeighbors( String lemma, Synset synset, WordNetRelation relation, int chainingLength) throws WordNetException { Set<Synset> synsets; if (relation.isLexical()) { SensedWord sensedWord = dictionary.getSensedWord(lemma, synset); synsets = new LinkedHashSet<Synset>(); for (SensedWord aSensedWord : sensedWord.getNeighborSensedWords(relation)) { synsets.add(aSensedWord.getSynset()); } } else { synsets = synset.getRelatedSynsets(relation, chainingLength); } return synsets; }
/** * If relation is lexical, return the {@link SensedWord}s that are directly related to the given * <lemma, synset>. If relation is semantic, return a {@link SensedWord} for each word in the * synsets related to the given synset, within #chainingLength steps away. * * @param lemma * @param synset * @param relation * @param chainingLength is the size of transitive relation chaining to be performed on the * retrieved rules. E.g. if chainingLength = 3, then every hypernym/hyponym, merornym and * holonym query will return rules with words related up to the 3rd degree (that's 1st, 2nd or * 3rd) from the original term. Queries on non transitive relations are unaffected by this * parameter. Must be positive. * @return * @throws WordNetException */ private Set<SensedWord> getSemanticOrLexicalNeighborSensedWords( String lemma, Synset synset, WordNetRelation relation, int chainingLength) throws WordNetException { Set<SensedWord> relatedSensedWords; if (relation.isLexical()) { SensedWord sensedWord = dictionary.getSensedWord(lemma, synset); relatedSensedWords = sensedWord.getNeighborSensedWords(relation); } else { relatedSensedWords = new LinkedHashSet<SensedWord>(); Set<Synset> relatedSynsets = synset.getRelatedSynsets(relation, chainingLength); // getNeighbors(relation); for (Synset relatedSynset : relatedSynsets) relatedSensedWords.addAll(relatedSynset.getAllSensedWords()); } return relatedSensedWords; }