Example #1
0
        public void find_lcs()
        {
            /* * | *  A  B  C  D  C  B  A
             * ---------------------------
             * | 0  0  0  0  0  0  0  0    <---- (Initialise all to 0)
             * ---------------------------
             * D | 0  0  0  0  1  1  1  1
             * ---------------------------
             * C | 0  0  0  1  1  2  2  2
             * ---------------------------
             * B | 0  0  1  1  1  2  3  3
             * ---------------------------
             * A | 0  1  1  1  1  2  3  4
             * ---------------------------
             * A | 0  1  1  1  1  2  3  4
             * ---------------------------
             * B | 0  1  2  2  2  2  3  4
             * ---------------------------
             * C | 0  1  2  3  3  3  3  4
             * ---------------------------
             *     ^
             |
             | (initialise all to 0)
             */

            var    lcs      = new LCS();
            string sequence = lcs.Find("ABCDCBA", "DCBAABC");

            Assert.AreEqual("DCBA", sequence);
        }
Example #2
0
        public float NormalizedLCS(AbstractContextInfo context)
        {
            var left  = ExtendedContext.Split(' ');
            var right = LocalContext.Split(' ');

            var lcs = LCS.Compute(left, right);

            return(2.0f * lcs / (left.Length + right.Length));
        }
Example #3
0
        public static string DiffReport <T>(IEnumerable <T> expected, IEnumerable <T> actual, IEqualityComparer <T> comparer = null, Func <T, string> toString = null, string separator = ",\r\n")
        {
            LCS <T> lcs = (comparer != null) ? new LCS <T>(comparer) : LCS <T> .Default;

            toString = toString ?? new Func <T, string>(obj => obj.ToString());

            IList <T> expectedList = expected as IList <T> ?? new List <T>(expected);
            IList <T> actualList   = actual as IList <T> ?? new List <T>(actual);

            return(string.Join(separator, lcs.CalculateDiff(expectedList, actualList, toString)));
        }
Example #4
0
        public void Ints()
        {
            Console.WriteLine("Test Integers");

            int[] ax = new int[]{ 2,2,3,1,2,3,4,5,6,7,8,9,0,6,6 };
            int[] bx = new int[]{ 2,1,3,3,4,5,6,7,9,1,1,2,3,5,6,6 };

            LCS<int> l = new LCS<int>( ax, bx );

            Console.WriteLine( "LCS Length {0} ", l.Length );
        }
Example #5
0
    // Driver Function
    public static void main(String[] args)
    {
        int[] arr1  = { 10, 15, 20, 25, 30, 35, 40 };
        int[] arr2  = { 10, 12, 23, 25, 28, 30, 32, 40 };
        int   size1 = arr1.Length;
        int   size2 = arr2.Length;
        LCS   obj   = new LCS();
        int   l     = obj.LongestCommonSubsequence(arr1, arr2, size1, size2);

        System.Write("Length of Longest Common Subsequence is: " + l);
    }
