Example #1
0
        /// <summary>
        /// Analyze trace table.
        /// </summary>
        /// <param name="traceTable">tracing target</param>
        /// <param name="distance">distance of samples</param>
        /// <returns>MatchingResult data.</returns>
        public static MatchingResult Trace(int[,] traceTable, double distance)
        {
            MatchingResult r = new MatchingResult();

            r.Distance = distance;
            int               tf            = traceTable.GetLength(1);
            int               rf            = traceTable.GetLength(0);
            int               ri            = rf - 1;
            int               ti            = tf - 1;
            List <int>        insertions    = new List <int>();
            List <IndexTuple> deletions     = new List <IndexTuple>();
            List <IndexTuple> substitutions = new List <IndexTuple>();

            while (ri > 0 && ti > 0)
            {
                int min = new[] { traceTable[ri - 1, ti], traceTable[ri, ti - 1], traceTable[ri - 1, ti - 1] }
                .Min();
                if (traceTable[ri - 1, ti - 1] == min)
                {
                    if (traceTable[ri, ti] != traceTable[ri - 1, ti - 1])
                    {
                        substitutions.Add(new IndexTuple(ti - 1, ri - 1));
                    }
                    ri--; ti--;
                }
                else if (traceTable[ri, ti - 1] == min)
                {
                    insertions.Add(ti - 1);
                    ti--;
                }
                else
                {
                    deletions.Add(new IndexTuple(ti, ri - 1));
                    ri--;
                }
            }
            if (ri != 0)
            {
                // reference index is remain.
                // -> Deletion error
                Enumerable.Range(0, ri)
                .ForEach(i => deletions.Add(new IndexTuple(0, i)));
            }
            if (ti != 0)
            {
                // test index is remain.
                // -> Insertion error
                Enumerable.Range(0, ti)
                .ForEach(insertions.Add);
            }
            // OrderBy method is a stable sort.
            r.InsertionIndexes    = insertions.OrderBy(i => i).ToArray();
            r.DeletionIndexes     = deletions.OrderBy(i => i.IndexOfReference).OrderBy(i => i.IndexOfText).ToArray();
            r.SubstitutionIndexes = substitutions.OrderBy(i => i.IndexOfReference).OrderBy(i => i.IndexOfText).ToArray();
            return(r);
        }
Example #2
0
 /// <summary>
 /// Analyze trace table.
 /// </summary>
 /// <param name="traceTable">tracing target</param>
 /// <param name="distance">distance of samples</param>
 /// <returns>MatchingResult data.</returns>
 public static MatchingResult Trace(int[,] traceTable, double distance)
 {
     MatchingResult r = new MatchingResult();
     r.Distance = distance;
     int tf = traceTable.GetLength(1);
     int rf = traceTable.GetLength(0);
     int ri = rf - 1;
     int ti = tf - 1;
     List<int> insertions = new List<int>();
     List<IndexTuple> deletions = new List<IndexTuple>();
     List<IndexTuple> substitutions = new List<IndexTuple>();
     while (ri > 0 && ti > 0)
     {
         int min = new[] { traceTable[ri - 1, ti], traceTable[ri, ti - 1], traceTable[ri - 1, ti - 1] }
             .Min();
         if (traceTable[ri - 1, ti - 1] == min)
         {
             if (traceTable[ri, ti] != traceTable[ri - 1, ti - 1])
                 substitutions.Add(new IndexTuple(ti - 1, ri - 1));
             ri--; ti--;
         }
         else if (traceTable[ri, ti - 1] == min)
         {
             insertions.Add(ti - 1);
             ti--;
         }
         else
         {
             deletions.Add(new IndexTuple(ti, ri - 1));
             ri--;
         }
     }
     if (ri != 0)
     {
         // reference index is remain.
         // -> Deletion error
         Enumerable.Range(0, ri)
             .ForEach(i => deletions.Add(new IndexTuple(0, i)));
     }
     if (ti != 0)
     {
         // test index is remain.
         // -> Insertion error
         Enumerable.Range(0, ti)
             .ForEach(insertions.Add);
     }
     // OrderBy method is a stable sort.
     r.InsertionIndexes = insertions.OrderBy(i => i).ToArray();
     r.DeletionIndexes = deletions.OrderBy(i => i.IndexOfReference).OrderBy(i => i.IndexOfText).ToArray();
     r.SubstitutionIndexes = substitutions.OrderBy(i => i.IndexOfReference).OrderBy(i => i.IndexOfText).ToArray();
     return r;
 }