Example usage for edu.stanford.nlp.util PriorityQueue removeFirst

List of usage examples for edu.stanford.nlp.util PriorityQueue removeFirst

Introduction

In this page you can find the example usage for edu.stanford.nlp.util PriorityQueue removeFirst.

Prototype

public E removeFirst();

Source Link

Document

Finds the object with the highest priority, removes it, and returns it.

Usage

From source file:conditionalCFG.ConditionalCFGParser.java

License:Open Source License

private PriorityQueue<Derivation> getCandidates(Vertex v, int k) {
    PriorityQueue<Derivation> candV = cand.get(v);
    if (candV == null) {
        candV = new BinaryHeapPriorityQueue<Derivation>();
        List<Arc> bsV = getBackwardsStar(v);

        for (Arc arc : bsV) {
            int size = arc.size();
            double score = arc.ruleScore;
            List<Double> childrenScores = new ArrayList<Double>();
            for (int i = 0; i < size; i++) {
                Vertex child = arc.tails.get(i);
                double s = iScore[child.start][child.end][child.goal];
                childrenScores.add(s);/*from   www .  j  ava 2  s  .  c om*/
                score += s;
            }
            if (score == Double.NEGATIVE_INFINITY) {
                continue;
            }
            List<Integer> j = new ArrayList<Integer>();
            for (int i = 0; i < size; i++) {
                j.add(1);
            }
            Derivation d = new Derivation(arc, j, score, childrenScores);
            candV.add(d, score);
        }
        PriorityQueue<Derivation> tmp = new BinaryHeapPriorityQueue<Derivation>();
        for (int i = 0; i < k; i++) {
            if (candV.isEmpty()) {
                break;
            }
            Derivation d = candV.removeFirst();
            tmp.add(d, d.score);
        }
        candV = tmp;
        cand.put(v, candV);
    }
    return candV;
}

From source file:conditionalCFG.ConditionalCFGParser.java

License:Open Source License

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);/*from  w ww  . ja  v  a  2  s.c o  m*/
    }
    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;
        }
    }
}