当前位置: 首页>>代码示例>>Java>>正文


Java PriorityQueue类代码示例

本文整理汇总了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;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:20,代码来源:ChainCRFTagger.java

示例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;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:17,代码来源:MultiThreadedParserWrapper.java

示例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;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:11,代码来源:ChainCRFTagger.java

示例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);
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:39,代码来源:Inference.java

示例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;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:9,代码来源:LazyList.java

示例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]);
	// }

}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:35,代码来源:GrammarMerger.java

示例7: setID

import edu.berkeley.nlp.util.PriorityQueue; //导入依赖的package包/类
public void setID(int i, PriorityQueue<List<Tree<String>>> q) {
	myID = i;
	queue = q;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:5,代码来源:ConstrainedArrayParser.java

示例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>");
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:54,代码来源:GrammarStatistics.java

示例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);
	}
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:55,代码来源:GrammarStatistics.java


注:本文中的edu.berkeley.nlp.util.PriorityQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。