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);
}
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);
}
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<>();
}
}
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<>();
}
}
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<>();
}
}
Aggregations