Exemple #1
0
 public DictLabel(Dictionary dict, LabelAlphabet labels) {
   this.dict = dict;
   this.mutiple = dict.isAmbiguity();
   this.labels = labels;
   idxB = labels.lookupIndex("B");
   idxM = labels.lookupIndex("M");
   idxE = labels.lookupIndex("E");
   idxS = labels.lookupIndex("S");
 }
Exemple #2
0
  public void addThruPipe(Instance instance) throws Exception {
    String[][] data = (String[][]) instance.getData();

    int length = data[0].length;
    int[][] dicData = new int[length][labels.size()];

    int indexLen = dict.getIndexLen();
    for (int i = 0; i < length; i++) {
      if (i + indexLen <= length) {
        WordInfo s = getNextN(data[0], i, indexLen);
        int[] index = dict.getIndex(s.word);
        if (index != null) {
          for (int k = 0; k < index.length; k++) {
            int n = index[k];
            if (n == indexLen) { // 下面那个check函数的特殊情况,只为了加速
              label(i, s.len, dicData);
              if (!mutiple) {
                i = i + s.len;
                break;
              }
            }
            int len = check(i, n, length, data[0], dicData);
            if (len > 0 && !mutiple) {
              i = i + len;
              break;
            }
          }
        }
      }
    }

    for (int i = 0; i < length; i++)
      if (hasWay(dicData[i])) for (int j = 0; j < dicData[i].length; j++) dicData[i][j]++;

    instance.setDicData(dicData);
  }