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

📄 configurationmanager.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        done = true;                    } else if (in.equals(".")) {                        return;                    } else {                        try {                            setProperty(name, propName, in);                            done = true;                        } catch  (PropertyException pe) {                            System.out.println("error setting value " + pe);                            svalue = in;                        }                    }                }            } catch (PropertyException pe) {                System.out.println("error getting values " + pe);            } catch (IOException ioe) {                System.out.println("Trouble reading input");                return;            }        }    }    // TODO: some experimental dumping functions, dump the config    // as HTML and as GDL. These should probably be moved out to    // the config monitor.    // TODO this dumping code is not done yet.    /**     * Dumps the config as a set of HTML tables     *      * @param path     *                where to output the HTML     * @throws IOException     *                 if an error occurs     */    public void showConfigAsHTML(String path) throws IOException {        PrintStream out = new PrintStream(new FileOutputStream(path));        dumpHeader(out);        String[] allNames = getInstanceNames(Object.class);        for (int i = 0; i < allNames.length; i++) {            dumpComponentAsHTML(out, allNames[i]);        }        dumpFooter(out);        out.close();    }    /**     * Dumps the header for HTML output     *      * @param out     *                the output stream     */    private void dumpHeader(PrintStream out) {        out.println("<html><head>");        out.println("    <title> Sphinx-4 Configuration</title");        out.println("</head>");        out.println("<body>");    }    /**     * Retrieves the global log level     *      * @return the global log level     */    String getGlobalLogLevel() {        String level = getMyGlobalProperty(ConfigurationManager.PROP_COMMON_LOG_LEVEL);        if (level == null) {            level = Level.WARNING.getName();        }        return level;    }    /**     * Dumps the footer for HTML output     *      * @param out     *                the output stream     */    private void dumpFooter(PrintStream out) {        out.println("</body>");        out.println("</html>");    }    /**     * Dumps the given component as HTML to the given stream     *      * @param out     *                where to dump the HTML     * @param name     *                the name of the component to dump     */    private void dumpComponentAsHTML(PrintStream out, String name) {        Symbol symbol = (Symbol) symbolTable.get(name);        out.println("<table border=1>");        //        out.println("<table border=1 width=\"%80\">");        out.print("    <tr><th bgcolor=\"#CCCCFF\" colspan=2>");        //       out.print("<a href="")        out.print(name);        out.print("</a>");        out.println("</td></tr>");        out                .println("    <tr><th bgcolor=\"#CCCCFF\">Property</th><th bgcolor=\"#CCCCFF\"> Value</th></tr>");        Registry registry = symbol.getRegistry();        Collection propertyNames = registry.getRegisteredProperties();        PropertySheet properties = symbol.getPropertySheet();        for (Iterator j = propertyNames.iterator(); j.hasNext();) {            String propName = (String) j.next();            out.print("    <tr><th align=\"leftt\">" + propName + "</th>");            Object obj;            try {                obj = properties.getRaw(propName);            } catch (PropertyException e) {                // this exception can occcur if a global name                // can't be resolved ...                obj = "[Unresolved!]";                out.println("<td>" + obj + "</td></tr>");            }            if (obj instanceof String) {                out.println("<td>" + obj + "</td></tr>");            } else if (obj instanceof List) {                List l = (List) obj;                out.println("    <td><ul>");                for (Iterator k = l.iterator(); k.hasNext();) {                    out.println("        <li>" + k.next() + "</li>");                }                out.println("    </ul></td>");            } else {                out.println("<td>DEFAULT</td></tr>");            }        }        out.println("</table><br>");    }    /**     * Dumps the config as a GDL plot     *      * @param path     *                where to output the GDL     * @throws IOException     *                 if an error occurs     */    public void showConfigAsGDL(String path) throws IOException {        PrintStream out = new PrintStream(new FileOutputStream(path));        dumpGDLHeader(out);        String[] allNames = getInstanceNames(Object.class);        for (int i = 0; i < allNames.length; i++) {            dumpComponentAsGDL(out, allNames[i]);        }        dumpGDLFooter(out);        out.close();    }    /**     * Dumps the given component as GDL to the given stream     *      * @param out     *                where to dump the GDL     * @param name     *                the name of the component to dump     */    private void dumpComponentAsGDL(PrintStream out, String name) {        out.println("node: {title: \"" + name + "\" color: " + getColor(name)                + "}");        Symbol symbol = (Symbol) symbolTable.get(name);        Registry registry = symbol.getRegistry();        Collection propertyNames = registry.getRegisteredProperties();        PropertySheet properties = symbol.getPropertySheet();        for (Iterator i = propertyNames.iterator(); i.hasNext();) {            String propName = (String) i.next();            PropertyType type = registry.lookup(propName);            try {                Object val = properties.getRaw(propName);                if (val != null) {                    if (type == PropertyType.COMPONENT) {                        out.println("edge: {source: \"" + name                                + "\" target: \"" + val + "\"}");                    } else if (type == PropertyType.COMPONENT_LIST) {                        List list = (List) val;                        for (Iterator j = list.iterator(); j.hasNext();) {                            Object dest = j.next();                            out.println("edge: {source: \"" + name                                    + "\" target: \"" + dest + "\"}");                        }                    }                }            } catch (PropertyException e) {                // nothing to do , its up to you            }        }    }    /**     * Gets the color for the given component     *      * @param componentName     *                the name of the component     * @return the color name for the component     */    private String getColor(String componentName) {        try {            Configurable c = lookup(componentName);            Class cls = c.getClass();            if (cls.getName().indexOf(".recognizer") > 1) {                return "cyan";            } else if (cls.getName().indexOf(".tools") > 1) {                return "darkcyan";            } else if (cls.getName().indexOf(".decoder") > 1) {                return "green";            } else if (cls.getName().indexOf(".frontend") > 1) {                return "orange";            } else if (cls.getName().indexOf(".acoustic") > 1) {                return "turquoise";            } else if (cls.getName().indexOf(".linguist") > 1) {                return "lightblue";            } else if (cls.getName().indexOf(".instrumentation") > 1) {                return "lightgrey";            } else if (cls.getName().indexOf(".util") > 1) {                return "lightgrey";            }        } catch (InstantiationException e) {            return "black";        } catch (PropertyException e) {            return "black";        }        return "darkgrey";    }    /**     * Outputs the GDL header     *      * @param out     *                the output stream     */    private void dumpGDLHeader(PrintStream out) {        out.println(" graph: {title: \"unix evolution\" ");        out.println("         layoutalgorithm: tree");        out.println("          scaling        : 2.0");        out.println("          colorentry 42  : 152 222 255");        out.println("     node.shape     : ellipse");        out.println("      node.color     : 42 ");        out.println("node.height    : 32  ");        out.println("node.fontname  : \"helvB08\"");        out.println("edge.color     : darkred");        out.println("edge.arrowsize :  6    ");        out.println("node.textcolor : darkblue ");        out.println("splines        : yes");    }    /**     * Dumps the footer for GDL output     *      * @param out     *                the output stream     */    private void dumpGDLFooter(PrintStream out) {        out.println("}");    }    /**     * Strips the ${ and } off of a global symbol of the form     * ${symbol}.     *     * @param symbol the symbol to strip     *     * @return the stripped symbol     */    private String stripGlobalSymbol(String symbol) {        Matcher matcher = globalSymbolPattern.matcher(symbol);        if (matcher.matches()) {            return matcher.group(1);        } else {            return symbol;        }    }    /**     * Generate a string of the given character      *     * @param c the character     * @param count the length of the string     *     * @return the padded string     */    private String pad(char c, int count) {        StringBuffer sb = new StringBuffer();        for (int i = 0; i < count; i++) {            sb.append(c);        }        return sb.toString();    }}

⌨️ 快捷键说明

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