예제 #1
0
 public void addBranchPath(String word, int offset) {
   char c;
   DictIndex0Item child = this;
   int len = word.length();
   for (int i = 0; i <= len; i++) {
     c = i == len ? 0 : word.charAt(i);
     child = child.getItem(c);
     if (i == len) child.index2Offset = offset;
   }
 }
예제 #2
0
 private DictIndex0Item getItem(char c) { // if none in map, put a new one
   Character cr = new Character(Character.toUpperCase(c));
   DictIndex0Item child = (DictIndex0Item) childrenItemMap.get(cr);
   if (child == null) {
     child = new DictIndex0Item();
     child.setChar(c);
     childrenItemMap.put(cr, child);
   }
   return child;
 }
예제 #3
0
 void print(DictIndex0Item child) {
   Logger.info_("[");
   Logger.info_(getPadded(Integer.toHexString(child.index0Offset), 5));
   Logger.info_("]");
   Logger.info_(getPadded("", deep << 1));
   Logger.info_("'");
   Logger.info_(child.c == 0 ? '□' : child.c);
   Logger.info_("'(");
   Logger.info_(getPadded(Integer.toHexString(child.getChildrenSize()), 2));
   Logger.info_(")_[");
   Logger.info_(getPadded(Integer.toHexString(child.getValue()), 8));
   Logger.info("]");
 }
예제 #4
0
  int traverse(DictIndex0Item item, int type, List itemsList) {
    int result = 0;
    Iterator i = item.childrenItemMap.values().iterator();
    DictIndex0Item child;
    boolean firstChild = true;
    int childrenNum = item.childrenItemMap.size();
    int pathNum;
    while (i.hasNext()) {
      child = (DictIndex0Item) i.next();
      switch (type) {
        case GET_CHILDREN_NUM:
          result = childrenNum;
          break;
        case GET_OFFSET:
          offset_ += 8;
          child.index0Offset = offset_;
          break;
        case GET_1STCLD_OFFSET:
          if (firstChild) {
            item.firstChildIndex0Offset = child.index0Offset;
            firstChild = false;
          }
          break;
        case GET_PATH_NUM:
          break;
        case GET_LIST:
          itemsList.add(child);
          break;
        case REMOVE_SMALLITEMS:
          pathNum = traverse(child, GET_PATH_NUM, itemsList);
          if (pathNum <= minwords) {
            child.childrenSize = pathNum;
            child.removeChildren();
          }
          break;
        case PRINT:
          print(child);
      }
    }

    i = item.childrenItemMap.values().iterator();
    while (i.hasNext()) {
      deep++;
      child = (DictIndex0Item) i.next();
      result += traverse(child, type, itemsList);
    }
    if (item.childrenItemMap.size() == 0 && type == GET_PATH_NUM) result = 1;

    deep--;
    return result;
  }
예제 #5
0
 public static void main(String[] args) {
   DictIndex0Item root = new DictIndex0Item();
   root.minwords = 1;
   root.setChar((char) 0);
   root.addBranchPath("A", 0x00);
   root.addBranchPath("AC", 0x10);
   root.addBranchPath("ACH", 0x20);
   root.addBranchPath("AD", 0x30);
   root.addBranchPath("ADG", 0x40);
   root.addBranchPath("B", 0x50);
   root.addBranchPath("BE", 0x60);
   root.addBranchPath("BF", 0x70);
   root.addBranchPath("BFI", 0x80);
   root.addBranchPath("T", 0x90);
   root.addBranchPath("TI", 0xa0);
   root.prepare();
   root.debug();
 }