sentencehmmstate.java
来自「It is the Speech recognition software. 」· Java 代码 · 共 713 行 · 第 1/2 页
JAVA
713 行
* @param state true if this is a final state */ public void setFinalState(boolean state) { if (state) { this.fields |= MASK_IS_FINAL; } else { this.fields &= ~MASK_IS_FINAL; } } /** * Determines if this state is a unit state * * @return <code>true</code> if the state is a unit state. */ public boolean isUnit() { return false; } /** * Dumps this SentenceHMMState and all its successors. Just for debugging. */ public void dumpAll() { visitStates(new SentenceHMMStateVisitor() { public boolean visit(SentenceHMMState state) { state.dump(); return false; } }, this, true); } /** * Returns any annotation for this state * * @return the annotation */ protected String getAnnotation() { return ""; } /** * Dumps this state */ private void dump() { System.out.println(" ----- " + getTitle() + " ---- "); for (int i = 0; i < getSuccessors().length; i++) { SentenceHMMStateArc arc = (SentenceHMMStateArc) getSuccessors()[i]; System.out.println(" -> " + arc.getState().toPrettyString()); } } /** * Validates this SentenceHMMState and all successors * */ public void validateAll() { // TODO fix me } /** * Gets the name for this state * * @return the name */ public String getName() { return name; } /** * Returns a pretty name for this HMM * * @return a pretty name */ public String getPrettyName() { return getName(); } /** * Returns the string representation of this object */ public String toString() { if (cachedName == null) { StringBuffer sb = new StringBuffer(); if (isEmitting()) { sb.append("*"); } sb.append(getName()); String base = (isEmitting() ? "*" : "") + getName() + getWhich() + (isFinal() ? "!" : ""); if (parent != null) { sb.append("_"); sb.append(parent.toString()); } if (isFinal()) { sb.append("!"); } cachedName = sb.toString(); } return cachedName; } /* * Returns a pretty version of the string representation * for this object * * @return a pretty string */ public String toPrettyString() { return toString(); } /** * Gets the fullName for this state * * @return the full name for this state */ public String getFullName() { if (fullName == null) { if (parent == null) { fullName = getName(); } else { fullName = getName() + "." + parent.getFullName(); } } return fullName; } /** * Gets the signature for this state * * @return the signature */ public String getSignature() { return getFullName(); } /** * gets the title (fullname + stateNumber) * for this state * * @return the title */ public String getTitle() { return getFullName() + ":" + stateNumber; // return getSignature() + ":" + stateNumber; } /** * Retrieves the index for this state * words * * @return the index */ public int getWhich() { return (fields >> SHIFT_WHICH) & MASK_WHICH; } /** * Sets the index for this state * * @param which the index for this state */ public void setWhich(int which) { assert which >= 0 && which <= MASK_WHICH; fields |= (which & MASK_WHICH) << SHIFT_WHICH; } /** * Retrieves the parent sate * * @return the parent state (or null if this state does not have a * parent state). */ public SentenceHMMState getParent() { return parent; } /** * Sets the parent state for this state * * @param parent the parent state */ private void setParent(SentenceHMMState parent) { this.parent = parent; } /** * Searches the set of arcs for an arc that points to a state with * an identical value * * @param state the state to search for * * @return the arc or null if none could be found. */ public SentenceHMMStateArc findArc(SentenceHMMState state) { SentenceHMMStateArc arc = (SentenceHMMStateArc) arcs.get(state.getValueSignature()); return arc; } /** * Returns the value signature of this unit * * @return the value signature */ public String getValueSignature() { return getFullName(); } /** * Visit all of the states starting at start with the given vistor * * @param visitor the state visitor * @param start the place to start the search * @param sorted if true, states are sorted before visited * * @return true if the visiting was terminated before all nodes * were visited */ public static boolean visitStates(SentenceHMMStateVisitor visitor, SentenceHMMState start, boolean sorted) { Set states = collectStates(start); if (sorted) { // sort the states by stateNumber TreeSet sortedStates = new TreeSet(new Comparator() { public int compare(Object o1, Object o2) { SentenceHMMState so1 = (SentenceHMMState) o1; SentenceHMMState so2 = (SentenceHMMState) o2; return so1.stateNumber - so2.stateNumber; } }); sortedStates.addAll(states); states = sortedStates; } for (Iterator i = states.iterator(); i.hasNext();) { SentenceHMMState state = (SentenceHMMState) i.next(); if (visitor.visit(state)) { return true; } } return false; } /** * Sets the color for this node * * @param color the color of this node */ public void setColor(Color color) { if (color == Color.RED) { this.fields |= MASK_COLOR_RED; } else { this.fields &= ~MASK_COLOR_RED; } } /** * Gets the color for this node * * @return the color of this node */ public Color getColor() { if ((fields & MASK_COLOR_RED) == MASK_COLOR_RED) { return Color.RED; } else { return Color.GREEN; } } /** * Sets the state number for this state * * @param stateNumber the state number */ private void setStateNumber(int stateNumber) { this.stateNumber = stateNumber; } /** * Gets the state number for this state * * @return the state number */ private int getStateNumber() { return stateNumber; } /** * Collect all states starting from the given start state * * @param start the state to start the search from * * @return the set of collected state */ static public Set collectStates(SentenceHMMState start) { Set visitedStates = new HashSet(); List queue = new LinkedList(); queue.add(start); while (queue.size() > 0) { SentenceHMMState state = (SentenceHMMState) queue.remove(0); visitedStates.add(state); SentenceHMMStateArc[] successors = state.getSuccessorArray(); for (int i = 0; i < successors.length; i++) { SentenceHMMStateArc arc = successors[i]; SentenceHMMState nextState = (SentenceHMMState) arc.getState(); if (!visitedStates.contains(nextState)) { queue.add(nextState); } } } return visitedStates; } /** * Returns the order of this particular state * * @return the state order for this state */ abstract public int getOrder();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?