本文整理汇总了Java中edu.berkeley.nlp.util.PriorityQueue类的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue类的具体用法?Java PriorityQueue怎么用?Java PriorityQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PriorityQueue类属于edu.berkeley.nlp.util包,在下文中一共展示了PriorityQueue类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopKLabelSequencesAndScores
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
public List<Pair<List<L>, Double>> getTopKLabelSequencesAndScores(
InstanceSequence<V, E, L> s, int k) {
Pair<int[][][][], double[][][]> chart = inf.getKBestChartAndBacktrace(
s, w, k);
List<Pair<List<L>, Double>> sentences = new ArrayList<Pair<List<L>, Double>>(
k);
int n = s.getSequenceLength();
PriorityQueue<Pair<Integer, Integer>> rankedScores = buildRankedScoreQueue(chart
.getSecond()[n - 1]);
for (int i = 0; i < k && rankedScores.hasNext(); i++) {
double score = rankedScores.getPriority();
Pair<Integer, Integer> chain = rankedScores.next();
sentences.add(Pair.makePair(
rebuildChain(chart.getFirst(), chain.getFirst(),
chain.getSecond()), score));
}
return sentences;
}
示例2: MultiThreadedParserWrapper
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
public MultiThreadedParserWrapper(ConstrainedArrayParser parser, int threads) {
nThreads = threads;
pool = Executors.newFixedThreadPool(nThreads);
submits = new Future[nThreads];
parsers = new ConstrainedArrayParser[nThreads];
queue = new PriorityQueue<List<Tree<String>>>();
parsers[0] = parser;
parsers[0].setID(0, queue);
for (int i = 0; i < nThreads; i++) {
parsers[i] = parser.newInstance();
parsers[i].setID(i, queue);
}
lastSubmitted = 0;
lastReturned = -1;
}
示例3: buildRankedScoreQueue
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
private PriorityQueue<Pair<Integer, Integer>> buildRankedScoreQueue(
double[][] scores) {
PriorityQueue<Pair<Integer, Integer>> pq = new PriorityQueue<Pair<Integer, Integer>>();
for (int l = 0; l < scores.length; l++) {
for (int c = 0; c < scores[l].length; c++) {
pq.add(Pair.makePair(l, c), scores[l][c]);
}
}
return pq;
}
示例4: getKBestChartAndBacktrace
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
public Pair<int[][][][], double[][][]> getKBestChartAndBacktrace(
InstanceSequence<V, E, L> sequence, double[] w, int k) {
int n = sequence.getSequenceLength();
int numLabels = encoding.getNumLabels();
int[][][][] bestLabels = new int[n][numLabels][][];
double[][][] bestScores = new double[n][numLabels][];
double[] startScores = scoreCalculator.getLinearVertexScores(sequence,
0, w);
for (int l = 0; l < numLabels; l++) {
bestScores[0][l] = new double[] { startScores[l] };
bestLabels[0][l] = new int[][] { new int[] { -1, 0 } };
}
for (int i = 1; i < n; i++) {
double[][] scoreMatrix = scoreCalculator.getLinearScoreMatrix(
sequence, i, w);
for (int l = 0; l < numLabels; l++) {
PriorityQueue<Pair<Integer, Integer>> pq = new PriorityQueue<Pair<Integer, Integer>>();
for (int pl = 0; pl < numLabels; pl++) {
double edgeScore = scoreMatrix[pl][l];
for (int c = 0; c < bestScores[i - 1][pl].length; c++) {
double totalScore = edgeScore
+ bestScores[i - 1][pl][c];
pq.add(Pair.makePair(pl, c), totalScore);
}
}
int cands = Math.min(k, pq.size());
bestScores[i][l] = new double[cands];
bestLabels[i][l] = new int[cands][2];
for (int c = 0; c < cands; c++) {
bestScores[i][l][c] = pq.getPriority();
Pair<Integer, Integer> backtrace = pq.next();
bestLabels[i][l][c][0] = backtrace.getFirst();
bestLabels[i][l][c][1] = backtrace.getSecond();
}
}
}
return Pair.makePair(bestLabels, bestScores);
}
示例5: LazyList
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
public LazyList(boolean[] tags) {
sortedBegining = new ArrayList<HyperEdge>();
fringe = new PriorityQueue<HyperEdge>();
nSorted = 0;
nFringe = 0;
grammarTags = tags;
// bestScore = Double.NEGATIVE_INFINITY;
}
示例6: printMergingStatistics
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* @param grammar
* @param newGrammar
*/
public static void printMergingStatistics(Grammar grammar,
Grammar newGrammar) {
PriorityQueue<String> lexiconStates = new PriorityQueue<String>();
PriorityQueue<String> grammarStates = new PriorityQueue<String>();
short[] numSubStatesArray = grammar.numSubStates;
short[] newNumSubStatesArray = newGrammar.numSubStates;
Numberer tagNumberer = grammar.tagNumberer;
for (short state = 0; state < numSubStatesArray.length; state++) {
System.out.print("\nState " + tagNumberer.object(state) + " had "
+ numSubStatesArray[state] + " substates and now has "
+ newNumSubStatesArray[state] + ".");
if (!grammar.isGrammarTag(state)) {
lexiconStates.add((String) tagNumberer.object(state),
newNumSubStatesArray[state]);
} else {
grammarStates.add((String) tagNumberer.object(state),
newNumSubStatesArray[state]);
}
}
System.out.print("\n");
System.out.println("Lexicon: " + lexiconStates.toString());
System.out.println("Grammar: " + grammarStates.toString());
// System.out.println("after merging, we have split trees:");
// for (int i=0; i<grammar.numStates; i++) {
// System.out.println(grammar.splitTrees[i]);
// }
}
示例7: setID
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
public void setID(int i, PriorityQueue<List<Tree<String>>> q) {
myID = i;
queue = q;
}
示例8: printGrammarStatistics
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* @param columnOutput
* @param pData
* @param tagNumberer
* @param topN
* @param gs
* @param noContinueTags
*/
private static void printGrammarStatistics(boolean columnOutput,
ParserData pData, Numberer tagNumberer, int topN,
GrammarStatistics gs, Set<Short> noContinueTags) {
System.out.println("<a name=\"grammar\"><h1>Grammar</h1></a>");
System.out.println("<div id=\"grammar\">");
// print rule probabilities
for (short curTag : noContinueTags) {
int nSubStates = pData.numSubStatesArray[curTag];
ArrayList<SearchState>[] results = new ArrayList[nSubStates];
for (short i = 0; i < nSubStates; i++) {
// do heavy computation
PriorityQueue<SearchState> pq = gs
.getTopProductions(new FullState(curTag, i));
// convert pq to array
results[i] = new ArrayList<SearchState>(topN);
while (pq.size() != 0) {
pq.peek().score = Math.exp(pq.peek().score);
results[i].add(0, pq.next());
}
}
String[][] outputMatrix = new String[topN + 1][nSubStates];
String tagName = (String) tagNumberer.object(curTag);
for (int i = 0; i < nSubStates; i++) {
outputMatrix[0][i] = tagName + "-" + i;
}
for (int j = 0; j < topN; j++) {
for (int i = 0; i < nSubStates; i++) {
String o = "";
double p = -1;
if (results[i].size() > j) {
p = results[i].get(j).score;
String w = results[i].get(j).toString(tagNumberer);
o = f.format(p) + " " + w;
}
outputMatrix[j + 1][i] = o;
}
}
printRules("Grammar", "productions", columnOutput, outputMatrix);
}
System.out.println("</div>");
}
示例9: printParentRuleStatistics
import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
/**
* @param columnOutput
* @param pData
* @param tagNumberer
* @param topN
* @param gs
* @param noContinueTags
*/
private static void printParentRuleStatistics(boolean columnOutput,
ParserData pData, Numberer tagNumberer, int topN,
GrammarStatistics gs, Set<Short> noContinueTags,
double[] probState, double[][] probSubGivenState) {
System.out.println("<a name=\"parentrules\"><h1>Parent Rules</h1></a>");
// print rule probabilities
for (short curTag : noContinueTags) {
int nSubStates = pData.numSubStatesArray[curTag];
ArrayList<SearchState>[] results = new ArrayList[nSubStates];
for (short i = 0; i < nSubStates; i++) {
// do heavy computation
PriorityQueue<SearchState> pq = gs.getTopParentRuleProductions(
new FullState(curTag, i), probState, probSubGivenState);
// convert pq to array
results[i] = new ArrayList<SearchState>(topN);
while (pq.size() != 0) {
pq.peek().score = Math.exp(pq.peek().score);
results[i].add(0, pq.next());
}
}
String[][] outputMatrix = new String[topN + 1][nSubStates];
String tagName = (String) tagNumberer.object(curTag);
for (int i = 0; i < nSubStates; i++) {
outputMatrix[0][i] = tagName + "-" + i;
}
for (int j = 0; j < topN; j++) {
for (int i = 0; i < nSubStates; i++) {
String o = "";
double p = -1;
if (results[i].size() > j) {
p = results[i].get(j).score;
String w = results[i].get(j).toString(tagNumberer);
o = f.format(p) + " " + w;
}
outputMatrix[j + 1][i] = o;
}
}
printRules("Parent Rules", "parentrules", columnOutput,
outputMatrix);
}
}