Exemplo 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;
  }
Exemplo n.º 2
0
  public void init() {
    FileInputStream propertiesStream;
    try {
      propertiesStream = new FileInputStream(CONFIG_PATH + FILE_CONFIG_NAME);
      JWNL.initialize(propertiesStream);
      // tagger = new StandfordTagger();
      // tagger.init();

      wordnet = Dictionary.getInstance();
      relationFinder = RelationshipFinder.getInstance();
    } catch (JWNLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (FileNotFoundException ef) {
      // TODO Auto-generated catch block
      ef.printStackTrace();
    }
  }
Exemplo n.º 3
0
  private WordNetAPI(String propsFile) throws Exception {

    info("Initialize WordNet...: ");

    if (propsFile == null) {
      throw new RuntimeException("Missing required property 'WN_PROP'");
    }

    try {
      JWNL.initialize(new FileInputStream(propsFile));
      wDict = Dictionary.getInstance();
      pUtils = PointerUtils.getInstance();
      morphProcessor = wDict.getMorphologicalProcessor();
    } catch (Exception e) {
      throw new RuntimeException("Initialization failed", e);
    }
    info("Done initializing WordNet...");
  }