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

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

Introduction

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

Prototype

public boolean add(E key, double priority);

Source Link

Document

Convenience method for if you want to pretend relaxPriority doesn't exist, or if you really want to use the return conditions of add().

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);/*w w  w  .ja  va 2  s .  co m*/
                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 lazyNext(PriorityQueue<Derivation> candV, Derivation derivation, int kPrime) {
    List<Vertex> tails = derivation.arc.tails;
    for (int i = 0, sz = derivation.arc.size(); i < sz; i++) {
        List<Integer> j = new ArrayList<Integer>(derivation.j);
        j.set(i, j.get(i) + 1);/*  w w w. j a v a2 s .  c om*/
        Vertex Ti = tails.get(i);
        lazyKthBest(Ti, j.get(i), kPrime);
        LinkedList<Derivation> dHatTi = dHat.get(Ti);
        // compute score for this derivation
        if (j.get(i) - 1 >= dHatTi.size()) {
            continue;
        }
        Derivation d = dHatTi.get(j.get(i) - 1);
        double newScore = derivation.score - derivation.childrenScores.get(i) + d.score;
        List<Double> childrenScores = new ArrayList<Double>(derivation.childrenScores);
        childrenScores.set(i, d.score);
        Derivation newDerivation = new Derivation(derivation.arc, j, newScore, childrenScores);
        if (!candV.contains(newDerivation) && newScore > Double.NEGATIVE_INFINITY) {
            candV.add(newDerivation, newScore);
        }
    }
}