Exemplo n.º 1
0
        PatchRegex ReunifyWithFlanking(PatchRegex left, PatchRegex unification, PatchRegex right)
        {
            ArrayList rgStringDisjuncts = new ArrayList();

            foreach (Disjunct disjunctUnification in unification.DisjunctCollection)
            {
                foreach (Disjunct disjunctLeft in left.DisjunctCollection)
                {
                    AASetSequence newLeftDisjunctOrNull = UnifyWithBeforeOrNull(disjunctLeft.Core.Count, disjunctLeft.FullAsAASetSequence, disjunctUnification.Before);
                    if (newLeftDisjunctOrNull != null)
                    {
                        Debug.Assert(newLeftDisjunctOrNull[0] != AASet.OptionalAny && newLeftDisjunctOrNull[newLeftDisjunctOrNull.Count - 1] != AASet.OptionalAny);                       // real assert - disjuncts never start or end with AASet.OptionalAny
                        foreach (Disjunct disjunctRight in right.DisjunctCollection)
                        {
                            AASetSequence newRightDisjunctOrNull = UnifyWithAfterOrNull(disjunctRight.Core.Count, disjunctRight.FullAsAASetSequence, disjunctUnification.After);
                            if (newRightDisjunctOrNull != null)
                            {
                                Debug.Assert(newRightDisjunctOrNull[0] != AASet.OptionalAny && newRightDisjunctOrNull[newRightDisjunctOrNull.Count - 1] != AASet.OptionalAny);                               // real assert - disjuncts never start or end with AASet.OptionalAny
                                Concatenate(newLeftDisjunctOrNull, disjunctUnification, newRightDisjunctOrNull, ref rgStringDisjuncts);
                            }
                        }
                    }
                }
            }

            if (rgStringDisjuncts.Count == 0)
            {
                return(null);
            }
            else
            {
                PatchRegex newRegex = PatchRegex.GetInstance(rgStringDisjuncts, PatchRegexFactory);
                return(newRegex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Example:  Suppose "1" is "[TNMSQC]" and the patchPattern is "11T11" and the other pattern is "T1111Z"
        ///                      then UnifyOrNull returns "T1T11Z" because that is the most general pattern
        ///                      such that "11T11".IsMatch("T1T11Z") is true and "T1111Z".IsMatch("T1T11Z") is true.
        /// Example:  Suppose "1" is "[TNMSQC]" and the patchPattern is "11T11" and the other pattern is "A1111"
        ///                      then UnifyOrNull returns null because there is no pattern X such that
        ///                      such that "11T11".IsMatch(X) is true and "A1111".IsMatch(X) is true.
        /// </summary>
        override public PatchPattern UnifyOrNull(PatchPattern other)
        {
            SpecialFunctions.CheckCondition(CoreLength <= other.CoreLength);  //!!!raise error
            SpecialFunctions.CheckCondition(other is PatchRegex);             //!!!raise error

            ArrayList newDisjuncts = new ArrayList();

            foreach (Disjunct disjunct in DisjunctCollection)
            {
                foreach (Disjunct disjunctOther in (other as PatchRegex).DisjunctCollection)
                {
                    disjunct.AppendUnifications(disjunctOther, ref newDisjuncts);
                }
            }

            if (newDisjuncts.Count == 0)
            {
                string sMiniVaccine = string.Format("{0}{1}{0}", new string('_', (int)Math.Max(MaxLength, other.MaxLength)), other.CoreRealization());
                if (IsMatch(sMiniVaccine))
                {
                    Debug.WriteLine(string.Format("Warning: two patterns would unify except for flanking regions that could be ignored by requiring that nothing be appending to the component. {0}, {1}", this, other));
                }
                return(null);
            }
            else
            {
                PatchPattern patchPatternUnified = PatchRegex.GetInstance(newDisjuncts, PatchRegexFactory);
                string       sMiniVaccine        = string.Format("{0}{1}{0}", new string('_', (int)Math.Max(MaxLength, other.MaxLength)), patchPatternUnified.CoreRealization());
                Debug.Assert(IsMatch(sMiniVaccine));                 // real assert
                Debug.Assert(other.IsMatch(sMiniVaccine));           // real assert
                return(patchPatternUnified);
            }
        }
Exemplo n.º 3
0
 public override PatchPattern GetInstance(string expression)
 {
     if (Hashtable.ContainsKey(expression))
     {
         PatchPattern patchPattern = (PatchPattern)Hashtable[expression];
         return(patchPattern);
     }
     else
     {
         PatchPattern patchPattern = PatchRegex.GetInstance(expression, this);
         SpecialFunctions.CheckCondition(patchPattern.ToString() == expression, "PatchPattern expression is not in standard form.");                 //!!!raise error
         Hashtable.Add(expression, patchPattern);
         return(patchPattern);
     }
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public override PatchPattern GetInstance(ICollection disjunctStringCollection)
        {
            PatchRegex patchRegex = PatchRegex.GetInstance(disjunctStringCollection, this);

            if (Hashtable.ContainsKey(patchRegex.ToString()))
            {
                PatchPattern patchPattern = (PatchPattern)Hashtable[patchRegex.ToString()];
                return(patchPattern);
            }
            else
            {
                PatchPattern patchPattern = patchRegex;
                Hashtable.Add(patchPattern.ToString(), patchPattern);
                return(patchPattern);
            }
        }
Exemplo n.º 6
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);
            //			}
        }
Exemplo n.º 7
0
        //Return an ArrayList of PatchRegex[] pairs
        private ArrayList SplitLeft(int overlap)
        {
            SpecialFunctions.CheckCondition(0 < overlap && overlap < CoreLength);             //!!!raise error

            ArrayList rgrg = new ArrayList();

            Disjunct[][] rgrgDisjuncts = SplitDisjuncts(overlap);
            foreach (Disjunct[] splitDisjunct in rgrgDisjuncts)
            {
                PatchRegex patchRegexLeft  = PatchRegex.GetInstance(splitDisjunct[0].FullAsAASetSequence.ToString(), PatchRegexFactory);
                PatchRegex patchRegexRight = PatchRegex.GetInstance(splitDisjunct[1].FullAsAASetSequence.ToString(), PatchRegexFactory);
                rgrg.Add(new PatchRegex[] { patchRegexLeft, patchRegexRight });
            }

            Debug.Assert(rgrg.Count == rgrgDisjuncts.Length);             // real assert

            return(rgrg);
        }