本文整理汇总了Java中edu.stanford.nlp.stats.Counters.toSortedList方法的典型用法代码示例。如果您正苦于以下问题:Java Counters.toSortedList方法的具体用法?Java Counters.toSortedList怎么用?Java Counters.toSortedList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.stats.Counters
的用法示例。
在下文中一共展示了Counters.toSortedList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHighPrecisionFeatures
import edu.stanford.nlp.stats.Counters; //导入方法依赖的package包/类
/**
* Returns a list of featured thresholded by minPrecision and sorted by their frequency of occurrence.
* precision in this case, is defined as the frequency of majority label over total frequency for that feature.
* @return list of high precision features.
*/
private List<F> getHighPrecisionFeatures(GeneralDataset<L,F> dataset, double minPrecision, int maxNumFeatures){
int[][] feature2label = new int[dataset.numFeatures()][dataset.numClasses()];
for(int f = 0; f < dataset.numFeatures(); f++)
Arrays.fill(feature2label[f],0);
int[][] data = dataset.data;
int[] labels = dataset.labels;
for(int d = 0; d < data.length; d++){
int label = labels[d];
//System.out.println("datum id:"+d+" label id: "+label);
if(data[d] != null){
//System.out.println(" number of features:"+data[d].length);
for(int n = 0; n < data[d].length; n++){
feature2label[data[d][n]][label]++;
}
}
}
Counter<F> feature2freq = new ClassicCounter<F>();
for(int f = 0; f < dataset.numFeatures(); f++){
int maxF = ArrayMath.max(feature2label[f]);
int total = ArrayMath.sum(feature2label[f]);
double precision = ((double)maxF)/total;
F feature = dataset.featureIndex.get(f);
if(precision >= minPrecision){
feature2freq.incrementCount(feature, total);
}
}
if(feature2freq.size() > maxNumFeatures){
Counters.retainTop(feature2freq, maxNumFeatures);
}
//for(F feature : feature2freq.keySet())
//System.out.println(feature+" "+feature2freq.getCount(feature));
//System.exit(0);
return Counters.toSortedList(feature2freq);
}
示例2: classifyAndWriteAnswersKBest
import edu.stanford.nlp.stats.Counters; //导入方法依赖的package包/类
/**
* Run the classifier on the documents in an ObjectBank, and print the
* answers to a given PrintWriter (with timing to stderr). The value of
* flags.documentReader is used to determine testFile format.
*
* @param documents The ObjectBank to test on.
*/
public void classifyAndWriteAnswersKBest(ObjectBank<List<IN>> documents, int k, PrintWriter printWriter,
DocumentReaderAndWriter<IN> readerAndWriter) throws IOException {
Timing timer = new Timing();
int numWords = 0;
int numSentences = 0;
for (List<IN> doc : documents) {
Counter<List<IN>> kBest = classifyKBest(doc, CoreAnnotations.AnswerAnnotation.class, k);
numWords += doc.size();
List<List<IN>> sorted = Counters.toSortedList(kBest);
int n = 1;
for (List<IN> l : sorted) {
System.out.println("<sentence id=" + numSentences + " k=" + n + " logProb=" + kBest.getCount(l) + " prob="
+ Math.exp(kBest.getCount(l)) + '>');
writeAnswers(l, printWriter, readerAndWriter);
System.out.println("</sentence>");
n++;
}
numSentences++;
}
long millis = timer.stop();
double wordspersec = numWords / (((double) millis) / 1000);
NumberFormat nf = new DecimalFormat("0.00"); // easier way!
System.err.println(this.getClass().getName() + " tagged " + numWords + " words in " + numSentences
+ " documents at " + nf.format(wordspersec) + " words per second.");
}
示例3: appendIntCountStats
import edu.stanford.nlp.stats.Counters; //导入方法依赖的package包/类
private static <E> void appendIntCountStats(StringBuilder sb, String label, IntCounter<E> counts)
{
sb.append(label).append("\n");
List<E> sortedKeys = Counters.toSortedList(counts);
int total = counts.totalIntCount();
for (E key:sortedKeys) {
int count = counts.getIntCount(key);
appendFrac(sb, key.toString(), count, total);
sb.append("\n");
}
}