本文整理汇总了Java中cc.mallet.fst.Transducer.TransitionIterator.getOutput方法的典型用法代码示例。如果您正苦于以下问题:Java TransitionIterator.getOutput方法的具体用法?Java TransitionIterator.getOutput怎么用?Java TransitionIterator.getOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.fst.Transducer.TransitionIterator
的用法示例。
在下文中一共展示了TransitionIterator.getOutput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MaxLatticeDefault
import cc.mallet.fst.Transducer.TransitionIterator; //导入方法依赖的package包/类
/** Initiate Viterbi decoding of the inputSequence, contrained to match non-null parts of the outputSequence.
* maxCaches indicates how much state information to memoize in n-best decoding. */
public MaxLatticeDefault (Transducer t, Sequence inputSequence, Sequence outputSequence, int maxCaches)
{
// This method initializes the forward path, but does not yet do the backward pass.
this.t = t;
if (maxCaches < 1)
maxCaches = 1;
this.maxCaches = maxCaches;
assert (inputSequence != null);
if (logger.isLoggable (Level.FINE)) {
logger.fine ("Starting ViterbiLattice");
logger.fine ("Input: ");
for (int ip = 0; ip < inputSequence.size(); ip++)
logger.fine (" " + inputSequence.get(ip));
logger.fine ("\nOutput: ");
if (outputSequence == null)
logger.fine ("null");
else
for (int op = 0; op < outputSequence.size(); op++)
logger.fine (" " + outputSequence.get(op));
logger.fine ("\n");
}
this.input = inputSequence;
this.providedOutput = outputSequence;
latticeLength = input.size()+1;
int numStates = t.numStates();
lattice = new ViterbiNode[latticeLength][numStates];
caches = new WeightCache[latticeLength-1];
// Viterbi Forward
logger.fine ("Starting Viterbi");
boolean anyInitialState = false;
for (int i = 0; i < numStates; i++) {
double initialWeight = t.getState(i).getInitialWeight();
if (initialWeight > Transducer.IMPOSSIBLE_WEIGHT) {
ViterbiNode n = getViterbiNode (0, i);
n.delta = initialWeight;
anyInitialState = true;
}
}
if (!anyInitialState) {
logger.warning ("Viterbi: No initial states!");
}
for (int ip = 0; ip < latticeLength-1; ip++)
for (int i = 0; i < numStates; i++) {
if (lattice[ip][i] == null || lattice[ip][i].delta == Transducer.IMPOSSIBLE_WEIGHT)
continue;
State s = t.getState(i);
TransitionIterator iter = s.transitionIterator (input, ip, providedOutput, ip);
if (logger.isLoggable (Level.FINE))
logger.fine (" Starting Viterbi transition iteration from state "
+ s.getName() + " on input " + input.get(ip));
while (iter.hasNext()) {
State destination = iter.next();
if (logger.isLoggable (Level.FINE))
logger.fine ("Viterbi[inputPos="+ip
+"][source="+s.getName()
+"][dest="+destination.getName()+"]");
ViterbiNode destinationNode = getViterbiNode (ip+1, destination.getIndex());
destinationNode.output = iter.getOutput();
double weight = lattice[ip][i].delta + iter.getWeight();
if (ip == latticeLength-2) {
weight += destination.getFinalWeight();
}
if (weight > destinationNode.delta) {
if (logger.isLoggable (Level.FINE))
logger.fine ("Viterbi[inputPos="+ip
+"][source][dest="+destination.getName()
+"] weight increased to "+weight+" by source="+
s.getName());
destinationNode.delta = weight;
destinationNode.maxWeightPredecessor = lattice[ip][i];
}
}
}
}