Example #6
0
        public void Length()
        {
            // Arrange
            int    expected = 4;
            string a        = "ACFSYGOS";
            string b        = "FSYG";

            // Act
            var actual = new LCS().GetLength(a, b);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void LCS_LongestCommonSubSequenceLength_Success_Test()
        {
            // Arrange
            string a = "ABACEB";
            String b = "ADBAACEB";

            // Act
            var length = LCS.LongestCommonSubSequenceLength(a.ToCharArray(), b.ToCharArray());

            // Assert

            Assert.AreEqual(6, length);
        }
Example #8
0
        public static LCS LCSubstr(string s1, string s2)
        {
            int[,] L = new int[2, s2.Length];
            int z           = 0;
            int foundIndex  = int.MaxValue;
            int foundIndex2 = 0;

            for (int i = 0; i < s1.Length; i++)
            {
                var iCur = i % 2;
                for (int j = 0; j < s2.Length; j++)
                {
                    bool first = i == 0 || j == 0 || L[1 - iCur, j - 1] == 0;

                    if (s1[i] == s2[j] && (s1[i] == ' ' || !first))
                    {
                        if (i == 0 || j == 0)
                        {
                            L[iCur, j] = 1;
                        }
                        else
                        {
                            L[iCur, j] = L[1 - iCur, j - 1] + 1;
                        }

                        if (s1[i] == ' ' && L[iCur, j] > z)
                        {
                            z           = L[iCur, j];
                            foundIndex  = i;
                            foundIndex2 = j;
                        }
                    }
                    else
                    {
                        L[iCur, j] = 0;
                    }
                }
            }

            var lcs = new LCS {
                Index1 = foundIndex - z + 1, Index2 = foundIndex2 - z + 1, Length = z
            };

            if (z == 0)
            {
                lcs.Index1 = -1;
                lcs.Index2 = -1;
            }

            return(lcs);
        }
Example #9
0
        public void FindSequences2()
        {
            String s2 = "ABAZDC";
            String s1 = "BACBAD";

            // Beklenen Sonuc: "GTAB"

            LCS lcs = new LCS(s1, s2);

            String sonuc = lcs.FindSequences();

            // Assert.AreEqual("Beklenen Deger", "Donen Sonuc");
            Assert.AreEqual("ABAD", sonuc);
        }
Example #10
0
        public void FindSequences1()
        {
            String s2 = "AGGTAB";
            String s1 = "GXTXAYB";

            // Beklenen Sonuc: "GTAB"

            LCS lcs = new LCS(s1, s2);

            String sonuc = lcs.FindSequences();

            // Assert.AreEqual("Beklenen Deger", "Donen Sonuc");
            Assert.AreEqual("GTAB", sonuc);
        }
Example #11
0
        public void Strings()
        {
            Console.WriteLine("Test Strings");

            string[] ax = "h u m a n".Split(' ');
            string[] bx = "c h i m p a n z e e".Split(' ');

            LCS<string> l = new LCS<string>( ax, bx );

            Console.WriteLine( "LCS Length {0}" , l.Length );

            string seq = String.Join("", l.Sequence.ToArray() );

            if ( !seq.Equals("hman") )
                throw new Exception("lcs failed!");
        }
Example #12
0
        public IActionResult SearchResult(string filename, string key)
        {
            // DirectoryInfo mydir = new DirectoryInfo(@"C:/Users/BS049/source/repos/CV Parsing/Resume4/wwwroot/Updates");
            DirectoryInfo mydir    = new DirectoryInfo(@"./wwwroot/Updates");
            string        path     = "./wwwroot/Updates/";
            ResumeView    model    = new ResumeView();
            int           MaxMatch = 0;

            FileInfo[]       f          = mydir.GetFiles();
            List <int>       LengthList = new List <int>();
            SearchResultView obj        = new SearchResultView();

            string filePath = path + filename;

            obj.Filename = filename;
            model.Text   = Helper.GetText(filePath);
            model.Text   = Helper.GetHtml(model.Text);
            obj.Len      = model.Text.Length;
            obj.htmlText = LCS.SearchFinalResult(model.Text, key);
            return(Ok(obj));
        }
Example #13
0
 public Substr(Section section, string text, LCS lcs)
 {
     Section = section;
     Text    = text;
     Lcs     = lcs;
 }
Example #14
0
            public static OResult <T> GetLongCommSubseq <T>(Tuple <T, int>[] prot1_resn_resi, Tuple <T, int>[] prot2_resn_resi)
            {
                var lcs = LCS.LongestCommonSubsequence(prot1_resn_resi, prot2_resn_resi, Equals);

                T  [] lcs_resn  = new T  [lcs.Length];
                int[] lcs_resi1 = new int[lcs.Length];
                int[] lcs_resi2 = new int[lcs.Length];
                int[] lcs_idx1  = new int[lcs.Length];
                int[] lcs_idx2  = new int[lcs.Length];
                for (int i = 0; i < lcs.Length; i++)
                {
                    T   resn  = lcs.lcs[i].Item1;
                    int idx1  = lcs.lcsidx1[i];
                    int idx2  = lcs.lcsidx2[i];
                    int resi1 = prot1_resn_resi[idx1].Item2;
                    int resi2 = prot2_resn_resi[idx2].Item2;
                    if (HDebug.IsDebuggerAttached)
                    {
                        bool check1 = (dynamic)resn == prot1_resn_resi[idx1].Item1;
                        bool check2 = (dynamic)resn == prot2_resn_resi[idx2].Item1;
                        HDebug.Assert(check1 && check2);
                    }

                    lcs_resn [i] = resn;
                    lcs_resi1[i] = resi1;
                    lcs_resi2[i] = resi2;
                    lcs_idx1 [i] = idx1;
                    lcs_idx2 [i] = idx2;
                }
                Tuple <LCS.Oper, T, int?>[] lcs_oper1to2 = new Tuple <LCS.Oper, T, int?> [lcs.oper1to2.Length];
                for (int i = 0; i < lcs.oper1to2.Length; i++)
                {
                    LCS.Oper oper = lcs.oper1to2[i].Item1;
                    T        resn = lcs.oper1to2[i].Item2.Item1;
                    int?     resi = lcs.oper1to2[i].Item2.Item2;
                    if (oper == LCS.Oper.Insert)
                    {
                        resi = null;
                    }
                    lcs_oper1to2[i] = new Tuple <LCS.Oper, T, int?>(oper, resn, resi);
                }
                Tuple <LCS.Oper, T, int?>[] lcs_oper2to1 = new Tuple <LCS.Oper, T, int?> [lcs.oper2to1.Length];
                for (int i = 0; i < lcs.oper2to1.Length; i++)
                {
                    LCS.Oper oper = lcs.oper2to1[i].Item1;
                    T        resn = lcs.oper2to1[i].Item2.Item1;
                    int?     resi = lcs.oper2to1[i].Item2.Item2;
                    if (oper == LCS.Oper.Insert)
                    {
                        resi = null;
                    }
                    lcs_oper2to1[i] = new Tuple <LCS.Oper, T, int?>(oper, resn, resi);
                }

                return(new OResult <T>
                {
                    prot1_resn_resi = prot1_resn_resi,
                    prot2_resn_resi = prot2_resn_resi,
                    lcs_resn = lcs_resn,
                    lcs_resi1 = lcs_resi1,
                    lcs_resi2 = lcs_resi2,
                    lcs_idx1 = lcs_idx1,
                    lcs_idx2 = lcs_idx2,
                    lcs_oper1to2 = lcs_oper1to2,
                    lcs_oper2to1 = lcs_oper2to1,
                });
            }