Пример #1
0
 /**
  * Add list of word to idx, dict file, modify size .ifo file.
  *
  * @param pWord word that is added
  * @param pMean word mean
  * @return true if success
  */
 public boolean addListOfWords(String[] pWord, String[] pMean) {
   if (pWord.length != pMean.length || pWord.length == 0) {
     return false;
   }
   try {
     for (int i = 0; i < pWord.length; i++) {
       String strLwrWord = pWord[i].toLowerCase();
       int pos = (int) idxFile.findIndexForWord(strLwrWord);
       boolean bExist = false;
       if (pos < (int) idxFile.getLongWordCount()) {
         if (strLwrWord.compareTo(((WordEntry) idxFile.getEntryList().get(pos)).getStrLwrWord())
             == 0) {
           bExist = true;
         }
       }
       long nextOffset = dictFile.addData(pMean[i]);
       if (nextOffset >= 0) {
         if (!bExist) {
           idxFile.addEntry(pWord[i], nextOffset, pMean[i].length(), pos);
         } else {
           WordEntry tempEntry = idxFile.getEntryList().get(pos);
           tempEntry.setLongOffset(nextOffset);
           tempEntry.setLongSize(pMean[i].length());
         }
       }
     }
     idxFile.write();
     ifoFile.setLongIdxFileSize(idxFile.getLongIdxFileSize());
     ifoFile.setLongWordCount(idxFile.getLongWordCount());
     ifoFile.write();
   } catch (Exception ex) {
     return false;
   }
   return true;
 }
Пример #2
0
  /**
   * lookup a word by its index.
   *
   * @param idx index of a word
   * @return word data
   */
  public String lookupWord(int idx) {
    if (idx < 0 || idx >= idxFile.getLongWordCount()) {
      return null;
    }
    WordEntry tempEntry = idxFile.getEntryList().get((int) idx);

    return dictFile.getWordData(tempEntry.getLongOffset(), tempEntry.getLongSize());
  }