All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.parser.metrics.TaggingEval Maven / Gradle / Ivy

Go to download

Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.

There is a newer version: 4.5.7
Show newest version
package edu.stanford.nlp.parser.metrics; 
import edu.stanford.nlp.util.logging.Redwood;

import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;

import edu.stanford.nlp.international.Language;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.HasTag;
import edu.stanford.nlp.ling.Label;
import edu.stanford.nlp.parser.lexparser.EnglishTreebankParserParams;
import edu.stanford.nlp.parser.lexparser.Lexicon;
import edu.stanford.nlp.parser.lexparser.TreebankLangParserParams;
import edu.stanford.nlp.stats.ClassicCounter;
import edu.stanford.nlp.stats.Counter;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeTransformer;
import edu.stanford.nlp.trees.Treebank;
import edu.stanford.nlp.util.Generics;
import edu.stanford.nlp.util.StringUtils;

/**
 * Computes POS tagging P/R/F1 from guess/gold trees. This version assumes that the yields match. For
 * trees with potentially different yields, use {@link TsarfatyEval}.
 * 

* This implementation assumes that the guess/gold input files are of equal length, and have one tree per * line. * * @author Spence Green * */ public class TaggingEval extends AbstractEval { /** A logger for this class */ private static Redwood.RedwoodChannels log = Redwood.channels(TaggingEval.class); private final Lexicon lex; private static boolean doCatLevelEval = false; private Counter precisions; private Counter recalls; private Counter f1s; private Counter precisions2; private Counter recalls2; private Counter pnums2; private Counter rnums2; private Counter percentOOV; private Counter percentOOV2; public TaggingEval(String str) { this(str, true, null); } public TaggingEval(String str, boolean runningAverages, Lexicon lex) { super(str, runningAverages); this.lex = lex; if(doCatLevelEval) { precisions = new ClassicCounter<>(); recalls = new ClassicCounter<>(); f1s = new ClassicCounter<>(); precisions2 = new ClassicCounter<>(); recalls2 = new ClassicCounter<>(); pnums2 = new ClassicCounter<>(); rnums2 = new ClassicCounter<>(); percentOOV = new ClassicCounter<>(); percentOOV2 = new ClassicCounter<>(); } } @Override protected Set makeObjects(Tree tree) { return (tree == null) ? Generics.newHashSet() : Generics.newHashSet(tree.taggedLabeledYield()); } private static Map> makeObjectsByCat(Tree t) { Map> catMap = Generics.newHashMap(); List tly = t.taggedLabeledYield(); for(CoreLabel label : tly) { if(catMap.containsKey(label.value())) catMap.get(label.value()).add(label); else { Set





© 2015 - 2024 Weber Informatics LLC | Privacy Policy