예제 #1
0
        private async Task <IEnumerable <string> > CalcAlignments(int i, int j)
        {
            var list = new List <string>();

            if ((i == 0) && (j == 0))
            {
                return(list);
            }

            LevField field = null;

            try
            {
                field = M[i, j];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            if (field.Direction == ELevDirection.None)
            {
                return(null);
            }



            return(null);
        }
예제 #2
0
        public int CalculateLevenshteinDistance(string input1, string input2, bool useHeristic = false)
        {
            m = input1.Length;
            n = input2.Length;

            int dLength = Math.Abs(m - n);
            int colOffset = 0, rowOffset = 0;

            if (m < n)
            {
                colOffset = dLength;
            }
            if (n < m)
            {
                rowOffset = dLength;
            }


            int minLength = Math.Min(n, m);

            a = input1;
            b = input2;

            M = new LevField[m + 1, n + 1];
            int colStart = 0;
            int colEnd   = 0;
            var K        = 0;

            int      f, currentStart = 0;
            LevField dist;

            K = Helper.HammingDistance(a, b);
            if (useHeristic)
            {
                for (int i = 0; i <= m; ++i)
                {
                    //K = Helper.HammingDistance(a, b, minPos.Item1, minPos.Item2) + rowMin;
                    //Console.WriteLine(K);
                    //rowMin = int.MaxValue;
                    if (colStart != 0)
                    {
                        currentStart = colStart;
                    }
                    colStart = 0;
                    for (int j = currentStart; j <= n; ++j)
                    {
                        dist = new LevField(levDistanceDirection(i, j));

                        f = dist + Math.Abs((m - i) - (n - j));

                        if (f >= K)
                        {
                            //skipCols = (f == K) ? 1 : 2;
                            if (m < n)
                            {
                                if (j < i)
                                {
                                    colStart = (colStart == 0) ? j + ((f == K) ? 1 : 2) : colStart;
                                }
                                else if ((colEnd < j) && (j - dLength > i))
                                {
                                    if (f == K)
                                    {
                                        M[i, j] = dist;
                                        colEnd  = j;
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                if (j + dLength < i)
                                {
                                    colStart = (colStart == 0) ? j + ((f == K) ? 1 : 2) : colStart;
                                }
                                else if ((colEnd < j) && (j > i))
                                {
                                    if (f == K)
                                    {
                                        M[i, j] = dist;
                                        colEnd  = j;
                                    }
                                    break;
                                }
                            }
                        }

                        M[i, j] = dist;

                        //Console.WriteLine(this);
                        //Thread.Sleep(100);
                    }
                }
            }
            else
            {
                for (int i = 0; i <= m; ++i)
                {
                    for (int j = 0; j <= n; ++j)
                    {
                        M[i, j] = new LevField(levDistanceDirection(i, j));
                    }
                }
            }


            return(this.LevenshteinDistance);
        }