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


Java MultiClassChunkEvalStats.score方法代码示例

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


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

示例1: evaluate

import edu.stanford.nlp.stats.MultiClassChunkEvalStats; //导入方法依赖的package包/类
public double evaluate(double[] x) {
  double score = 0;
  setValues(x);
  if (getCmd() != null) {
    evaluateCmd(getCmd());
    score = interpretCmdOutput();
  } else {
    try {
      // TODO: Classify in memory instead of writing to tmp file
      File f = File.createTempFile("CRFClassifierEvaluator","txt");
      f.deleteOnExit();
      OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(f));
      PrintWriter pw = IOUtils.encodedOutputStreamPrintWriter(outputStream, null, true);
      classifier.classifyAndWriteAnswers(data, featurizedData, pw,
                                         classifier.makeReaderAndWriter());
      outputStream.close();
      BufferedReader br = new BufferedReader(new FileReader(f));
      MultiClassChunkEvalStats stats = new MultiClassChunkEvalStats("O");
      score = stats.score(br, "\t");
      System.err.println(stats.getConllEvalString());
      f.delete();
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
  return score;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:28,代码来源:CRFClassifierEvaluator.java

示例2: main

import edu.stanford.nlp.stats.MultiClassChunkEvalStats; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        final CommandLine cmd = CommandLine
                .parser()
                .withName("./evaluate-pos")
                .withHeader("Calculate POS evaluation for Stanford")
                .withOption("t", "guessed", "Input file", "FILE",
                        CommandLine.Type.FILE_EXISTING, true, false, true)
                .withOption("g", "gold-standard", "Input gold standard file", "FILE",
                        CommandLine.Type.FILE, true, false, true)
                .withLogger(LoggerFactory.getLogger("eu.fbk")).parse(args);

        File guessed = cmd.getOptionValue("guessed", File.class);
        File gold = cmd.getOptionValue("gold-standard", File.class);

        List<String> guesses = Files.readLines(guessed, Charsets.UTF_8);
        List<String> trueLabels = Files.readLines(gold, Charsets.UTF_8);

        int total = 0;
        int correct = 0;

        for (int i = 0; i < guesses.size(); i++) {
            String guess = guesses.get(i);
            String goldLabel = trueLabels.get(i);

            if (goldLabel.equals("<eos>") || goldLabel.length() == 0) {
                continue;
            }

            total++;

            String[] parts = guess.split("\t");
            guess = parts[1];

            SimplePOS goldPos = SimplePOS.OTHER;
            SimplePOS guessedPos = SimplePOS.OTHER;

            if (goldLabel.startsWith("V")) {
                goldPos = SimplePOS.VERB;
            } else if (goldLabel.startsWith("S")) {
                goldPos = SimplePOS.NOUN;
            } else if (goldLabel.startsWith("A")) {
                goldPos = SimplePOS.ADJECTIVE;
            } else if (goldLabel.startsWith("B")) {
                goldPos = SimplePOS.ADVERB;
            }

            if (guess.startsWith("B")) {
                guessedPos = SimplePOS.ADVERB;
            } else if (guess.startsWith("V")) {
                guessedPos = SimplePOS.VERB;
            } else if (guess.startsWith("S")) {
                guessedPos = SimplePOS.NOUN;
            } else if (guess.startsWith("A")) {
                guessedPos = SimplePOS.ADJECTIVE;
            }

            if (goldPos.equals(guessedPos)) {
                correct++;
            }
        }

        System.out.println(correct);
        System.out.println(total);
        System.out.println(correct * 1.0 / total);
        System.exit(1);

        MultiClassChunkEvalStats stats = new MultiClassChunkEvalStats("O");
        stats.score(guesses, trueLabels);
        System.out.println(stats.getConllEvalString());
    } catch (Exception e) {
        CommandLine.fail(e);
    }
}
 
开发者ID:dhfbk,项目名称:tint,代码行数:75,代码来源:StanfordEvaluation.java

示例3: main

import edu.stanford.nlp.stats.MultiClassChunkEvalStats; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        final CommandLine cmd = CommandLine
                .parser()
                .withName("./evaluate-pos")
                .withHeader("Calculate POS evaluation for TreeTagger")
                .withOption("t", "guessed", "Input file", "FILE",
                        CommandLine.Type.FILE_EXISTING, true, false, true)
                .withOption("g", "gold-standard", "Input gold standard file", "FILE",
                        CommandLine.Type.FILE, true, false, true)
                .withLogger(LoggerFactory.getLogger("eu.fbk")).parse(args);

        File guessed = cmd.getOptionValue("guessed", File.class);
        File gold = cmd.getOptionValue("gold-standard", File.class);

        List<String> guesses = Files.readLines(guessed, Charsets.UTF_8);
        List<String> trueLabels = Files.readLines(gold, Charsets.UTF_8);

        for (int i = 0; i < trueLabels.size(); i++) {
            String label = trueLabels.get(i);
            if (label.trim().length() == 0) {
                trueLabels.remove(i);
            }
        }

        int total = 0;
        int correct = 0;

        for (int i = 0; i < guesses.size(); i++) {
            String guess = guesses.get(i);
            String goldLabel = trueLabels.get(i);

            if (goldLabel.equals("<eos>")) {
                continue;
            }

            total++;

            String[] parts = guess.split("\t");
            guess = parts[1];

            SimplePOS goldPos = SimplePOS.OTHER;
            SimplePOS guessedPos = SimplePOS.OTHER;

            if (goldLabel.startsWith("V")) {
                goldPos = SimplePOS.VERB;
            } else if (goldLabel.startsWith("S")) {
                goldPos = SimplePOS.NOUN;
            } else if (goldLabel.startsWith("A")) {
                goldPos = SimplePOS.ADJECTIVE;
            } else if (goldLabel.startsWith("B")) {
                goldPos = SimplePOS.ADVERB;
            }

            if (guess.startsWith("ADV")) {
                guessedPos = SimplePOS.ADVERB;
            } else if (guess.startsWith("VER")) {
                guessedPos = SimplePOS.VERB;
            } else if (guess.startsWith("NOM")) {
                guessedPos = SimplePOS.NOUN;
            } else if (guess.startsWith("ADJ")) {
                guessedPos = SimplePOS.ADJECTIVE;
            }

            if (goldPos.equals(guessedPos)) {
                correct++;
            }
        }

        System.out.println(correct);
        System.out.println(total);
        System.out.println(correct * 1.0 / total);
        System.exit(1);

        MultiClassChunkEvalStats stats = new MultiClassChunkEvalStats("O");
        stats.score(guesses, trueLabels);
        System.out.println(stats.getConllEvalString());
    } catch (Exception e) {
        CommandLine.fail(e);
    }
}
 
开发者ID:dhfbk,项目名称:tint,代码行数:82,代码来源:TreeTaggerEvaluation.java


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