/** * return the list of WN POSs corresponding to the given generic POS. may return an empty list * * @param genericPos * @return * @throws LexicalResourceException */ private WordNetPartOfSpeech[] toWordNetPartOfspeech(PartOfSpeech genericPos) throws LexicalResourceException { WordNetPartOfSpeech[] poss; if (genericPos == null) poss = WordNetPartOfSpeech.values(); // null is a wildcard POS else { WordNetPartOfSpeech wnPos = WordNetPartOfSpeech.toWordNetPartOfspeech(genericPos); if (wnPos != null) { poss = ARRAY_OF_ONE_POS; poss[0] = wnPos; } else poss = EMPTY_ARRAY_OF_POS; } return poss; }
/* * (non-Javadoc) * @see ac.biu.nlp.nlp.instruments.dictionary.wordnet.Dictionary#getSortedSynsetsOf(java.lang.String, ac.biu.nlp.nlp.instruments.dictionary.wordnet.WordNetPartOfSpeech) */ public List<Synset> getSortedSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech) throws WordNetException { try { IndexWord indexWord = getIndexWord(lemma, partOfSpeech); return indexWord != null ? indexWordToList(indexWord) : new ArrayList<Synset>(); } catch (JWNLException e) { throw new WordNetException( "looking for word <" + lemma + "> with part of speech: " + partOfSpeech.toString() + " failed. See nested exception", e); } }
/* * (non-Javadoc) * @see ac.biu.nlp.nlp.instruments.dictionary.wordnet.Dictionary#getSynsetsOf(java.lang.String, ac.biu.nlp.nlp.instruments.dictionary.wordnet.WordNetPartOfSpeech) */ public Set<Synset> getSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech) throws WordNetException { if (doNotProcessThisWord(lemma)) return new LinkedHashSet<Synset>(); else { try { IndexWord indexWord = extJwnlRealDictionary.lookupIndexWord( ExtJwnlUtils.getJwnlPartOfSpeec(partOfSpeech), lemma); return indexWordToSet(indexWord); } catch (JWNLException e) { throw new WordNetException( "looking for word <" + lemma + "> with part of speech: " + partOfSpeech.toString() + " failed. See nested exception", e); } } }
/* * (non-Javadoc) * @see ac.biu.nlp.nlp.instruments.dictionary.wordnet.Dictionary#getSortedSynsetOf(java.lang.String) */ public Map<WordNetPartOfSpeech, List<Synset>> getSortedSynsetOf(String lemma) throws WordNetException { Map<WordNetPartOfSpeech, List<Synset>> ret = new LinkedHashMap<WordNetPartOfSpeech, List<Synset>>(); if (doNotProcessThisWord(lemma)) ; else { try { IndexWordSet indexWordSet = extJwnlRealDictionary.lookupAllIndexWords(lemma); if (indexWordSet != null) { for (WordNetPartOfSpeech partOfSpeech : WordNetPartOfSpeech.values()) { POS pos = ExtJwnlUtils.getJwnlPartOfSpeec(partOfSpeech); if (indexWordSet.getIndexWord(pos) != null) ret.put(partOfSpeech, indexWordToList(indexWordSet.getIndexWord(pos))); } } } catch (JWNLException e) { throw new WordNetException( "looking for lemma <" + lemma + "> failed. See nested exception", e); } } return ret; }
/** * Find the ordinal of targetSynset, among the lemma's synsets * * @param lemma * @param pos * @param targetSynset * @return * @throws LexicalResourceException * @throws WordNetException */ private int getSynsetNo(String lemma, PartOfSpeech pos, Synset targetSynset) throws LexicalResourceException { int synsetNo = 1; WordNetPartOfSpeech wnPos = null; try { wnPos = WordNetPartOfSpeech.toWordNetPartOfspeech(pos); if (wnPos != null) for (Synset synset : dictionary.getSortedSynsetsOf(lemma, wnPos)) if (synset.equals(targetSynset)) return synsetNo; else synsetNo++; } catch (WordNetException e) { throw new LexicalResourceException( "Error pulling the synsets of <" + lemma + ", " + pos + ">", e); } throw new LexicalResourceException( "Internal error. could not find the following synset in the synset-set of <" + lemma + ", " + wnPos + ">: " + targetSynset); }