Ejemplo n.º 1
1
  public static synchronized Dictionary initializeWordNet() {

    if (wordnet != null) return wordnet;

    try {
      String propsFileText = FileUtils.readFile(Utils.class.getResourceAsStream(propsFile));
      Map<String, String> map = Maps.newTreeMap();
      map.put("WordNet_dictionary_path", Utils.getConfig().getString("WordNet_dictionary_path"));
      propsFileText = StringUtil.macroReplace(propsFileText, map);
      JWNL.initialize(new StringInputStream(propsFileText));
      // JWNL.initialize(new FileInputStream(propsFile));
      wordnet = Dictionary.getInstance();
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }

    SUPERTYPE_SYNSETS = new Synset[SUPERTYPES.length];
    Synset[] classSynset;
    IndexWord iw;
    int count = 0;
    for (String type : SUPERTYPES) {
      try {
        iw = wordnet.getIndexWord(POS.NOUN, type);
      } catch (JWNLException e) {
        throw new RuntimeException(e);
      }
      if (iw == null) {
        System.err.println(type);
        continue;
      }

      try {
        classSynset = iw.getSenses();
      } catch (JWNLException e) {
        throw new RuntimeException(e);
      }
      // System.err.println("**********************");
      if (classSynset.length > 1) {
        // for(Synset cs:classSynset)
        // System.err.println(cs);
        if (type.equals("abstraction")) {
          SUPERTYPE_SYNSETS[count] = classSynset[5];
        } else if (type.equals("measure")) {
          SUPERTYPE_SYNSETS[count] = classSynset[2];
        } else if (type.equals("state")) {
          SUPERTYPE_SYNSETS[count] = classSynset[3];
        } else if (type.equals("act")) {
          SUPERTYPE_SYNSETS[count] = classSynset[1];
        } else {
          SUPERTYPE_SYNSETS[count] = classSynset[0];
        }
      }
      count++;
    }
    if (wordnet == null) throw new RuntimeException("WordNet not intialized");
    else {
      System.out.println("Wordnet initialized " + wordnet);
    }
    return wordnet;
  }
 public NamedEntityTagChunk() {
   /* defaults */
   currentConfig = Utils.getConfig();
   modelDir = Utils.getDataDirectory();
   models = currentConfig.getNERModels("tagchunkmodels");
 }
 /**
  * Trains a classifier using the feature files housed in the training directories in the Config.
  *
  * @param options - a string array of various options used in training (e.g. - where to save the
  *     model file, training parameters, etc.)
  */
 public void train(File trainFile, File outputModelFile) {
   if (mOptions == null) {
     mOptions = Utils.getConfig().getStringArray("ClOptions." + getName());
   }
   train(trainFile, outputModelFile, mOptions);
 }
 /**
  * Classifies the instances located in the test directories in the Config.
  *
  * @param options - a string array of various options used in testing (e.g. - where to load the
  *     model file, testing parameters, etc.)
  * @return the minimum and maximum numerical values of the classified instances
  */
 public double[] test(Reader testFile, Writer outputFile) {
   if (mOptions == null) {
     mOptions = Utils.getConfig().getStringArray("ClOptions." + getName());
   }
   return test(testFile, outputFile, mOptions);
 }