示例#1
0
        /// <summary>
        /// Writes a CSV file representing a character-level error table for this session.
        /// </summary>
        /// <param name="writer">The stream writer to write the file.</param>
        /// <param name="useInputStream">A boolean indicating whether the input stream should
        /// be considered or only the presented and transcribed strings.</param>
        /// <returns>True if successful; false otherwise.</returns>
        public bool WriteCharacterErrorTable(StreamWriter writer, bool useInputStream)
        {
            bool success = true;

            try
            {
                CharacterErrorTable table = !useInputStream ? new CharacterErrorTable() : new CharacterErrorTableEx(); // polymorphism!

                for (int i = 0; i < _trials.Count; i++)
                {
                    TrialData     td = _trials[i];
                    List <string> Plist, Tlist;
                    if (!useInputStream)
                    {
                        int nAlign = td.ComputeAlignments(out Plist, out Tlist);
                        for (int j = 0; j < nAlign; j++)
                        {
                            table.RecordEntries(Plist[j], Tlist[j], null, nAlign);
                        }
                    }
                    else
                    {
                        List <string> ISlist;
                        int           nAlign = td.ComputeAlignments(out Plist, out Tlist, out ISlist);
                        for (int j = 0; j < nAlign; j++)
                        {
                            table.RecordEntries(Plist[j], Tlist[j], ISlist[j], nAlign);
                        }
                    }
                }
                table.CalculateErrorProbabilities();
                table.WriteToCsv(writer, false);
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex);
                success = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                success = false;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
            return(success);
        }
示例#2
0
        /// <summary>
        /// Writes a CSV file representing a character-level confusion matrix for this session.
        /// </summary>
        /// <param name="writer">The stream writer to write the file.</param>
        /// <param name="useInputStream">A boolean indicating whether the input stream should
        /// be considered or only the presented and transcribed strings.</param>
        /// <returns>True if successful; false otherwise.</returns>
        public bool WriteConfusionMatrix(StreamWriter writer, bool useInputStream)
        {
            bool success = true;

            try
            {
                ConfusionMatrix matrix = !useInputStream ? new ConfusionMatrix() : new ConfusionMatrixEx(); // polymorphism!

                for (int i = 0; i < _trials.Count; i++)
                {
                    TrialData     td = _trials[i];
                    List <string> Plist, Tlist;
                    if (!useInputStream)
                    {
                        int nAlign = td.ComputeAlignments(out Plist, out Tlist);
                        for (int j = 0; j < nAlign; j++)
                        {
                            matrix.RecordEntries(Plist[j], Tlist[j], null, nAlign);
                        }
                    }
                    else
                    {
                        List <string> ISlist;
                        int           nAlign = td.ComputeAlignments(out Plist, out Tlist, out ISlist);
                        for (int j = 0; j < nAlign; j++)
                        {
                            matrix.RecordEntries(Plist[j], Tlist[j], ISlist[j], nAlign);
                        }
                    }
                }
                matrix.WriteToCsv(writer);
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex);
                success = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                success = false;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
            return(success);
        }