コード例 #1
0
 // do not use cachedToString
 @Deprecated
 public String toString(SymbolTable symbolTable) {
   StringBuffer sb = new StringBuffer();
   sb.append(symbolTable.getWord(this.lhs));
   sb.append(" ||| ");
   sb.append(symbolTable.getWords(this.pFrench));
   sb.append(" |||");
   for (int i = 0; i < this.featScores.length; i++) {
     sb.append(String.format(" %.4f", this.featScores[i]));
   }
   return sb.toString();
 }
コード例 #2
0
  @Deprecated
  public String toStringWithoutFeatScores(SymbolTable symbolTable) {
    StringBuffer sb = new StringBuffer();
    if (symbolTable == null) sb.append(this.getLHS());
    else sb.append(symbolTable.getWord(this.getLHS()));

    return sb.append(" ||| ").append(convertToString(this.getFrench(), symbolTable)).toString();
  }
コード例 #3
0
  public String convertToString(int[] words, SymbolTable symbolTable) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < words.length; i++) {
      if (symbolTable != null) sb.append(symbolTable.getWord(words[i]));
      else sb.append(words[i]);

      if (i < words.length - 1) sb.append(" ");
    }
    return sb.toString();
  }
コード例 #4
0
 @Deprecated
 public String toString(
     Map<Integer, String> ntVocab, SymbolTable sourceVocab, SymbolTable targetVocab) {
   if (null == this.cachedToString) {
     StringBuffer sb = new StringBuffer();
     sb.append(ntVocab.get(this.lhs));
     sb.append(" ||| ");
     sb.append(sourceVocab.getWords(this.pFrench, true));
     sb.append(" |||");
     for (int i = 0; i < this.featScores.length; i++) {
       // sb.append(String.format(" %.4f", this.feat_scores[i]));
       sb.append(' ').append(Float.toString(this.featScores[i]));
     }
     this.cachedToString = sb.toString();
   }
   return this.cachedToString;
 }
コード例 #5
0
ファイル: Ngram.java プロジェクト: nano5th/joshua
  /** if symbolTbl!=null, then convert string to integer */
  public static void getNgrams(
      SymbolTable symbolTbl,
      Map<String, Integer> tbl,
      int startOrder,
      int endOrder,
      final String[] wrds) {

    for (int i = 0; i < wrds.length; i++)
      for (int j = startOrder - 1; j < endOrder && j + i < wrds.length; j++) { // ngram: [i,i+j]
        StringBuffer ngram = new StringBuffer();
        for (int k = i; k <= i + j; k++) {
          String t_wrd = wrds[k];
          if (symbolTbl != null) ngram.append(symbolTbl.getID(t_wrd));
          else ngram.append(t_wrd);
          if (k < i + j) ngram.append(" ");
        }
        String ngramStr = ngram.toString();
        increaseCount(tbl, ngramStr, 1);
      }
  }