/** If a token is a phrasal verb with an underscore between a verb and a * particle, return the phrasal verb lemmatized. If not, return null */ private static String phrasalVerb(Morphology morpha, String word, String tag) { // must be a verb and contain an underscore assert(word != null); assert(tag != null); if(!tag.startsWith("VB") || !word.contains("_")) return null; // check whether the last part is a particle String[] verb = word.split("_"); if(verb.length != 2) return null; String particle = verb[1]; if(particles.contains(particle)) { String base = verb[0]; String lemma = morpha.lemma(base, tag); return lemma + '_' + particle; } return null; }
/** * Lemmatize returning a {@code WordLemmaTag}. */ public WordLemmaTag lemmatize(WordTag wT) { String tag = wT.tag(); String word = wT.word(); String lemma = lemma(word, tag); return new WordLemmaTag(word, lemma, tag); }
private static void addLemmata(SemanticGraph sg) { sg.vertexListSorted().forEach(w -> { if(w.lemma() == null) { w.setLemma(MORPH.lemma(w.word(), w.tag())); } }); }
private static void addLemmata(Tree tree) { tree.yield().forEach(l -> { CoreLabel w = (CoreLabel) l; if(w.lemma() == null) { w.setLemma(MORPH.lemma(w.word(), w.tag())); } }); }
private static void addLemma(Morphology morpha, Class<? extends CoreAnnotation<String>> ann, CoreMap map, String word, String tag) { if ( ! tag.isEmpty()) { String phrasalVerb = phrasalVerb(morpha, word, tag); if (phrasalVerb == null) { map.set(ann, morpha.lemma(word, tag)); } else { map.set(ann, phrasalVerb); } } else { map.set(ann, morpha.stem(word)); } }
word.set(CoreAnnotations.LemmaAnnotation.class, morphology.lemma(token, posTag));
@Override public Tree transformTree(Tree t) { Morphology morphology = new Morphology(); List<TaggedWord> tagged = null; int index = 0; for (Tree leaf : t.getLeaves()) { Label label = leaf.label(); if (label == null) { continue; } String tag; if (!(label instanceof HasTag) || ((HasTag) label).tag() == null) { if (tagged == null) { tagged = t.taggedYield(); } tag = tagged.get(index).tag(); } else { tag = ((HasTag) label).tag(); } if (!(label instanceof HasLemma)) { throw new IllegalArgumentException("Got a tree with labels which do not support lemma"); } ((HasLemma) label).setLemma(morphology.lemma(label.value(), tag, true)); ++index; } return t; }
private static void processTree(Tree t, String tag, Morphology morpha) { if (t.isPreTerminal()) { tag = t.label().value(); } if (t.isLeaf()) { t.label().setValue(morpha.lemma(t.label().value(), tag)); } else { for (Tree kid : t.children()) { processTree(kid, tag, morpha); } } }
/** * Lemmatize returning a {@code WordLemmaTag}. */ public WordLemmaTag lemmatize(WordTag wT) { String tag = wT.tag(); String word = wT.word(); String lemma = lemma(word, tag); return new WordLemmaTag(word, lemma, tag); }
/** * Lemmatize returning a {@code WordLemmaTag}. */ public WordLemmaTag lemmatize(WordTag wT) { String tag = wT.tag(); String word = wT.word(); String lemma = lemma(word, tag); return new WordLemmaTag(word, lemma, tag); }
/** * Lemmatize returning a <code>WordLemmaTag </code>. */ public WordLemmaTag lemmatize(WordTag wT) { String tag = wT.tag(); String word = wT.word(); String lemma = lemma(word, tag); return new WordLemmaTag(word, lemma, tag); }
/** * Lemmatize returning a <code>WordLemmaTag </code>. */ public WordLemmaTag lemmatize(WordTag wT) { String tag = wT.tag(); String word = wT.word(); String lemma = lemma(word, tag); return new WordLemmaTag(word, lemma, tag); }
private static void addLemmata(SemanticGraph sg) { sg.vertexListSorted().forEach(w -> { if(w.lemma() == null) { w.setLemma(MORPH.lemma(w.word(), w.tag())); } }); }
private static void addLemmata(SemanticGraph sg) { sg.vertexListSorted().forEach(w -> { if(w.lemma() == null) { w.setLemma(MORPH.lemma(w.word(), w.tag())); } }); }
private static void addLemmata(Tree tree) { tree.yield().forEach(l -> { CoreLabel w = (CoreLabel) l; if(w.lemma() == null) { w.setLemma(MORPH.lemma(w.word(), w.tag())); } }); }
private static void addLemmata(Tree tree) { tree.yield().forEach(l -> { CoreLabel w = (CoreLabel) l; if(w.lemma() == null) { w.setLemma(MORPH.lemma(w.word(), w.tag())); } }); }
private static void processTree(Tree t, String tag, Morphology morpha) { if (t.isPreTerminal()) { tag = t.label().value(); } if (t.isLeaf()) { t.label().setValue(morpha.lemma(t.label().value(), tag)); } else { for (Tree kid : t.children()) { processTree(kid, tag, morpha); } } }
private static void processTree(Tree t, String tag, Morphology morpha) { if (t.isPreTerminal()) { tag = t.label().value(); } if (t.isLeaf()) { t.label().setValue(morpha.lemma(t.label().value(), tag)); } else { for (Tree kid : t.children()) { processTree(kid, tag, morpha); } } }
private void processTree(Tree t, String tag) { if (t.isPreTerminal()) { tag = t.label().value(); } if (t.isLeaf()) { t.label().setValue(morpha.lemma(t.label().value(), tag)); } else { for (Tree kid : t.children()) { processTree(kid, tag); } } }
private void processTree(Tree t, String tag, Morphology morpha) { if (t.isPreTerminal()) { tag = t.label().value(); } if (t.isLeaf()) { t.label().setValue(morpha.lemma(t.label().value(), tag)); } else { for (Tree kid : t.children()) { processTree(kid, tag, morpha); } } }