Search in sources :

Example 1 with POS

use of net.didion.jwnl.data.POS 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)

Example 2 with POS

use of net.didion.jwnl.data.POS 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 3 with POS

use of net.didion.jwnl.data.POS in project cogcomp-nlp by CogComp.

the class WordHelpers method getHypernyms.

public static List<String> getHypernyms(TextAnnotation ta, int tokenId, WordNetManager wnManager) throws JWNLException {
    String word = getWord(ta, tokenId).toLowerCase();
    String wordPOS = getPOS(ta, tokenId);
    if (POSUtils.isPOSOpenSet(wordPOS)) {
        POS wnPos = getWNPOS(wordPOS);
        return wnManager.getHypernyms(word, wnPos, true);
    } else {
        return new ArrayList<>();
    }
}
Also used : POS(net.didion.jwnl.data.POS) ArrayList(java.util.ArrayList)

Example 4 with POS

use of net.didion.jwnl.data.POS in project cogcomp-nlp by CogComp.

the class WordHelpers method getHypernymsMostFrequentSense.

public static List<String> getHypernymsMostFrequentSense(TextAnnotation ta, int tokenId, WordNetManager wnManager) throws JWNLException {
    String word = getWord(ta, tokenId).toLowerCase();
    String wordPOS = getPOS(ta, tokenId);
    if (POSUtils.isPOSOpenSet(wordPOS)) {
        POS wnPos = getWNPOS(wordPOS);
        return wnManager.getHypernyms(word, wnPos, false);
    } else {
        return new ArrayList<>();
    }
}
Also used : POS(net.didion.jwnl.data.POS) ArrayList(java.util.ArrayList)

Example 5 with POS

use of net.didion.jwnl.data.POS in project cogcomp-nlp by CogComp.

the class WordHelpers method getSynsetMostFrequentSense.

public static List<String> getSynsetMostFrequentSense(TextAnnotation ta, int tokenId, WordNetManager wnManager) throws JWNLException {
    String word = getWord(ta, tokenId).toLowerCase();
    String wordPOS = getPOS(ta, tokenId);
    if (POSUtils.isPOSOpenSet(wordPOS)) {
        POS wnPos = getWNPOS(wordPOS);
        return wnManager.getSynonyms(word, wnPos, true);
    } else {
        return new ArrayList<>();
    }
}
Also used : POS(net.didion.jwnl.data.POS) ArrayList(java.util.ArrayList)

Aggregations

POS (net.didion.jwnl.data.POS)7 ArrayList (java.util.ArrayList)4 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)2 JWNLException (net.didion.jwnl.JWNLException)2 Ontology (info.ephyra.nlp.semantics.ontologies.Ontology)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1