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

📄 nistalign.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                / ((float) totalReferenceWords);        }    }    /**     * Returns the total sentence accuracy.     *     * @return the accuracy between 0.0 and 1.0     */    public float getTotalSentenceAccuracy() {        int totalSentencesCorrect = totalSentences - totalSentencesWithErrors;        if (totalSentences == 0) {            return 0;        } else {            return ((float) totalSentencesCorrect / (float) totalSentences);        }    }    /**     * Gets the total number of words     *     * @return the total number of words     */    public int getTotalWords() {        return totalReferenceWords;    }    /**     * Gets the total number of substitution errors     *     * @return the total number of substitutions     */    public int getTotalSubstitutions() {        return totalSubstitutions;    }    /**     * Gets the total number of insertion errors     *     * @return the total number of insertion errors     */    public int getTotalInsertions() {        return totalInsertions;    }    /**     * Gets the total number of deletions     *     * @return the total number of deletions     */    public int getTotalDeletions() {        return totalDeletions;    }    /**     * Gets the total number of sentences     *     * @return the total number of sentences     */    public int getTotalSentences() {        return totalSentences;    }    /**     * Gets the total number of sentences with errors     *     * @return the total number of sentences with errors     */    public int getTotalSentencesWithErrors() {        return totalSentencesWithDeletions;    }    /**     * Prints the results for this sentence to System.out.  If you     * want the output to match the NIST output, see     * printNISTSentenceSummary.     *     * @see #printNISTSentenceSummary     */    public void printSentenceSummary() {        if (showResults) {            System.out.println("REF:       " + toString(referenceWords));            System.out.println("HYP:       " + toString(hypothesisWords));        }                if (showAlignedResults) {            System.out.println("ALIGN_REF: " + toString(alignedReferenceWords));            System.out.println("ALIGN_HYP: " + toString(alignedHypothesisWords));        }    }    /**     * Prints the total summary for all calls.  If you want the output     * to match the NIST output, see printNISTTotalSummary.     *     * @see #printNISTTotalSummary     */    public void printTotalSummary() {        if (totalSentences > 0) {            float wordErrorRate = getTotalWordErrorRate();	    System.out.print(                "   Accuracy: " + toPercentage("##0.000%",                                               getTotalWordAccuracy()));	    System.out.println(                "    Errors: " + getTotalWordErrors()                 + "  (Sub: " + totalSubstitutions                + "  Ins: " + totalInsertions                + "  Del: " + totalDeletions + ")");            System.out.println(                "   Words: " + totalReferenceWords                 + "   Matches: " + totalWordsCorrect                + "    WER: " + toPercentage("##0.000%",                                             getTotalWordErrorRate()));	    System.out.println(                "   Sentences: " + totalSentences                + "   Matches: " + (totalSentences - totalSentencesWithErrors)                + "   SentenceAcc: " + toPercentage("##0.000%",                                                    getTotalSentenceAccuracy()));	}    }        /**     * Prints the results for this sentence to System.out.  This     * matches the output from the NIST aligner.     */    public void printNISTSentenceSummary() {        int sentenceErrors = substitutions + insertions + deletions;                System.out.println();                System.out.print("REF: " + toString(alignedReferenceWords));        if (referenceAnnotation != null) {            System.out.print(" " + referenceAnnotation);        }                System.out.println();                System.out.print("HYP: " + toString(alignedReferenceWords));        if (referenceAnnotation != null) {            System.out.print(" " + referenceAnnotation);        }        System.out.println();        System.out.println();        if (referenceAnnotation != null) {            System.out.println("SENTENCE " + totalSentences                               + "  " + referenceAnnotation);        } else {            System.out.println("SENTENCE " + totalSentences);        }                System.out.println("Correct          = "                           + toPercentage("##0.0%",                                          correct,                                          referenceWords.size())                           + padLeft(5, correct)                           + "   ("                           + padLeft(6, totalWordsCorrect)                           + ")");        System.out.println("Errors           = "                           + toPercentage("##0.0%",                                          sentenceErrors,                                          referenceWords.size())                           + padLeft(5, sentenceErrors)                           + "   ("                           + padLeft(6, totalSentencesWithErrors)                           + ")");                System.out.println();        System.out.println(HRULE);    }        /**     * Prints the summary for all calls to align to System.out.  This     * matches the output from the NIST aligner.     */    public void printNISTTotalSummary() {        int totalSentencesCorrect = totalSentences - totalSentencesWithErrors;                System.out.println();        System.out.println("---------- SUMMARY ----------");        System.out.println();        System.out.println("SENTENCE RECOGNITION PERFORMANCE:");        System.out.println(            "sentences                          " + totalSentences);        System.out.println(            "  correct                  "            + toPercentage("##0.0%", totalSentencesCorrect, totalSentences)            + " (" + padLeft(4, totalSentencesCorrect) + ")");        System.out.println(            "  with error(s)            "            + toPercentage("##0.0%", totalSentencesWithErrors, totalSentences)            + " (" + padLeft(4, totalSentencesWithErrors) + ")");        System.out.println(            "    with substitutions(s)  "            + toPercentage("##0.0%", totalSentencesWithSubtitutions, totalSentences)            + " (" + padLeft(4, totalSentencesWithSubtitutions) + ")");        System.out.println(            "    with insertion(s)      "            + toPercentage("##0.0%", totalSentencesWithInsertions, totalSentences)            + " (" + padLeft(4, totalSentencesWithInsertions) + ")");        System.out.println(            "    with deletions(s)      "            + toPercentage("##0.0%", totalSentencesWithDeletions, totalSentences)            + " (" + padLeft(4, totalSentencesWithDeletions) + ")");        System.out.println();        System.out.println();        System.out.println();        System.out.println("WORD RECOGNITION PERFORMANCE:");        System.out.println(            "Correct           = "            + toPercentage("##0.0%", totalWordsCorrect, totalReferenceWords)            + " (" + padLeft(6, totalWordsCorrect) + ")");        System.out.println(            "Substitutions     = "            + toPercentage("##0.0%", totalSubstitutions, totalReferenceWords)            + " (" + padLeft(6, totalSubstitutions) + ")");        System.out.println(            "Deletions         = "            + toPercentage("##0.0%", totalDeletions, totalReferenceWords)            + " (" + padLeft(6, totalDeletions) + ")");        System.out.println(            "Insertions        = "            + toPercentage("##0.0%", totalInsertions, totalReferenceWords)            + " (" + padLeft(6, totalInsertions) + ")");        System.out.println(            "Errors            = "            + toPercentage("##0.0%", getTotalWordErrors(), totalReferenceWords)            + " (" + padLeft(6, getTotalWordErrors()) + ")");        System.out.println();                System.out.println(            "Ref. words           = " + padLeft(6, totalReferenceWords));        System.out.println(            "Hyp. words           = " + padLeft(6, totalHypothesisWords));        System.out.println(            "Aligned words        = " + padLeft(6, totalAlignedWords));        System.out.println();        System.out.println(            "WORD ACCURACY=  "            + toPercentage("##0.000%", totalWordsCorrect, totalReferenceWords)            + " ("            + padLeft(5, totalWordsCorrect)            + "/"            + padLeft(5, totalReferenceWords)            + ")  ERRORS= "            + toPercentage("##0.000%",                           getTotalWordErrors(),                           totalReferenceWords)            + " ("            + padLeft(5, getTotalWordErrors())            + "/"            + padLeft(5, totalReferenceWords)            + ")");                                               System.out.println();    }    /**        * Creates the backtrace table.  This is magic.  The basic idea is     * that the penalty table contains a set of penalty values based     * on some strategically selected numbers.  I'm not quite sure     * what they are, but they help determine the backtrace table     * values.  The backtrace table contains information used to help     * determine if words matched (OK), were inserted (INSERTION),     * substituted (SUBSTITUTION), or deleted (DELETION).     *     * @param referenceWords the ordered list of reference words     * @param hypothesisWords the ordered list of hypothesis words     *     * @return the backtrace table     */    int[][] createBacktraceTable(LinkedList referenceWords,                               LinkedList hypothesisWords) {        int[][] penaltyTable;        int[][] backtraceTable;        int penalty;        int minPenalty;	penaltyTable = 	    new int[referenceWords.size() + 1][hypothesisWords.size() + 1];	backtraceTable = 	    new int[referenceWords.size() + 1][hypothesisWords.size() + 1];	// Initialize the penaltyTable and the backtraceTable.  The	// rows of each table represent the words in the reference	// string.  The columns of each table represent the words in	// the hypothesis string.        //	penaltyTable[0][0] = 0;	backtraceTable[0][0] = OK;        // The lower left of the tables represent deletions.  If you	// think about this, a shorter hypothesis string will have        // deleted words from the reference string.        //	for (int i = 1; i <= referenceWords.size(); i++) {	    penaltyTable[i][0] = DELETION_PENALTY * i;	    backtraceTable[i][0] = DELETION;	}        // The upper right of the tables represent insertions.  If        // you think about this, a longer hypothesis string will have        // inserted words.        //	for (int j = 1; j <= hypothesisWords.size(); j++) {	    penaltyTable[0][j] = INSERTION_PENALTY * j;	    backtraceTable[0][j] = INSERTION;        }        // Row-by-row, column-by-column, fill out the tables.        // The goal is to keep the penalty for each cell to a        // minimum.

⌨️ 快捷键说明

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