1   package eu.fbk.dh.tint.inverse.digimorph.annotator;
2   
3   import edu.stanford.nlp.ling.CoreAnnotation;
4   import edu.stanford.nlp.ling.CoreAnnotations;
5   import edu.stanford.nlp.ling.CoreLabel;
6   import edu.stanford.nlp.pipeline.Annotation;
7   import edu.stanford.nlp.pipeline.Annotator;
8   import edu.stanford.nlp.util.CoreMap;
9   import eu.fbk.dh.tint.digimorph.annotator.DigiMorphAnnotations;
10  
11  import java.util.Collections;
12  import java.util.List;
13  import java.util.Set;
14  
15  /**
16   * Created by giovannimoretti on 31/01/17.
17   */
18  
19  public class DigiInverseMorphAnnotator implements Annotator {
20  
21      public void annotate(Annotation annotation) {
22          if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
23              for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
24                  List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
25                  for (CoreLabel c : tokens) {
26                      String[] morph_features = c.get(DigiMorphAnnotations.MorphoAnnotation.class).split(" ");
27  
28                      c.set(DigiInverseMorphAnnotations.InverseMorphoAnnotation.class, morph_features[0]);
29  
30                  }
31              }
32          }
33  
34      }
35  
36      /**
37       * Returns a set of requirements for which tasks this annotator can
38       * provide.  For example, the POS annotator will return "pos".
39       */
40      @Override public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {
41          return Collections.singleton(DigiInverseMorphAnnotations.InverseMorphoAnnotation.class);
42      }
43  
44      /**
45       * Returns the set of tasks which this annotator requires in order
46       * to perform.  For example, the POS annotator will return
47       * "tokenize", "ssplit".
48       */
49      @Override public Set<Class<? extends CoreAnnotation>> requires() {
50          return Collections.singleton(DigiMorphAnnotations.MorphoAnnotation.class);
51      }
52  }