예제 #1
0
//		private void SetToStringFromSegmentCollection()
//		{
//			StringBuilder toStringStringBuilder = new StringBuilder();
//			foreach(Segment segment in SegmentCollection)
//			{
//				if (toStringStringBuilder.Length != 0)
//				{
//					toStringStringBuilder.Append(SegmentJoiner);
//				}
//				toStringStringBuilder.Append(segment.ToString());
//			}
//
//			String = toStringStringBuilder.ToString();
//		}


        private void SetEverythingElse(PatchRegexFactory patchRegexFactory)
        {
            PatchRegexFactory = patchRegexFactory;
            _MaxLength        = int.MinValue;
            _coreRealization  = null;
            StringBuilder regexStringBuilder = new StringBuilder();

            foreach (Disjunct Disjunct in DisjunctCollection)
            {
                _MaxLength = Math.Max(Disjunct.FullAsAASetSequence.Count, MaxLength);
                if (_coreRealization == null)
                {
                    _coreRealization = Disjunct.CoreRealization;
                    _fullRealization = Disjunct.FullRealization;
                }
                else
                {
                    SpecialFunctions.CheckCondition(CoreLength == Disjunct.Core.Count);                     //!!!raise error - disjuncts lengths vary
                    if (_fullRealization.Length > Disjunct.FullRealization.Length)
                    {
                        _fullRealization = Disjunct.FullRealization;
                    }
                }
                if (regexStringBuilder.Length != 0)
                {
                    regexStringBuilder.Append('|');
                }
                regexStringBuilder.Append(Disjunct.RegexString);
            }

            RegexString = regexStringBuilder.ToString();
            Regex       = new Regex(regexStringBuilder.ToString() /*, RegexOptions.Compiled*/);
            Debug.Assert(CoreLength <= MaxLength);
        }
예제 #2
0
        static public Disjunct GetInstance(string expression, PatchRegexFactory patchRegexFactory)
        {
            Disjunct disjunct = new Disjunct();

            disjunct.FullAsString      = expression;
            disjunct.PatchRegexFactory = patchRegexFactory;
            disjunct.SetLeftCoreRightRealizationAbstractionAndRegex();
            return(disjunct);
        }
예제 #3
0
        static private PatchPattern MergePatchPatterns(ArrayList rgOut, PatchRegexFactory patchRegexFactory)
        {
            ArrayList rgStringDisjuncts = new ArrayList();

            foreach (PatchRegex aPatchRegex in rgOut)
            {
                Debug.Assert(aPatchRegex != null);                 // real assert
                foreach (Disjunct aDisjunct in aPatchRegex.DisjunctCollection)
                {
                    rgStringDisjuncts.Add(aDisjunct.FullAsAASetSequence.ToString());
                }
            }
            PatchRegex newRegex = PatchRegex.GetInstance(rgStringDisjuncts, patchRegexFactory);

            return(newRegex);
        }
예제 #4
0
        static private PatchRegex Concatenate(params PatchRegex[] patchRegexParams)
        {
            SpecialFunctions.CheckCondition(patchRegexParams.Length > 0);             //!!!raise error
            PatchRegexFactory patchRegexFactory = null;
            //ArrayList rgSegment = new ArrayList();
            double        combinations = 1;
            AASetSequence sbLuckyOne   = AASetSequence.GetInstance();

            foreach (PatchRegex patchRegex in patchRegexParams)
            {
                //rgSegment.AddRange(patchRegex.SegmentCollection);
                combinations *= patchRegex.DisjunctCollection.Length;
                if (combinations == 1)
                {
                    sbLuckyOne.Append(patchRegex.DisjunctCollection[0].FullAsAASetSequence);
                }
                if (patchRegexFactory == null)
                {
                    patchRegexFactory = patchRegex.PatchRegexFactory;
                }
                else
                {
                    Debug.Assert(patchRegexFactory == patchRegex.PatchRegexFactory);                    //this says that all PatchRegex's must come from the same Hashtable
                }
            }

            if (combinations == 1)
            {
                Debug.Assert(sbLuckyOne[0] != AASet.OptionalAny && sbLuckyOne[sbLuckyOne.Count - 1] != AASet.OptionalAny);               // real assert - disjuncts can't start or end with AASet.OptionalAny
                string[]   rgDisjuncts = new string[] { sbLuckyOne.ToString() };
                PatchRegex patchRegex  = PatchRegex.GetInstance(rgDisjuncts, patchRegexFactory);
                return(patchRegex);
            }
            else
            {
                Debug.Fail("how may combinations?");
                Debug.WriteLine("place of interest");
                return(null);
            }
            //			else if (rgSegment.Count > 1 && combinations == 2)
            //			{
            //				Segment segment = TurnToOneSegment(rgSegment, patchRegexFactory);
            //				rgSegment.Clear();
            //				rgSegment.Add(segment);
            //			}
        }
예제 #5
0
        static public PatchRegex GetInstance(ICollection disjunctStringCollection, PatchRegexFactory patchRegexFactory)
        {
            Debug.Assert(!(disjunctStringCollection is AASetSequence));             // real assert

            // e.g. "ABC123", "ABC123|1BCD23"
            SortedList rgDisjunct = new SortedList();

            foreach (string disjunctAsString in disjunctStringCollection)
            {
                Disjunct disjunct = Disjunct.GetInstance(disjunctAsString, patchRegexFactory);
                rgDisjunct[disjunct.FullAsString] = disjunct;                 //Remove idenitical disjuncts
            }

            PatchRegex patchRegex = FinishUp(rgDisjunct, patchRegexFactory);

            return(patchRegex);
        }
예제 #6
0
        private static PatchRegex FinishUp(SortedList rgDisjunct1, PatchRegexFactory patchRegexFactory)
        {
            SortedList rgDisjunct2 = RemoveSubsumedDisjuncts(rgDisjunct1);
            PatchRegex patchRegex  = new PatchRegex();

            patchRegex.DisjunctCollection = new Disjunct[rgDisjunct2.Count];
            rgDisjunct2.Values.CopyTo(patchRegex.DisjunctCollection, 0);

            SpecialFunctions.CheckCondition(rgDisjunct2.Count > 0);             //!!!raise error - just have at least one disjunct
            patchRegex.SetStringFromDisjunctCollection();
            patchRegex.SetEverythingElse(patchRegexFactory);

            if (patchRegexFactory.Hashtable.ContainsKey(patchRegex.ToString()))
            {
                return((PatchRegex)patchRegexFactory.Hashtable[patchRegex.ToString()]);
            }
            else
            {
                return(patchRegex);
            }
        }
예제 #7
0
 static public PatchPatternFactory GetFactory(string language /*AASimilarity aAASimilarity*/)
 {
     //!!!switch to switch
     if (language == "strings")
     {
         Debug.WriteLine("Using the strings language");
         PatchPatternFactory patchPatternFactory = new PatchStringFactory();
         return(patchPatternFactory);
     }
     else if (language == "regexs")
     {
         Debug.WriteLine("Using the regexs language");
         PatchRegexFactory patchRegexFactory = new PatchRegexFactory();
         return(patchRegexFactory);
     }
     else
     {
         Debug.Fail("Don't know how to create a PatchPatternFactory for language " + language);
         return(null);
     }
 }
예제 #8
0
 static public PatchRegex GetInstance(string expression, PatchRegexFactory patchRegexFactory)
 {
     return(GetInstance(expression.Split(DisjunctJoiner), patchRegexFactory));
 }