本文整理汇总了Java中edu.stanford.nlp.stats.MultiClassChunkEvalStats类的典型用法代码示例。如果您正苦于以下问题:Java MultiClassChunkEvalStats类的具体用法?Java MultiClassChunkEvalStats怎么用?Java MultiClassChunkEvalStats使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MultiClassChunkEvalStats类属于edu.stanford.nlp.stats包,在下文中一共展示了MultiClassChunkEvalStats类的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;
}
示例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);
}
}
示例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);
}
}