本文整理汇总了Java中edu.stanford.nlp.util.PriorityQueue类的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue类的具体用法?Java PriorityQueue怎么用?Java PriorityQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PriorityQueue类属于edu.stanford.nlp.util包,在下文中一共展示了PriorityQueue类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getKBestParses
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/** Get the exact k best parses for the sentence.
*
* @param k The number of best parses to return
* @return The exact k best parses for the sentence, with
* each accompanied by its score (typically a
* negative log probability).
*/
public List<ScoredObject<Tree>> getKBestParses(int k) {
cand = new HashMap<Vertex,PriorityQueue<Derivation>>();
dHat = new HashMap<Vertex,LinkedList<Derivation>>();
int start = 0;
int end = length;
int goal = stateNumberer.number(goalStr);
Vertex v = new Vertex(goal, start, end);
List<ScoredObject<Tree>> kBestTrees = new ArrayList<ScoredObject<Tree>>();
for (int i = 1; i <= k; i++) {
Tree internalTree = getTree(v, i, k);
if (internalTree == null) { break; }
// restoreUnaries(internalTree);
kBestTrees.add(new ScoredObject<Tree>(internalTree, dHat.get(v).get(i-1).score));
}
return kBestTrees;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:27,代码来源:ExhaustivePCFGParser.java
示例2: lazyKthBest
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
private void lazyKthBest(Vertex v, int k, int kPrime) {
PriorityQueue<Derivation> candV = getCandidates(v, kPrime);
LinkedList<Derivation> dHatV = dHat.get(v);
if (dHatV == null) {
dHatV = new LinkedList<Derivation>();
dHat.put(v,dHatV);
}
while (dHatV.size() < k) {
if ( ! dHatV.isEmpty()) {
Derivation derivation = dHatV.getLast();
lazyNext(candV, derivation, kPrime);
}
if ( ! candV.isEmpty()) {
Derivation d = candV.removeFirst();
dHatV.add(d);
} else {
break;
}
}
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:22,代码来源:ExhaustivePCFGParser.java
示例3: toVerticalString
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* Returns a <code>String</code> representation of the <code>k</code> keys
* with the largest counts in the given {@link Counter}, using the given
* format string.
*
* @param c a Counter
* @param k how many keys to print
* @param fmt a format string, such as "%.0f\t%s" (do not include final "%n")
* @param swap whether the count should appear after the key
*/
public static <E> String toVerticalString(Counter<E> c, int k, String fmt, boolean swap) {
PriorityQueue<E> q = Counters.toPriorityQueue(c);
List<E> sortedKeys = q.toSortedList();
StringBuilder sb = new StringBuilder();
int i = 0;
for (Iterator<E> keyI = sortedKeys.iterator(); keyI.hasNext() && i < k; i++) {
E key = keyI.next();
double val = q.getPriority(key);
if (swap) {
sb.append(String.format(fmt, key, val));
} else {
sb.append(String.format(fmt, val, key));
}
if (keyI.hasNext()) {
sb.append('\n');
}
}
return sb.toString();
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:30,代码来源:Counters.java
示例4: toVerticalString
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* Returns a <code>String</code> representation of the <code>k</code> keys
* with the largest counts in the given {@link Counter}, using the given
* format string.
*
* @param c
* a Counter
* @param k
* how many keys to print
* @param fmt
* a format string, such as "%.0f\t%s" (do not include final "%n")
* @param swap
* whether the count should appear after the key
*/
public static <E> String toVerticalString(Counter<E> c, int k, String fmt, boolean swap) {
PriorityQueue<E> q = Counters.toPriorityQueue(c);
List<E> sortedKeys = q.toSortedList();
StringBuilder sb = new StringBuilder();
int i = 0;
for (Iterator<E> keyI = sortedKeys.iterator(); keyI.hasNext() && i < k; i++) {
E key = keyI.next();
double val = q.getPriority(key);
if (swap) {
sb.append(String.format(fmt, key, val));
} else {
sb.append(String.format(fmt, val, key));
}
if (keyI.hasNext()) {
sb.append('\n');
}
}
return sb.toString();
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:34,代码来源:Counters.java
示例5: init
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public void init(List<Pair<Double, Integer>> dataScores) {
PriorityQueue<Pair<Integer, Pair<Double, Integer>>> q = new BinaryHeapPriorityQueue<Pair<Integer, Pair<Double, Integer>>>();
for (int i = 0; i < dataScores.size(); i++) {
q.add(new Pair<Integer, Pair<Double, Integer>>(Integer.valueOf(i), dataScores.get(i)), -dataScores.get(i).first().doubleValue());
}
List<Pair<Integer, Pair<Double, Integer>>> sorted = q.toSortedList();
scores = new double[sorted.size()];
classes = new int[sorted.size()];
System.err.println("incoming size " + dataScores.size() + " resulting " + sorted.size());
for (int i = 0; i < sorted.size(); i++) {
Pair<Double, Integer> next = sorted.get(i).second();
scores[i] = next.first().doubleValue();
classes[i] = next.second().intValue();
}
init();
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:18,代码来源:PRCurve.java
示例6: initMC
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public void initMC(ArrayList<Triple<Double, Integer, Integer>> dataScores) {
PriorityQueue<Pair<Integer, Triple<Double, Integer, Integer>>> q = new BinaryHeapPriorityQueue<Pair<Integer, Triple<Double, Integer, Integer>>>();
for (int i = 0; i < dataScores.size(); i++) {
q.add(new Pair<Integer, Triple<Double, Integer, Integer>>(Integer.valueOf(i), dataScores.get(i)), -dataScores.get(i).first().doubleValue());
}
List<Pair<Integer, Triple<Double, Integer, Integer>>> sorted = q.toSortedList();
scores = new double[sorted.size()];
classes = new int[sorted.size()];
guesses = new int[sorted.size()];
System.err.println("incoming size " + dataScores.size() + " resulting " + sorted.size());
for (int i = 0; i < sorted.size(); i++) {
Triple<Double, Integer, Integer> next = sorted.get(i).second();
scores[i] = next.first().doubleValue();
classes[i] = next.second().intValue();
guesses[i] = next.third().intValue();
}
init();
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:20,代码来源:PRCurve.java
示例7: lazyKthBest
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
private void lazyKthBest(Vertex v, int k, int kPrime) {
PriorityQueue<Derivation> candV = getCandidates(v, kPrime);
LinkedList<Derivation> dHatV = dHat.get(v);
if (dHatV == null) {
dHatV = new LinkedList<Derivation>();
dHat.put(v,dHatV);
}
while (dHatV.size() < k) {
if (!dHatV.isEmpty()) {
Derivation derivation = dHatV.getLast();
lazyNext(candV, derivation, kPrime);
}
if (!candV.isEmpty()) {
Derivation d = candV.removeFirst();
dHatV.add(d);
} else {
break;
}
}
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:22,代码来源:ExhaustivePCFGParser.java
示例8: getKBestParses
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/** Get the exact k best parses for the sentence.
*
* @param k The number of best parses to return
* @return The exact k best parses for the sentence, with
* each accompanied by its score (typically a
* negative log probability).
*/
public List<ScoredObject<Tree>> getKBestParses(int k) {
cand = new HashMap<Vertex,PriorityQueue<Derivation>>();
dHat = new HashMap<Vertex,LinkedList<Derivation>>();
int start = 0;
int end = length;
int goal = stateIndex.indexOf(goalStr);
Vertex v = new Vertex(goal, start, end);
List<ScoredObject<Tree>> kBestTrees = new ArrayList<ScoredObject<Tree>>();
for (int i = 1; i <= k; i++) {
Tree internalTree = getTree(v, i, k);
if (internalTree == null) { break; }
// restoreUnaries(internalTree);
kBestTrees.add(new ScoredObject<Tree>(internalTree, dHat.get(v).get(i-1).score));
}
return kBestTrees;
}
开发者ID:amark-india,项目名称:eventspotter,代码行数:27,代码来源:ExhaustivePCFGParser.java
示例9: toPriorityQueue
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* Returns a {@link edu.stanford.nlp.util.PriorityQueue} whose elements
* are the keys of Counter c,
* and the score of each key in c becomes its priority.
*
* @param c Input Counter
* @return A PriorityQueue where the count is a key's priority
*/
// TODO: rewrite to use entrySet()
public static <E> edu.stanford.nlp.util.PriorityQueue<E> toPriorityQueue(Counter<E> c) {
edu.stanford.nlp.util.PriorityQueue<E> queue = new BinaryHeapPriorityQueue<E>();
for (E key : c.keySet()) {
double count = c.getCount(key);
queue.add(key, count);
}
return queue;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:18,代码来源:Counters.java
示例10: toBiggestValuesFirstString
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public static <E> String toBiggestValuesFirstString(Counter<E> c, int k) {
PriorityQueue<E> pq = toPriorityQueue(c);
PriorityQueue<E> largestK = new BinaryHeapPriorityQueue<E>();
//TODO: Is there any reason the original (commented out) line is better than the one replacing it?
// while (largestK.size() < k && ((Iterator<E>)pq).hasNext()) {
while (largestK.size() < k && !pq.isEmpty()) {
double firstScore = pq.getPriority(pq.getFirst());
E first = pq.removeFirst();
largestK.changePriority(first, firstScore);
}
return largestK.toString();
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:13,代码来源:Counters.java
示例11: toPriorityQueue
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* Returns a {@link edu.stanford.nlp.util.PriorityQueue} whose elements are
* the keys of Counter c, and the score of each key in c becomes its priority.
*
* @param c
* Input Counter
* @return A PriorityQueue where the count is a key's priority
*/
// TODO: rewrite to use entrySet()
public static <E> edu.stanford.nlp.util.PriorityQueue<E> toPriorityQueue(Counter<E> c) {
edu.stanford.nlp.util.PriorityQueue<E> queue = new BinaryHeapPriorityQueue<E>();
for (E key : c.keySet()) {
double count = c.getCount(key);
queue.add(key, count);
}
return queue;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:18,代码来源:Counters.java
示例12: toBiggestValuesFirstString
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public static <E> String toBiggestValuesFirstString(Counter<E> c, int k) {
PriorityQueue<E> pq = toPriorityQueue(c);
PriorityQueue<E> largestK = new BinaryHeapPriorityQueue<E>();
// TODO: Is there any reason the original (commented out) line is better
// than the one replacing it?
// while (largestK.size() < k && ((Iterator<E>)pq).hasNext()) {
while (largestK.size() < k && !pq.isEmpty()) {
double firstScore = pq.getPriority(pq.getFirst());
E first = pq.removeFirst();
largestK.changePriority(first, firstScore);
}
return largestK.toString();
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:14,代码来源:Counters.java
示例13: retainTopMass
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* Retains the minimal set of top keys such that their count sum is more than thresholdCount.
* @param counter
* @param thresholdCount
*/
public static<E> void retainTopMass(Counter<E> counter, double thresholdCount){
PriorityQueue<E> queue = Counters.toPriorityQueue(counter);
counter.clear();
double mass = 0;
while (mass < thresholdCount && !queue.isEmpty()) {
double value = queue.getPriority();
E key = queue.removeFirst();
counter.setCount(key, value);
mass += value;
}
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:18,代码来源:Counters.java
示例14: topKeys
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public static<E> List<E> topKeys(Counter<E> t, int topNum){
List<E> list = new ArrayList<E>();
PriorityQueue<E> q = Counters.toPriorityQueue(t);
int num = 0;
while(!q.isEmpty() && num < topNum){
num++;
list.add(q.removeFirst());
}
return list;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:11,代码来源:Counters.java
示例15: topKeysWithCounts
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public static<E> List<Pair<E, Double>> topKeysWithCounts(Counter<E> t, int topNum){
List<Pair<E, Double>> list = new ArrayList<Pair<E, Double>>();
PriorityQueue<E> q = Counters.toPriorityQueue(t);
int num = 0;
while(!q.isEmpty() && num < topNum){
num++;
E k = q.removeFirst();
list.add(new Pair<E, Double>(k, t.getCount(k)));
}
return list;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:12,代码来源:Counters.java
示例16: initMC
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public <F> void initMC(ProbabilisticClassifier<L,F> classifier, GeneralDataset<L,F> data) {
//if (!(gData instanceof Dataset)) {
// throw new UnsupportedOperationException("Can only handle Datasets, not "+gData.getClass().getName());
//}
//
//Dataset data = (Dataset)gData;
PriorityQueue<Pair<Integer, Pair<Double, Boolean>>> q = new BinaryHeapPriorityQueue<Pair<Integer, Pair<Double, Boolean>>>();
total = 0;
correct = 0;
logLikelihood = 0.0;
for (int i = 0; i < data.size(); i++) {
Datum<L,F> d = data.getRVFDatum(i);
Counter<L> scores = classifier.logProbabilityOf(d);
L guess = Counters.argmax(scores);
L correctLab = d.label();
double guessScore = scores.getCount(guess);
double correctScore = scores.getCount(correctLab);
int guessInd = data.labelIndex().indexOf(guess);
int correctInd = data.labelIndex().indexOf(correctLab);
total++;
if (guessInd == correctInd) {
correct++;
}
logLikelihood += correctScore;
q.add(new Pair<Integer, Pair<Double, Boolean>>(Integer.valueOf(i), new Pair<Double, Boolean>(new Double(guessScore), Boolean.valueOf(guessInd == correctInd))), -guessScore);
}
accuracy = (double) correct / (double) total;
List<Pair<Integer, Pair<Double, Boolean>>> sorted = q.toSortedList();
scores = new double[sorted.size()];
isCorrect = new boolean[sorted.size()];
for (int i = 0; i < sorted.size(); i++) {
Pair<Double, Boolean> next = sorted.get(i).second();
scores[i] = next.first().doubleValue();
isCorrect[i] = next.second().booleanValue();
}
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:41,代码来源:MultiClassAccuracyStats.java
示例17: main
import edu.stanford.nlp.util.PriorityQueue; //导入依赖的package包/类
public static void main(String[] args) {
PriorityQueue<String> q = new BinaryHeapPriorityQueue<String>();
q.add("bla", 2);
q.add("bla3", 2);
System.err.println("size of q " + q.size());
PRCurve pr = new PRCurve("c:/data0204/precsvm", true);
System.err.println("acc " + pr.accuracy() + " opt " + pr.optimalAccuracy() + " cwa " + pr.cwa() + " optcwa " + pr.optimalCwa());
for (int r = 1; r <= pr.numSamples(); r++) {
System.err.println("optimal precision at recall " + r + " " + pr.precision(r));
System.err.println("model precision at recall " + r + " " + pr.logPrecision(r));
}
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:15,代码来源:PRCurve.java
注:本文中的edu.stanford.nlp.util.PriorityQueue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论