Пример #1
0
 // Searches for the tag in the LexEntries of the vector v
 private FreqLexEntry searchTag(String tag, Vector vector) {
   for (int i = 0; i < vector.size(); i++) {
     FreqLexEntry myEntry = (FreqLexEntry) vector.elementAt(i);
     if (myEntry.getTag().equals(tag)) return myEntry;
   }
   return null;
 }
Пример #2
0
  private int getFrequency(String word, HashMap theHash) {
    Vector entries = (Vector) theHash.get(word);
    if (entries == null) return 0;

    int frequency = 0;
    for (int i = 0; i < entries.size(); i++) {
      FreqLexEntry entry = (FreqLexEntry) entries.elementAt(i);
      frequency = frequency + entry.getFrequency();
    }
    return frequency;
  }
Пример #3
0
 private String lookup(HashMap theHash, String word) {
   Vector entries = (Vector) theHash.get(word);
   String tagStr = null;
   if (entries != null) {
     for (int i = 0; i < entries.size(); i++) {
       FreqLexEntry entry = (FreqLexEntry) entries.elementAt(i);
       if (i == 0) tagStr = entry.getTag();
       else tagStr = tagStr + "_" + entry.getTag();
     }
   }
   return tagStr;
 }
Пример #4
0
  private int getFrequencyWordTag(HashMap theHash, String word, String tag) {
    Vector entries = (Vector) theHash.get(word);
    if (entries == null) return 0;

    int frequency = 0;
    for (int i = 0; i < entries.size(); i++) {
      FreqLexEntry entry = (FreqLexEntry) entries.elementAt(i);
      if (entry.getTag().equals(tag)) {
        frequency = entry.getFrequency();
        break;
      }
    }
    return frequency;
  }
Пример #5
0
  // Builds a hash for tags of rare words used in suffix handling
  // A tag is a key, a frequency is a value
  private void storeSuffixTags(Vector vector, HashMap suffixTags /*, int howOften*/) {
    // The vector stores all the tags and frequencies to add to the hash
    for (int i = 0; i < vector.size(); i++) {
      FreqLexEntry entry = (FreqLexEntry) vector.elementAt(i); // The entry object
      String tag = entry.getTag(); // The tag string
      int freq = entry.getFrequency(); // The frequency

      Integer intObj = (Integer) suffixTags.get(tag); // Get the integer object
      if (intObj == null) // If not found
      {
        intObj = new Integer(freq);
        suffixTags.put(tag, intObj);
      } else // else increment the frequency
      {
        int theFreq = intObj.intValue();
        theFreq += freq;
        intObj = new Integer(theFreq);
        suffixTags.put(tag, intObj);
      }
    }
  }
Пример #6
0
  private void addSuffixEntry(String suffix, Vector vectorToAdd, HashMap theHashMap) {
    // We have to make copies of the entries in the vector vectorToAdd and use those entries
    // in the hashmap, because else we are manipulating the same objects (FreqLexEntry) as used in
    // the word hashmap!
    FreqLexEntry entryToAdd;
    Vector myVector = (Vector) theHashMap.get(suffix);
    if (myVector == null) // If nothing is there yet
    {

      myVector = new Vector();
      for (int i = 0; i < vectorToAdd.size(); i++) {
        entryToAdd = (FreqLexEntry) vectorToAdd.elementAt(i);
        FreqLexEntry newEntry = new FreqLexEntry(entryToAdd.getTag(), entryToAdd.getFrequency());
        myVector.add(newEntry);
      }
      theHashMap.put(
          suffix, myVector); // The suffix is the key, the value is a vector of LexEntries
    } else { // The vector is already there - its values now need to be updated
      for (int i = 0;
          i < vectorToAdd.size();
          i++) // Loop through the vector which holds entries to be added
      {
        entryToAdd = (FreqLexEntry) vectorToAdd.elementAt(i);
        String tag = entryToAdd.getTag();
        FreqLexEntry myEntry =
            searchTag(tag, myVector); // Get my entry which corresponds to this tag
        if (myEntry == null) // Then the tag was not found in the vector, add a new entry
        {
          myEntry = new FreqLexEntry(entryToAdd.getTag(), entryToAdd.getFrequency());
          myVector.add(myEntry);
        } else { // The tag was found in the vector; increment the tag frequency
          myEntry.setFrequency(myEntry.getFrequency() + entryToAdd.getFrequency());
        }
      }
    }
  }