本文整理汇总了Java中edu.stanford.nlp.util.PriorityQueue.removeFirst方法的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue.removeFirst方法的具体用法?Java PriorityQueue.removeFirst怎么用?Java PriorityQueue.removeFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.util.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.removeFirst方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
}
示例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;
}
}
}
示例3: 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();
}
示例4: 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();
}
示例5: 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;
}
}
示例6: 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;
}
示例7: toBiggestValuesFirstString
import edu.stanford.nlp.util.PriorityQueue; //导入方法依赖的package包/类
public static <T> String toBiggestValuesFirstString(Counter<Integer> c, int k, Index<T> index) {
PriorityQueue<Integer> pq = toPriorityQueue(c);
PriorityQueue<T> largestK = new BinaryHeapPriorityQueue<T>();
// while (largestK.size() < k && ((Iterator)pq).hasNext()) { //same as above
while (largestK.size() < k && !pq.isEmpty()) {
double firstScore = pq.getPriority(pq.getFirst());
int first = pq.removeFirst();
largestK.changePriority(index.get(first), firstScore);
}
return largestK.toString();
}
示例8: toSortedString
import edu.stanford.nlp.util.PriorityQueue; //导入方法依赖的package包/类
/**
* Returns a string representation of a Counter, displaying the keys and
* their counts in decreasing order of count. At most k keys are displayed.
*
* Note that this method subsumes many of the other toString methods, e.g.:
*
* toString(c, k) and toBiggestValuesFirstString(c, k)
* => toSortedString(c, k, "%s=%f", ", ", "[%s]")
*
* toVerticalString(c, k)
* => toSortedString(c, k, "%2$g\t%1$s", "\n", "%s\n")
*
* @param counter A Counter.
* @param k The number of keys to include. Use Integer.MAX_VALUE to
* include all keys.
* @param itemFormat The format string for key/count pairs, where the key is
* first and the value is second. To display the value first,
* use argument indices, e.g. "%2$f %1$s".
* @param joiner The string used between pairs of key/value strings.
* @param wrapperFormat The format string for wrapping text around the joined items,
* where the joined item string value is "%s".
* @return The top k values from the Counter, formatted as specified.
*/
public static <T> String toSortedString(
Counter<T> counter, int k, String itemFormat, String joiner, String wrapperFormat) {
PriorityQueue<T> queue = toPriorityQueue(counter);
List<String> strings = new ArrayList<String>();
for (int rank = 0; rank < k && !queue.isEmpty(); ++rank) {
T key = queue.removeFirst();
double value = counter.getCount(key);
strings.add(String.format(itemFormat, key, value));
}
return String.format(wrapperFormat, StringUtils.join(strings, joiner));
}
示例9: toSortedString
import edu.stanford.nlp.util.PriorityQueue; //导入方法依赖的package包/类
/**
* Returns a string representation of a Counter, displaying the keys and their
* counts in decreasing order of count. At most k keys are displayed.
*
* Note that this method subsumes many of the other toString methods, e.g.:
*
* toString(c, k) and toBiggestValuesFirstString(c, k) => toSortedString(c, k,
* "%s=%f", ", ", "[%s]")
*
* toVerticalString(c, k) => toSortedString(c, k, "%2$g\t%1$s", "\n", "%s\n")
*
* @param counter
* A Counter.
* @param k
* The number of keys to include. Use Integer.MAX_VALUE to include
* all keys.
* @param itemFormat
* The format string for key/count pairs, where the key is first and
* the value is second. To display the value first, use argument
* indices, e.g. "%2$f %1$s".
* @param joiner
* The string used between pairs of key/value strings.
* @param wrapperFormat
* The format string for wrapping text around the joined items, where
* the joined item string value is "%s".
* @return The top k values from the Counter, formatted as specified.
*/
public static <T> String toSortedString(Counter<T> counter, int k, String itemFormat, String joiner, String wrapperFormat) {
PriorityQueue<T> queue = toPriorityQueue(counter);
List<String> strings = new ArrayList<String>();
for (int rank = 0; rank < k && !queue.isEmpty(); ++rank) {
T key = queue.removeFirst();
double value = counter.getCount(key);
strings.add(String.format(itemFormat, key, value));
}
return String.format(wrapperFormat, StringUtils.join(strings, joiner));
}