📄 dynamicflatlinguist.java
字号:
FullHMMSearchState(PronunciationState p, int which, int lc, int rc) { this.pState = p; this.index = which; this.lc = lc; this.rc = rc; int base = p.getPronunciation().getUnits()[which].getBaseID(); int id = hmmPool.buildID(base, lc, rc); hmm = hmmPool.getHMM(id, getPosition()); isLastUnitOfWord = which == p.getPronunciation().getUnits().length - 1; } /** * Determines the insertion probability based upon the type of unit * * @return the insertion probability */ public float getInsertionProbability() { Unit unit = hmm.getBaseUnit(); if (unit.isSilence()) { return logSilenceInsertionProbability; } else if (unit.isFiller()) { return logFillerInsertionProbability; } else { return logUnitInsertionProbability; } } /** * Returns a string representation of this object * * @return a string representation */ public String toString() { return hmm.getUnit().toString(); } /** * Generate a hashcode for an object * * @return the hashcode */ public int hashCode() { return pState.getGrammarState().getGrammarNode().hashCode() * 29 + pState.getPronunciation().hashCode() * 19 + index * 7 + 43 * lc + rc; } /** * Determines if the given object is equal to this object * * @param o * the object to test * @return <code>true</code> if the object is equal to this */ public boolean equals(Object o) { if (o == this) { return true; } else if (o instanceof FullHMMSearchState) { FullHMMSearchState other = (FullHMMSearchState) o; // the definition for equal for a FullHMMState: // Grammar Node equal // Pronunciation equal // index equal // rc equal return pState.getGrammarState().getGrammarNode() == other.pState.getGrammarState().getGrammarNode() && pState.getPronunciation() == other.pState.getPronunciation() && index == other.index && lc == other.lc && rc == other.rc; } else { return false; } } /** * Returns the unit assoicated with this state * * @return the unit */ public Unit getUnit() { return hmm.getBaseUnit(); } /** * Gets the set of successors for this state * * @return the set of successors */ public SearchStateArc[] getSuccessors() { SearchStateArc[] arcs = getCachedSuccessors(); if (arcs == null) { arcs = new SearchStateArc[1]; arcs[0] = new HMMStateSearchState(this, hmm.getInitialState()); cacheSuccessors(arcs); } return arcs; } /** * Determines if this unit is the last unit of a word * * @return true if this unit is the last unit of a word */ boolean isLastUnitOfWord() { return isLastUnitOfWord; } /** * Determines the position of the unit within the word * * @return the position of the unit within the word */ HMMPosition getPosition() { int len = pState.getPronunciation().getUnits().length; if (len == 1) { return HMMPosition.SINGLE; } else if (index == 0) { return HMMPosition.BEGIN; } else if (index == len -1) { return HMMPosition.END; } else { return HMMPosition.INTERNAL; } } /** * Returns the HMM for this state * * @return the HMM */ HMM getHMM() { return hmm; } /** * Returns the order of this state type among all of the search states * * @return the order */ public int getOrder() { return 3; } /** * Determines the insertion probability based upon the type of unit * * @return the insertion probability */ private float calcInsertionProbability() { Unit unit = hmm.getBaseUnit(); if (unit.isSilence()) { return logSilenceInsertionProbability; } else if (unit.isFiller()) { return logFillerInsertionProbability; } else { return logUnitInsertionProbability; } } /** * Returns a unique string representation of the state. This string is * suitable (and typically used) for a label for a GDL node * * @return the signature */ public String getSignature() { return "HSS " + pState.getGrammarState().getGrammarNode() + pState.getPronunciation() + index + "-" + rc + "-" + lc; } /** * Returns the ID of the right context for this state * * @return the right context unit ID */ int getRC() { return rc; } /** * Returns the next set of arcs after this state and all * substates have been processed * * @return the next set of arcs */ SearchStateArc[] getNextArcs() { SearchStateArc[] arcs; // this is the last state of the hmm // so check to see if we are at the end // of a word, if not get the next full hmm in the word // otherwise generate arcs to the next set of words Pronunciation pronunciation = pState.getPronunciation(); int nextLC = getHMM().getBaseUnit().getBaseID(); if (!isLastUnitOfWord()) { arcs = pState.getSuccessors(nextLC, index + 1); } else { // we are at the end of the word, so we transit to the // next grammar nodes GrammarState gs = pState.getGrammarState(); arcs = gs.getNextGrammarStates(nextLC, getRC()); } return arcs; } } /** * Represents a single hmm state in the search graph */ class HMMStateSearchState extends FlatSearchState implements HMMSearchState { private FullHMMSearchState fullHMMSearchState; private HMMState hmmState; private float probability; /** * Creates an HMMStateSearchState * * @param hss the parent hmm state * @param hmmState which hmm state */ HMMStateSearchState(FullHMMSearchState hss, HMMState hmmState) { this(hss, hmmState, logOne); } /** * Creates an HMMStateSearchState * * @param hss the parent hmm state * @param hmmState which hmm state * @param prob the transition probability */ HMMStateSearchState(FullHMMSearchState hss, HMMState hmmState, float prob) { this.probability = prob; fullHMMSearchState = hss; this.hmmState = hmmState; } /** * Returns the acoustic probability for this state * * @return the probability */ public float getAcousticProbability() { return probability; } /** * Generate a hashcode for an object * * @return the hashcode */ public int hashCode() { return 7 * fullHMMSearchState.hashCode() + hmmState.hashCode(); } /** * Determines if the given object is equal to this object * * @param o * the object to test * @return <code>true</code> if the object is equal to this */ public boolean equals(Object o) { if (o == this) { return true; } else if (o instanceof HMMStateSearchState) { HMMStateSearchState other = (HMMStateSearchState) o; return other.fullHMMSearchState.equals(fullHMMSearchState) && other.hmmState.equals(hmmState); } else { return false; } } /** * Determines if this state is an emitting state * * @return true if this is an emitting state */ public boolean isEmitting() { return hmmState.isEmitting(); } /** * Gets the set of successors for this state * * @return the set of successors */ public SearchStateArc[] getSuccessors() { SearchStateArc[] arcs = getCachedSuccessors(); if (arcs == null) { if (hmmState.isExitState()) { arcs = fullHMMSearchState.getNextArcs(); } else { HMMStateArc[] next = hmmState.getSuccessors(); arcs = new SearchStateArc[next.length]; for (int i = 0; i < arcs.length; i++) { arcs[i] = new HMMStateSearchState(fullHMMSearchState, next[i].getHMMState(), next[i].getLogProbability()); } } cacheSuccessors(arcs); } return arcs; } /** * Returns the order of this state type among all of the search states * * @return the order */ public int getOrder() { return isEmitting() ? 4 : 0; } /** * Returns a unique string representation of the state. This string is * suitable (and typically used) for a label for a GDL node * * @return the signature */ public String getSignature() { return "HSSS " + fullHMMSearchState.getSignature() + "-" + hmmState; } /** * Returns the hmm state for this search state * * @return the hmm state */ public HMMState getHMMState() { return hmmState; } } /** * The search graph that is produced by the flat linguist. */ class DynamicFlatSearchGraph implements SearchGraph { /* * (non-Javadoc) * * @see edu.cmu.sphinx.linguist.SearchGraph#getInitialState() */ public SearchState getInitialState() { InitialState initialState = new InitialState(); initialState.addArc(new GrammarState(grammar.getInitialNode())); // add an out-of-grammar branch if configured to do so if (addOutOfGrammarBranch) { OutOfGrammarGraph oogg = new OutOfGrammarGraph (phoneLoopAcousticModel, logOutOfGrammarBranchProbability, logPhoneInsertionProbability); initialState.addArc(oogg.getOutOfGrammarGraph()); } return initialState; } /* * (non-Javadoc) * * @see edu.cmu.sphinx.linguist.SearchGraph#getNumStateOrder() */ public int getNumStateOrder() { return 5; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -