Search in sources :

Example 6 with JWNLException

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;
}
Also used : JWNLException(net.didion.jwnl.JWNLException) IndexWord(net.didion.jwnl.data.IndexWord)

Example 7 with JWNLException

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;
}
Also used : JWNLException(net.didion.jwnl.JWNLException) IndexWord(net.didion.jwnl.data.IndexWord)

Aggregations

JWNLException (net.didion.jwnl.JWNLException)7 IndexWord (net.didion.jwnl.data.IndexWord)4 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)2 POS (net.didion.jwnl.data.POS)2 Synset (net.didion.jwnl.data.Synset)2 IndexWordSet (net.didion.jwnl.data.IndexWordSet)1