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

📄 edge.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.result;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.util.StringTokenizer;/** * Edges are part of Lattices.  They connect Nodes, and contain the score * associated with that sequence. */public class Edge {    protected double acousticScore;    protected double lmScore;    protected Node fromNode;    protected Node toNode;    /**     * Create an Edge from fromNode to toNode with acoustic and     * Language Model scores.     *     * @param fromNode     * @param toNode     * @param acousticScore     * @param lmScore     */    protected Edge( Node fromNode, Node toNode,                    double acousticScore, double lmScore ) {        this.acousticScore = acousticScore;        this.lmScore = lmScore;        this.fromNode = fromNode;        this.toNode = toNode;    }    public String toString() {        return "Edge(" + fromNode + "-->" + toNode + "[" + acousticScore                + "," + lmScore + "])";    }    /**     * Internal routine used when creating a Lattice from a .LAT file     * @param lattice     * @param tokens     */    static void load( Lattice lattice, StringTokenizer tokens ) {        String from = tokens.nextToken();        String to = tokens.nextToken();        int score = Integer.parseInt( tokens.nextToken() );        Node fromNode = lattice.getNode(from);        if( fromNode == null ) {            throw new Error( "Edge fromNode \"" + from + "\" does not exist" );        }        Node toNode = lattice.getNode(to);        if( fromNode == null ) {            throw new Error( "Edge toNode \"" + to + "\" does not exist" );        }        lattice.addEdge(fromNode,toNode,score,0.0);    }    /**     * Internal routine used when dumping a Lattice as a .LAT file     * @param f     * @throws IOException     */    void dump(PrintWriter f) throws IOException {        f.println( "edge: " + fromNode.getId() + " " + toNode.getId() + " "                    + acousticScore + " " + lmScore );    }    /**     * Internal routine used when dumping a Lattice as an AiSee file     * @param f     * @throws IOException     */    void dumpAISee(FileWriter f) throws IOException {        f.write( "edge: { sourcename: \"" + fromNode.getId()                + "\" targetname: \"" + toNode.getId()                + "\" label: \"" + acousticScore + "," + lmScore + "\" }\n" );    }    /**     * Get the acoustic score associated with an Edge     * @return the score     */    public double getAcousticScore() {        return acousticScore;    }    /**     * Get the language model score associated with an Edge     * @return the score     */    public double getLMScore() {        return lmScore;    }    /**     * Get the "from" Node associated with an Edge     * @return the Node     */    public Node getFromNode() {        return fromNode;    }    /**     * Get the "to" Node associated with an Edge     * @return the Node     */    public Node getToNode() {        return toNode;    }    /**     * Sets the acoustic score     *     * @param v the acoustic score.     */    public void setAcousticScore(double v) {        acousticScore = v;    }    /**     * Sets the language model score      *     * @param v the lm score.     */    public void setLMScore(double v) {        lmScore = v;    }    /**     * Returns true if the given edge is equivalent to this edge.     * Two edges are equivalent only if they have their 'fromNode'     * and 'toNode' are equivalent, and that their acoustic and language     * scores are the same.     *     * @param other the Edge to compare this Edge against     *     * @return true if the Edges are equivalent; false otherwise     */    public boolean isEquivalent(Edge other) {        /*         * TODO: Figure out why there would be minute differences         * in the acousticScore. Therefore, the equality of the acoustic         * score is judge based on whether the difference is bigger than 1.         */        double diff = Math.abs(acousticScore) * 0.00001;        return ((Math.abs(acousticScore - other.getAcousticScore()) <= diff &&                 lmScore == other.getLMScore()) &&                (fromNode.isEquivalent(other.getFromNode()) &&                 toNode.isEquivalent(other.getToNode())));    }}

⌨️ 快捷键说明

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