use of net.didion.jwnl.JWNLException in project lucida by claritylab.
the class WordNet method isCompoundWord.
/**
* Checks if the word exists in WordNet. Supports multi-token terms.
*
* @param word a word
* @return <code>true</code> iff the word is in WordNet
*/
public static boolean isCompoundWord(String word) {
if (dict == null)
return false;
// do not look up words with special characters other than '.'
if (word.matches(".*?[^\\w\\s\\.].*+"))
return false;
IndexWordSet indexWordSet = null;
try {
indexWordSet = dict.lookupAllIndexWords(word);
} catch (JWNLException e) {
}
// 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;
for (IndexWord indexWord : indexWordSet.getIndexWordArray()) {
String lemma = indexWord.getLemma();
int lemmaTokens = lemma.split("\\s", -1).length;
int lemmaDots = lemma.split("\\.", -1).length;
if (wordTokens == lemmaTokens && wordDots == lemmaDots)
return true;
}
return false;
}
use of net.didion.jwnl.JWNLException in project lucida by claritylab.
the class WordNet method getHyponyms.
/**
* Looks up hyponyms of the synset with the given POS and offset.
*
* @param pos POS of the synset
* @param offset offset of the synset
* @return hyponyms or <code>null</code> if lookup failed
*/
public static String[] getHyponyms(POS pos, long offset) {
Synset synset = null;
try {
synset = dict.getSynsetAt(pos, offset);
} catch (JWNLException e) {
}
if (synset == null)
return null;
Synset[] hyponyms = getHyponymSynsets(synset);
if (hyponyms == null)
return null;
return getLemmas(hyponyms);
}
use of net.didion.jwnl.JWNLException in project lucida by claritylab.
the class WordNet method getCommonSynset.
/**
* Looks up the most common synset of a word.
*
* @param word a word
* @param pos its part of speech
* @return synset or <code>null</code> if lookup failed
*/
private static Synset getCommonSynset(String word, POS pos) {
if (dict == null)
return null;
Synset synset = null;
try {
IndexWord indexWord = dict.lookupIndexWord(pos, word);
if (indexWord == null)
return null;
synset = indexWord.getSense(1);
} catch (JWNLException e) {
}
return synset;
}
use of net.didion.jwnl.JWNLException in project cogcomp-nlp by CogComp.
the class WordNetPlusLemmaViewGenerator method addView.
@Override
public void addView(TextAnnotation ta) {
TokenLabelView view = new TokenLabelView(getViewName(), "WordNetPlus", ta, 1.0);
for (int i = 0; i < ta.size(); i++) {
String word = ta.getToken(i).toLowerCase().trim();
String pos = WordHelpers.getPOS(ta, i);
POS wnPOS = WordNetHelper.getWNPOS(pos);
String lemma;
boolean posVerb = POSUtils.isPOSVerb(pos);
boolean knownLemma = lemmaDict.contains(word);
boolean contraction = contractions.containsKey(word);
String replaceRE = word.replace("re-", "");
boolean knownTrimmedLemma = word.startsWith("re-") && lemmaDict.contains(replaceRE);
if (posVerb && knownLemma) {
lemma = lemmaDict.get(word);
} else if (posVerb && contraction) {
lemma = contractions.get(word);
} else if (knownTrimmedLemma) {
lemma = lemmaDict.get(replaceRE);
} else if (wnPOS != null) {
try {
lemma = wn.getLemma(word, wnPOS);
} catch (JWNLException e) {
lemma = ta.getToken(i);
}
} else if (POSUtils.isPOSClosedSet(pos))
lemma = word;
else
lemma = ta.getToken(i);
view.addTokenLabel(i, lemma, 1.0);
}
ta.addView(getViewName(), view);
}
use of net.didion.jwnl.JWNLException in project cogcomp-nlp by CogComp.
the class WordNetLemmaViewGenerator method addView.
@Override
public void addView(TextAnnotation ta) {
TokenLabelView view = new TokenLabelView(getViewName(), "WordNet", ta, 1.0);
for (int i = 0; i < ta.size(); i++) {
String word = ta.getToken(i).toLowerCase().trim();
POS wnPOS = WordNetHelper.getWNPOS(WordHelpers.getPOS(ta, i));
String lemma;
if (wnPOS == null)
lemma = ta.getToken(i);
else {
try {
lemma = wn.getLemma(word, wnPOS);
} catch (JWNLException e) {
lemma = ta.getToken(i);
}
}
view.addTokenLabel(i, lemma, 1.0);
}
ta.addView(getViewName(), view);
}
Aggregations