1   package eu.fbk.dkm.pikes.tintop;
2   
3   import javax.annotation.Nullable;
4   import java.io.File;
5   import java.util.Properties;
6   
7   /**
8    * Created by alessio on 15/01/16.
9    */
10  
11  public class Defaults {
12  
13      private static String[] booleanTrue = new String[] { "yes", "1", "y", "true" };
14      private static String[] booleanFalse = new String[] { "no", "0", "n", "false" };
15  
16      public static Integer getInteger(@Nullable String value, int defaultValue) {
17          try {
18              return Integer.parseInt(value);
19          } catch (Exception e) {
20              return defaultValue;
21          }
22      }
23  
24      public static Boolean getBoolean(@Nullable String value, boolean defaultValue) {
25          if (value != null) {
26              for (String s : booleanTrue) {
27                  if (value.equalsIgnoreCase(s)) {
28                      return true;
29                  }
30              }
31              for (String s : booleanFalse) {
32                  if (value.equalsIgnoreCase(s)) {
33                      return false;
34                  }
35              }
36          }
37          try {
38              return Boolean.parseBoolean(value);
39          } catch (Exception e) {
40              return defaultValue;
41          }
42      }
43  
44      public static Double getDouble(@Nullable String value, double defaultValue) {
45          try {
46              return Double.parseDouble(value);
47          } catch (Exception e) {
48              return defaultValue;
49          }
50      }
51  
52      public static Properties classProperties() {
53          Properties ret = new Properties();
54          ret.setProperty("stanford.customAnnotatorClass.simple_pos",
55                  "eu.fbk.fcw.wnpos.SimplePosAnnotator");
56          ret.setProperty("stanford.customAnnotatorClass.ukb", "eu.fbk.fcw.ukb.UKBAnnotator");
57          ret.setProperty("stanford.customAnnotatorClass.conll_parse",
58                  "eu.fbk.fcw.mate.AnnaParseAnnotator");
59          ret.setProperty("stanford.customAnnotatorClass.semafor", "eu.fbk.fcw.semafor.SemaforAnnotator");
60          ret.setProperty("stanford.customAnnotatorClass.mate", "eu.fbk.fcw.mate.MateSrlAnnotator");
61          ret.setProperty("stanford.customAnnotatorClass.mst_fake",
62                  "eu.fbk.dkm.pikes.depparseannotation.FakeMstParserAnnotator");
63          ret.setProperty("stanford.customAnnotatorClass.stanford2conll",
64                  "eu.fbk.dkm.pikes.depparseannotation.StanfordToConllDepsAnnotator");
65          ret.setProperty("stanford.customAnnotatorClass.ner_custom",
66                  "eu.fbk.fcw.ner.NERCustomAnnotator");
67          ret.setProperty("stanford.customAnnotatorClass.ner_confidence",
68                  "eu.fbk.fcw.ner.NERConfidenceAnnotator");
69          ret.setProperty("stanford.customAnnotatorClass.ner_flair",
70                  "eu.fbk.fcw.ner.NERCFlairAnnotator");
71          ret.setProperty("stanford.customAnnotatorClass.dbps", "eu.fbk.dkm.pikes.twm.LinkingAnnotator");
72          ret.setProperty("stanford.customAnnotatorClass.ml", "eu.fbk.dkm.pikes.twm.LinkingAnnotator");
73          ret.setProperty("stanford.customAnnotatorClass.el_neural", "eu.fbk.dkm.pikes.twm.LinkingAnnotator");
74  
75          // Unused
76          ret.setProperty("stanford.customAnnotatorClass.anna_pos",
77                  "eu.fbk.fcw.mate.AnnaPosAnnotator");
78          ret.setProperty("stanford.customAnnotatorClass.mst_server",
79                  "eu.fbk.fcw.mst.api.MstServerParserAnnotator");
80          ret.setProperty("stanford.customAnnotatorClass.anna_fake",
81                  "eu.fbk.dkm.pikes.tintop.annotators.FakeAnnaParserAnnotator");
82          return ret;
83      }
84  
85      public static final String MODEL_FOLDER = "models" + File.separator;
86      public static final String DEFAULT_URI = "http://pikes.fbk.eu/";
87      public static final int MAXLEN = 200;
88      public static final int MAX_TEXT_LEN = 1000;
89      public static final String ANNOTATORS = "tokenize, ssplit, dbps, pos, simple_pos, lemma, ukb, ner_custom, parse, conll_parse, mst_fake, mate, semafor, dcoref";
90  
91      public static final String PREDICATE_MATRIX = MODEL_FOLDER + "PredicateMatrix.txt";
92      public static final String WN_DICT = "wordnet" + File.separator;
93  
94      public static final String ON_FREQUENCIES = MODEL_FOLDER + "on-frequencies.tsv";
95  
96      public static void setNotPresent(Properties config) {
97          config.setProperty("stanford.annotators", config.getProperty("stanford.annotators", ANNOTATORS));
98          config.setProperty("stanford.ner_custom.maxlength",
99                  config.getProperty("stanford.ner_custom.maxlength", Integer.toString(MAXLEN)));
100         config.setProperty("stanford.parse.maxlen",
101                 config.getProperty("stanford.parse.maxlen", Integer.toString(MAXLEN)));
102         config.setProperty("default_uri", config.getProperty("default_uri", DEFAULT_URI));
103         config.setProperty("max_text_len", getInteger(config.getProperty("max_text_len"), MAX_TEXT_LEN).toString());
104     }
105 }