Example #1
0
 /**
  * This method returns a map format set of the result.
  *
  * @return
  */
 public HashMap<String, String> getMappedResult() {
   if (_result != null) return _result;
   _result = new HashMap<String, String>();
   for (ArrayList<Phrase> pa : phrases) {
     for (Phrase p : pa) {
       String ps = p.toString();
       _result.put(ps, p.phraseType.toString());
     }
   }
   return _result;
 }
Example #2
0
  /**
   * This method process the whole input result set and gives all _phrases in the set a name type.
   *
   * @param resultSet
   * @return
   */
  public NERResultSet process(NERResultSet resultSet) {
    // store the relationship of _phrases in memory for further use
    HashMap<Phrase, HashSet<Phrase>> phraseInMemory = new HashMap<Phrase, HashSet<Phrase>>();

    // scoring
    ArrayList<ArrayList<Phrase>> _phrases = resultSet.phrases;
    for (int si = 0; si < _phrases.size(); si++) {
      // for each sentence
      ArrayList<Phrase> phrasesInSentence = _phrases.get(si);
      for (int pi = 0; pi < phrasesInSentence.size(); pi++) {
        // for each phrase in the sentence
        Phrase p = phrasesInSentence.get(pi);
        if (p.isDate) continue;
        for (int scoreIndex = 0; scoreIndex < _config.name_type.length; scoreIndex++) {
          // score all the dimensions
          p.score[scoreIndex] = _fm.score(p, scoreIndex);
        }

        boolean flag = false;
        for (Phrase keyPhrase : phraseInMemory.keySet()) {
          if (p.isSubPhraseOf(keyPhrase)) {
            phraseInMemory.get(keyPhrase).add(p);
            flag = true;
            break;
          }
        }
        if (!flag || p.phrase.length > 1) {
          HashSet<Phrase> newSet = new HashSet<Phrase>();
          newSet.add(p);
          phraseInMemory.put(p, newSet);
        }
      }
    }

    // copy the score of _phrases that have relationships:
    for (Phrase key : phraseInMemory.keySet()) {
      HashSet<Phrase> aSet = phraseInMemory.get(key);
      /*
      double[] score = new double[config.name_type.length];
      for(Phrase phrase : aSet) {
      	for(int i = 0; i < config.name_type.length; i++)
      		score[i] += phrase.score[i];
      	phrase.score = score;
      }
      */
      double[] score = key.score;
      for (Phrase phrase : aSet) {
        phrase.classify(_config.name_type);
        if (phrase.phraseType == NameType.NULL_TYPE) {
          phrase.score = score;
          phrase.classify(_config.name_type);
        }
      }
      for (Phrase phrase : aSet) {}
    }
    return resultSet;
  }