当前位置: 首页>>代码示例>>Java>>正文


Java PrintFile.print方法代码示例

本文整理汇总了Java中edu.stanford.nlp.io.PrintFile.print方法的典型用法代码示例。如果您正苦于以下问题:Java PrintFile.print方法的具体用法?Java PrintFile.print怎么用?Java PrintFile.print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.io.PrintFile的用法示例。


在下文中一共展示了PrintFile.print方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save_problem

import edu.stanford.nlp.io.PrintFile; //导入方法依赖的package包/类
/**
 * This method writes the problem data into a file, which is good for reading
 * with MatLab.  It could also have other applications,
 * like reducing the memory requirements
 */

void save_problem(String filename) {
  try {
    PrintFile pf = new PrintFile(filename);
    int N = p.data.xSize;
    int M = p.data.ySize;
    int F = p.fSize;
    // byte[] nl = "\n".getBytes();
    // byte[] dotsp = ". ".getBytes();
    // int space = (int) ' ';
    // write the sizes of X, Y, and F( number of features );
    pf.println(N);
    pf.println(M);
    pf.println(F);
    // save the objective vector like 1.c0, ... ,N*M. cN*M-1
    for (int i = 0; i < N * M; i++) {
      pf.print(i + 1);
      pf.print(". ");
      pf.println(p.data.ptildeX(i / M));
    }// for i

    // save the constraints matrix B
    // for each feature , save its row
    for (int i = 0; i < p.fSize; i++) {
      int[] values = p.functions.get(i).indexedValues;
      for (int k = 0; k < values.length; k++) {
        pf.print(i + 1);
        pf.print(". ");
        pf.print(values[k]);
        pf.print(" ");
        pf.println(1);
      }// k

    }// i

    // save the constraints vector
    // for each feature, save its empirical expectation

    for (int i = 0; i < p.fSize; i++) {
      pf.print(i + 1);
      pf.print(". ");
      pf.println(ftildeArr[i]);
    }// end
    pf.close();

  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:55,代码来源:LambdaSolve.java

示例2: writeTagsAndErrors

import edu.stanford.nlp.io.PrintFile; //导入方法依赖的package包/类
/** Write the tagging and note any errors (if pf != null) and accumulate
 *  global statistics.
 *
 *  @param finalTags Chosen tags for sentence
 *  @param pf File to write tagged output to (can be null, then no output;
 *               at present it is non-null iff the debug property is set)
 */
protected void writeTagsAndErrors(String[] finalTags, PrintFile pf, boolean verboseResults) {
  StringWriter sw = new StringWriter(200);
  for (int i = 0; i < correctTags.length; i++) {
    sw.write(toNice(sent.get(i)));
    sw.write(tagSeparator);
    sw.write(finalTags[i]);
    sw.write(' ');
    if (pf != null) {
      pf.print(toNice(sent.get(i)));
      pf.print(tagSeparator);
      pf.print(finalTags[i]);
    }
    if ((correctTags[i]).equals(finalTags[i])) {
      numRight++;
    } else {
      numWrong++;
      if (pf != null) pf.print('|' + correctTags[i]);
      if (verboseResults) {
        EncodingPrintWriter.err.println((maxentTagger.dict.isUnknown(sent.get(i)) ? "Unk" : "") + "Word: " + sent.get(i) + "; correct: " + correctTags[i] + "; guessed: " + finalTags[i], encoding);
      }

      if (maxentTagger.dict.isUnknown(sent.get(i))) {
        numWrongUnknown++;
        if (pf != null) pf.print("*");
      }// if
    }// else
    if (pf != null) pf.print(' ');
  }// for
  if (pf != null) pf.println();

  if (verboseResults) {
    PrintWriter pw;
    try {
      pw = new PrintWriter(new OutputStreamWriter(System.out, encoding), true);
    } catch (UnsupportedEncodingException uee) {
      pw = new PrintWriter(new OutputStreamWriter(System.out), true);
    }
    pw.println(sw);
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:48,代码来源:TestSentence.java

示例3: printUnknown

import edu.stanford.nlp.io.PrintFile; //导入方法依赖的package包/类
/**
 * This method should be called after the sentence has been tagged.
 * For every unknown word, this method prints the 3 most probable tags
 * to the file pfu.
 *
 * @param numSent The sentence number
 * @param pfu The file to print the probable tags to
 */
void printUnknown(int numSent, PrintFile pfu) {
  NumberFormat nf = new DecimalFormat("0.0000");
  int numTags = maxentTagger.tags.getSize();
  double[][][] probabilities = new double[size][kBestSize][numTags];
  calculateProbs(probabilities);
  for (int current = 0; current < size; current++) {
    if (maxentTagger.dict.isUnknown(sent.get(current))) {
      pfu.print(sent.get(current));
      pfu.print(':');
      pfu.print(numSent);
      double[] probs = new double[3];
      String[] tag3 = new String[3];
      getTop3(probabilities, current, probs, tag3);
      for (int i = 0; i < 3; i++) {
        if (probs[i] > Double.NEGATIVE_INFINITY) {
          pfu.print('\t');
          pfu.print(tag3[i]);
          pfu.print(' ');
          pfu.print(nf.format(Math.exp(probs[i])));
        }
      }
      int rank;
      String correctTag = toNice(this.correctTags[current]);
      for (rank = 0; rank < 3; rank++) {
        if (correctTag.equals(tag3[rank])) {
          break;
        } //if
      }
      pfu.print('\t');
      switch (rank) {
        case 0:
          pfu.print("Correct");
          break;
        case 1:
          pfu.print("2nd");
          break;
        case 2:
          pfu.print("3rd");
          break;
        default:
          pfu.print("Not top 3");
      }
      pfu.println();
    }// if
  }// for
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:55,代码来源:TestSentence.java

示例4: printTop

import edu.stanford.nlp.io.PrintFile; //导入方法依赖的package包/类
void printTop(PrintFile pfu) {
  NumberFormat nf = new DecimalFormat("0.0000");
  int numTags = maxentTagger.tags.getSize();
  double[][][] probabilities = new double[size][kBestSize][numTags];
  calculateProbs(probabilities);
  for (int current = 0; current < size; current++) {
    pfu.print(sent.get(current));
    double[] probs = new double[3];
    String[] tag3 = new String[3];
    getTop3(probabilities, current, probs, tag3);
    for (int i = 0; i < 3; i++) {
      if (probs[i] > Double.NEGATIVE_INFINITY) {
        pfu.print('\t');
        pfu.print(tag3[i]);
        pfu.print(' ');
        pfu.print(nf.format(Math.exp(probs[i])));
      }
    }
    int rank;
    String correctTag = toNice(this.correctTags[current]);
    for (rank = 0; rank < 3; rank++) {
      if (correctTag.equals(tag3[rank])) {
        break;
      } //if
    }
    pfu.print('\t');
    switch (rank) {
    case 0:
      pfu.print("Correct");
      break;
    case 1:
      pfu.print("2nd");
      break;
    case 2:
      pfu.print("3rd");
      break;
    default:
      pfu.print("Not top 3");
    }
    pfu.println();
  } // for
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:43,代码来源:TestSentence.java


注:本文中的edu.stanford.nlp.io.PrintFile.print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。