⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
字号:
/* * Copyright 1999-2002 Carnegie Mellon University.   * Portions Copyright 2002 Sun Microsystems, Inc.   * Portions Copyright 2002 Mitsubishi Electric Research Laboratories. * All Rights Reserved.  Use is subject to license terms. *  * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL  * WARRANTIES. * */package edu.cmu.sphinx.trainer;import java.util.List;import java.util.ArrayList;import java.util.Iterator;/** * Defines the basic Node for any graph * A generic graph Node must have a list of outgoing edges * and an identifier. */public class Node {    // Do we really need nodeId and object? Maybe we can use object as    // the id when we assign a string to it.    /**     * The identifier for this Node     */    private String nodeId;    /**     * Object contained in this mode. Typically, an HMM state, a     * senone.     */    private Object object;    /** The type of node, such as a dummy node or node represented by     * a specific type of symbol     */    private NodeType nodeType;    /**     * The list of incoming edges to this node.     */    private List incomingEdges;    private Iterator incomingEdgeIterator;    /**     * The list of outgoing edges from this node     */    private List outgoingEdges;    private Iterator outgoingEdgeIterator;    /**     * Constructor for node when a type and symbol are given.     *     * @param nodeType the type of node.     * @param nodeSymbol the symbol for this type.     */    Node(NodeType nodeType, String nodeSymbol) {        incomingEdges = new ArrayList();        outgoingEdges = new ArrayList();	this.nodeId = nodeSymbol;	this.nodeType = nodeType;	this.object = null;    }    /**     * Constructor for node when a type only is given.     *     * @param nodeType the type of node.     */    Node(NodeType nodeType) {        this(nodeType, (String)null);    }    /**     * Assign an object to this node.     *     * @param object the object to assign     */    public void setObject(Object object) {	this.object = object;    }    /**     * Retrieves the object associated with this node.     *     * @return the object     */    public Object getObject() {	return object;    }    /**     * Method to add an incoming edge.     * Note that we do not check if the destination node of the     * incoming edge is identical to this node     *     * @param edge the incoming edge     */    public void addIncomingEdge(Edge edge){        incomingEdges.add(edge);    }    /**     * Start iterator for incoming edges.     */    public void startIncomingEdgeIterator() {	incomingEdgeIterator = incomingEdges.iterator();    }    /**     * Whether there are more incoming edges.     *     * @return if true, there are more incoming edges     */    public boolean hasMoreIncomingEdges() {	return incomingEdgeIterator.hasNext();    }    /**     * Returns the next incoming edge to this node.     *     * @return the next edge incoming edge     */    public Edge nextIncomingEdge() {	return (Edge) incomingEdgeIterator.next();    }    /**     * Returns the size of the incoming edges list.     *     * @return the number of incoming edges     */    public int incomingEdgesSize() {	return incomingEdges.size();    }    /**     * Method to add an outgoing edge.     * Note that we do not check if the source node of the outgoing     * edge is identical to this node     *     * @param edge the outgoing edge     */    public void addOutgoingEdge(Edge edge){        outgoingEdges.add(edge);    }    /**     * Start iterator for outgoing edges.     */    public void startOutgoingEdgeIterator() {	outgoingEdgeIterator = outgoingEdges.iterator();    }    /**     * Whether there are more outgoing edges.     *     * @return if true, there are more outgoing edges     */    public boolean hasMoreOutgoingEdges() {	return outgoingEdgeIterator.hasNext();    }    /**     * Returns the next outgoing edge from this node.     *     * @return the next outgoing edge     */    public Edge nextOutgoingEdge() {	return (Edge) outgoingEdgeIterator.next();    }    /**     * Returns the size of the outgoing edges list.     *     * @return the number of outgoing edges     */    public int outgoingEdgesSize() {	return outgoingEdges.size();    }    /**     * Method to check the type of a node.     *     * @return if true, this node is of the type specified     */    public boolean isType(String type){        return (type.equals(this.nodeType.toString()));    }    /**     * Returns type of a node.     *     * @return returns the type of this node     */    public NodeType getType() {        return nodeType;    }    /**     * Returns the ID of a node. Typically, a string representing a     * word or a phoneme.     *     * @return this node's ID     */    public String getID() {        return nodeId;    }    /**     * Validade node. Checks if all nodes have at least one incoming     * and one outgoing edge.     *     * @return if true, node passed validation     */    public boolean validate() {	boolean passed = true;	if (isType("WORD") || isType("PHONE")) {	    if (nodeId == null) {		System.out.println("Content null in a WORD node.");		passed = false;	    }	}	if ((incomingEdgesSize() == 0) && (outgoingEdgesSize() == 0)) {	    System.out.println("Node not connected anywhere.");	    passed = false;	}	return passed;    }    /**     * Prints out this node.     */    public void print() {	System.out.print("ID: " + nodeId);	System.out.print(" Type: " + nodeType.toString() + " | ");	for (startIncomingEdgeIterator();	     hasMoreIncomingEdges();) {	    System.out.print(nextIncomingEdge() + " ");	}	System.out.print(" | ");	for (startOutgoingEdgeIterator();	     hasMoreOutgoingEdges();) {	    System.out.print(nextOutgoingEdge() + " ");	}	System.out.println();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -