use of net.didion.jwnl.JWNLException in project lucida by claritylab.
the class WordNet method isCompoundNoun.
/**
* Checks if the word exists as a noun. Supports multi-token terms.
*
* @param word a word
* @return <code>true</code> iff the word is a noun
*/
public static boolean isCompoundNoun(String word) {
if (dict == null)
return false;
// do not look up words with special characters other than '.'
if (word.matches(".*?[^\\w\\s\\.].*+"))
return false;
IndexWord indexWord = null;
try {
indexWord = dict.lookupIndexWord(POS.NOUN, word);
} catch (JWNLException e) {
}
if (indexWord == null)
return false;
// ensure that the word, and not just a substring, was found in WordNet
int wordTokens = word.split("\\s", -1).length;
int wordDots = word.split("\\.", -1).length;
String lemma = indexWord.getLemma();
int lemmaTokens = lemma.split("\\s", -1).length;
int lemmaDots = lemma.split("\\.", -1).length;
return wordTokens == lemmaTokens && wordDots == lemmaDots;
}
use of net.didion.jwnl.JWNLException in project lucida by claritylab.
the class WordNet method getLemma.
/**
* Looks up the lemma of a word.
*
* @param word a word
* @param pos its part of speech
* @return lemma or <code>null</code> if lookup failed
*/
public static String getLemma(String word, POS pos) {
if (dict == null)
return null;
IndexWord indexWord = null;
try {
indexWord = dict.lookupIndexWord(pos, word);
} catch (JWNLException e) {
}
if (indexWord == null)
return null;
String lemma = indexWord.getLemma();
lemma = lemma.replace("_", " ");
return lemma;
}
Aggregations