從來源:
你有迭代器和狀態都在這個庫:
/**
* Main word lookup procedure. First try a normal lookup. If that doesn't work,
* try looking up the stemmed form of the lemma.
* @param pos the part-of-speech of the word to look up
* @param lemma the lemma to look up
* @return IndexWord the IndexWord found by the lookup procedure, or null
* if an IndexWord is not found
*/
public IndexWord lookupIndexWord(POS pos, String lemma) throws JWNLException {
lemma = prepareQueryString(lemma);
IndexWord word = getIndexWord(pos, lemma);
if (word == null && getMorphologicalProcessor() != null) {
word = getMorphologicalProcessor().lookupBaseForm(pos, lemma);
}
return word;
}
/**
* Return a set of <code>IndexWord</code>s, with each element in the set
* corresponding to a part-of-speech of <var>word</var>.
* @param lemma the word for which to lookup senses
* @return An array of IndexWords, each of which is a sense of <var>word</var>
*/
public IndexWordSet lookupAllIndexWords(String lemma) throws JWNLException {
lemma = prepareQueryString(lemma);
IndexWordSet set = new IndexWordSet(lemma);
for (Iterator itr = POS.getAllPOS().iterator(); itr.hasNext();) {
IndexWord current = lookupIndexWord((POS)itr.next(), lemma);
if (current != null) set.add(current);
}
return set;
}
和POS我們發現
private static final List ALL_POS =
Collections.unmodifiableList( /* alphazero: this is good news .. */
Arrays.asList(new POS[] {NOUN, VERB, ADJECTIVE, ADVERB}));
public static List getAllPOS() {
return ALL_POS;
}
嘗試林奇的回答。它應該工作。
將使用字典作爲單身人士的類會幫助嗎? – 2011-04-26 04:26:05
你將不得不諮詢他的wordnet詞典API,看看它是否是線程安全的。 – MeBigFatGuy 2011-04-26 04:27:20
如果您確定此代碼不是線程安全的,則必須在所有訪問器使用的同步塊中進行此調用。 'synchronized(someLockingObject){return Dictionary.getInstance()。lookupAllIndexWords(newWord); }' – MeBigFatGuy 2011-04-26 04:28:53