1   package eu.fbk.dh.tint.readability.gl;
2   
3   import com.itextpdf.layout.hyphenation.Hyphenation;
4   import com.itextpdf.layout.hyphenation.Hyphenator;
5   import edu.stanford.nlp.ling.CoreLabel;
6   import edu.stanford.nlp.pipeline.Annotation;
7   import edu.stanford.nlp.util.CoreMap;
8   import eu.fbk.dh.tint.readability.Readability;
9   import eu.fbk.dh.tint.readability.ReadabilityAnnotations;
10  import eu.fbk.utils.gson.JSONExclude;
11  
12  import java.util.Properties;
13  
14  /**
15   * Created by alessio on 21/09/16.
16   */
17  
18  abstract class GalicianReadability extends Readability {
19  
20      @JSONExclude GalicianReadabilityModel model;
21      @JSONExclude int level1WordSize = 0, level2WordSize = 0, level3WordSize = 0;
22  
23      public static void main(String[] args) {
24          Hyphenator hyphenator = new Hyphenator("gl", "es", 1, 1);
25          Hyphenation produción = hyphenator.hyphenate("produción");
26          System.out.println(produción);
27      }
28  
29      @Override public void finalizeReadability() {
30          super.finalizeReadability();
31  
32          double fleschSzigriszt =
33                  206.835 - (62.3 * getHyphenCount() / getHyphenWordCount()) - (1.0 * getWordCount()
34                          / getSentenceCount());
35          double fernandezHuerta =
36                  206.84 - 0.6 * (100.0 * getHyphenCount() / getHyphenWordCount()) - 1.02 * (100.0 * getSentenceCount()
37                          / getWordCount());
38          labels.put("main", "Flesch-Szigriszt");
39          measures.put("main", fleschSzigriszt);
40          measures.put("fernandez-huerta", fernandezHuerta);
41          measures.put("level1", 100.0 * level1WordSize / getContentWordSize());
42          measures.put("level2", 100.0 * level2WordSize / getContentWordSize());
43          measures.put("level3", 100.0 * level3WordSize / getContentWordSize());
44  
45      }
46  
47      public GalicianReadability(Properties globalProperties, Properties localProperties, Annotation annotation) {
48          super("gl", annotation, localProperties);
49          hyphenator = new Hyphenator("es", "es", 1, 1);
50          model = GalicianReadabilityModel.getInstance(globalProperties, localProperties);
51      }
52  
53      @Override public void addingContentWord(CoreLabel token) {
54          super.addingContentWord(token);
55  
56          token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 4);
57          String lemma = token.lemma();
58          if (model.getLevel3Lemmas().contains(lemma)) {
59              level3WordSize++;
60              token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 3);
61          }
62          if (model.getLevel2Lemmas().contains(lemma)) {
63              level2WordSize++;
64              token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 2);
65          }
66          if (model.getLevel1Lemmas().contains(lemma)) {
67              level1WordSize++;
68              token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 1);
69          }
70      }
71  
72      @Override public void addingEasyWord(CoreLabel token) {
73  
74      }
75  
76      @Override public void addingWord(CoreLabel token) {
77          super.addingWord(token);
78      }
79  
80      @Override public void addingToken(CoreLabel token) {
81      }
82  
83      @Override public void addingSentence(CoreMap sentence) {
84  
85      }
86  }