Exemple #1
0
        private SymPattern BuildSymSequences(string seq)
        {
            bool isEven = (seq.Length % 2 == 0);
            int  mid    = seq.Length / 2;
            int  index  = 0;
            bool go     = true;

            while (go)
            {
                string lhs    = seq.Substring(0, mid - index);
                string rhs    = isEven ? seq.Substring(mid + index) : seq.Substring(mid + index + 1);
                string middle = isEven ? seq.Substring(mid - index, 2 * index) : seq.Substring(mid - index, (2 * index) + 1);


                //Debug.WriteLine(lhs.Length + " " + middle.Length + " " + rhs.Length);
                //Debug.WriteLine(lhs + "-" + middle + "-" + rhs);



                if (lhs.Length == 0 || rhs.Length == 0)
                {
                    return(null);
                }

                bool SymMatch       = (lhs == rhs);
                bool MirrorSymMatch = (lhs == ReverseString(rhs));

                if (SymMatch || MirrorSymMatch)
                {
                    SymPattern SP = new SymPattern {
                        SymMatch = SymMatch, MirrorSymMatch = MirrorSymMatch, Length = middle.Length, LHS = lhs, RHS = rhs, Middle = middle
                    };
                    return(SP);
                }

                if (index >= mid)
                {
                    go = false;
                }

                if (index > 3)
                {
                    go = false;
                }
                index++;
            }

            return(null);
        }
Exemple #2
0
        public void Go3()
        {
            List <Rule> Rules = FindCandidates3();
            //List<Rule> Rules = new List<Rule>() {};


            StreamWriter sw = new StreamWriter("SymPatterns.txt", false, Encoding.UTF8);

            sw.WriteLine("Sym,Mirror Sym,Identifier,Name,Chandam Length,Chandam Name,Raw Pattern,Bridge Length,Symmetric Pattern,Symmetric Pattern2");

            foreach (Rule R in Rules)
            {
                if (R.Sequence == "")
                {
                    Console.WriteLine(R.Identifier + " - Skipping");
                    continue;
                }
                //if (R.CharLength < 7)
                //{
                //    continue;
                //}

                SymPattern SP = BuildSymSequences(R.Sequence.Replace("-", "").Replace("|", "I"));
                if (SP != null)
                {
                    Console.WriteLine(R.Identifier + " - Symmetric Pattern Found.");

                    string l = Mark(SP.LHS, 3);
                    string m = SP.Middle;
                    string r = Mark(SP.RHS, 3);

                    string seq = l + (m == "" ? "-" : "-(" + m + ")-") + r;

                    string seq2 = SP.LHS + (m == "" ? "-" : "-(" + m + ")-") + SP.RHS;

                    sw.WriteLine(SP.SymMatch + "," + SP.MirrorSymMatch + "," + R.Identifier + "," + R.ShortName + "," + R.CharLength + "," + R.ChandamName + "," + R.Sequence.Replace("|", "I") + "," + SP.Length + "," + seq + "," + seq2);
                }
                else
                {
                    Console.WriteLine(R.Identifier + " -No Symmetric Pattern Found.");
                }
            }
            sw.Close();
        }