/** * Annotate lemmas */ public Annotator morpha(Properties properties, boolean verbose) { return new MorphaAnnotator(verbose); }
@Override public void annotate(Annotation annotation) { if (VERBOSE) { log.info("Finding lemmas ..."); } Morphology morphology = new Morphology(); if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); //log.info("Lemmatizing sentence: " + tokens); for (CoreLabel token : tokens) { String text = token.get(CoreAnnotations.TextAnnotation.class); String posTag = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); addLemma(morphology, CoreAnnotations.LemmaAnnotation.class, token, text, posTag); } } } else { throw new RuntimeException("Unable to find words/tokens in: " + annotation); } }
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)); } }
annotator.annotate(document);
/** * Annotate lemmas */ public Annotator morpha(Properties properties, boolean verbose) { return new MorphaAnnotator(verbose); }
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)); } }
public void annotate(Annotation annotation) { if (VERBOSE) { System.err.print("Finding lemmas ..."); } Morphology morphology = new Morphology(); if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) { for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); //System.err.println("Lemmatizing sentence: " + tokens); for (CoreLabel token : tokens) { String text = token.get(CoreAnnotations.TextAnnotation.class); String posTag = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); addLemma(morphology, CoreAnnotations.LemmaAnnotation.class, token, text, posTag); } } } else { throw new RuntimeException("Unable to find words/tokens in: " + annotation); } }
public Annotator create() { return new MorphaAnnotator(false); } });
private static void addLemma(Morphology morpha, Class<? extends CoreAnnotation<String>> ann, CoreMap map, String word, String tag) { if (tag.length() > 0) { 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)); } }
public void annotate(Annotation annotation) { if (VERBOSE) { System.err.print("Finding lemmas ..."); } Morphology morphology = new Morphology(); if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) { for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); //System.err.println("Lemmatizing sentence: " + tokens); for (CoreLabel token : tokens) { String text = token.get(CoreAnnotations.TextAnnotation.class); String posTag = token.get(PartOfSpeechAnnotation.class); this.addLemma(morphology, LemmaAnnotation.class, token, text, posTag); } } } else { throw new RuntimeException("Unable to find words/tokens in: " + annotation); } }
@Override public Annotator create() { return new MorphaAnnotator(false); }
private static void addLemma(Morphology morpha, Class<? extends CoreAnnotation<String>> ann, CoreMap map, String word, String tag) { if (tag.length() > 0) { 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)); } }
@Override public void annotate(Annotation annotation) { if (VERBOSE) { log.info("Finding lemmas ..."); } Morphology morphology = new Morphology(); if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); //log.info("Lemmatizing sentence: " + tokens); for (CoreLabel token : tokens) { String text = token.get(CoreAnnotations.TextAnnotation.class); String posTag = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); addLemma(morphology, CoreAnnotations.LemmaAnnotation.class, token, text, posTag); } } } else { throw new RuntimeException("Unable to find words/tokens in: " + annotation); } }
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); annotator = new MorphaAnnotator(false); }