Search in sources :

Example 1 with JWNLException

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

Example 2 with JWNLException

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

Example 3 with JWNLException

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

Example 4 with JWNLException

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);
}
Also used : POS(net.didion.jwnl.data.POS) TokenLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView) JWNLException(net.didion.jwnl.JWNLException)

Example 5 with JWNLException

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);
}
Also used : POS(net.didion.jwnl.data.POS) TokenLabelView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView) JWNLException(net.didion.jwnl.JWNLException)

Aggregations

JWNLException (net.didion.jwnl.JWNLException)10 IndexWord (net.didion.jwnl.data.IndexWord)4 InvalidEndpointException (io.minio.errors.InvalidEndpointException)3 InvalidPortException (io.minio.errors.InvalidPortException)3 IOException (java.io.IOException)3 DatastoreException (org.cogcomp.DatastoreException)3 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)2 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)2 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)2 ResourceConfigurator (edu.illinois.cs.cogcomp.core.resources.ResourceConfigurator)2 WordNetManager (edu.illinois.cs.cogcomp.edison.utilities.WordNetManager)2 BrownClusters (edu.illinois.cs.cogcomp.ner.ExpressiveFeatures.BrownClusters)2 FlatGazetteers (edu.illinois.cs.cogcomp.ner.ExpressiveFeatures.FlatGazetteers)2 Gazetteers (edu.illinois.cs.cogcomp.ner.ExpressiveFeatures.Gazetteers)2 POSAnnotator (edu.illinois.cs.cogcomp.pos.POSAnnotator)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 POS (net.didion.jwnl.data.POS)2 Synset (net.didion.jwnl.data.Synset)2