示例#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
 public Pair<Long, Long> findWordMemoryOffsets(int idx) {
   if (idx < 0 || idx >= idxFile.getLongWordCount()) {
     return null;
   }
   WordEntry tempEntry = idxFile.getEntryList().get((int) idx);
   return new Pair<Long, Long>(tempEntry.getLongOffset(), tempEntry.getLongSize());
 }
示例#3
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());
  }
示例#4
0
  /**
   * check if a word is in dictionary.
   *
   * @param word that is looked up in database
   * @return true if exists, false otherwise
   */
  public boolean existWord(String word) {
    int wordIndex = (int) idxFile.findIndexForWord(word);

    if (wordIndex >= idxFile.getLongWordCount()) {
      return false;
    }

    String lwrWord = word.toLowerCase();
    if (lwrWord.equals(idxFile.getEntryList().get(wordIndex).getStrLwrWord())) {
      return true;
    }

    return false;
  }
示例#5
0
 /**
  * get the nearest of the chosen word.
  *
  * @param word that is looked up in database
  * @return a list of nearest word.
  */
 public List<Word> getNearestWords(String word) {
   if (boolAvailable) {
     int idx = (int) idxFile.findIndexForWord(word);
     int nMax = nearest + idx;
     if (nMax > idxFile.getLongWordCount()) {
       nMax = (int) idxFile.getLongWordCount();
     }
     List<Word> wordList = new ArrayList<Word>();
     for (int i = idx; i < nMax; i++) {
       if (i != 0) {
         Word tempWord = new Word();
         tempWord.setStrWord(idxFile.getEntryList().get(i).getStrWord());
         tempWord.setIndex(i);
         wordList.add(tempWord);
       }
     }
     return wordList;
   }
   return null;
 }
示例#6
0
 /**
  * get a list of word entry.
  *
  * @return list of word entry
  */
 public List<WordEntry> getWordEntry() {
   return idxFile.getEntryList();
 }