Exemple #1
0
        private bool AfterAndCoreUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence)
        {
            int iHowMuchDoesThisStickIn = Math.Max(other.Core.Count - (possiblePos + Core.Count), 0);

            for (int iCommon = 0; iCommon < iHowMuchDoesThisStickIn; ++iCommon)
            {
                AASet chOther = other.Core[other.Core.Count - iHowMuchDoesThisStickIn + iCommon];
                if (iCommon < After.Count)
                {
                    AASet chThis = After[(int)iCommon];

                    AASet chUnifyOrEmpty = FlankingAndCoreUnifyOrEmpty(chThis, chOther);
                    if (chUnifyOrEmpty == AASet.Empty)                     //!!!const
                    {
                        return(false);
                    }
                    aAASetSequence.Append(chUnifyOrEmpty);
                }
                else
                {
                    aAASetSequence.Append(chOther);
                }
            }
            return(true);
        }
Exemple #2
0
        private bool AfterUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence)
        {
            //This creates the new after string. It will be the unification of other's after string
            //and any of This's after that sticks out beyond the core of other
            int iHowMuchDoesThisStickOut = Math.Max(0, possiblePos + Core.Count + After.Count - other.Core.Count);

            int iHowMuchInCommon = Math.Min(iHowMuchDoesThisStickOut, other.After.Count);

            for (int iCommon = 0; iCommon < iHowMuchInCommon; ++iCommon)
            {
                AASet chThis  = After[After.Count - iHowMuchDoesThisStickOut + iCommon];
                AASet chOther = other.After[iCommon];

                AASet chUnifyOrOptionalEmpty = FlankingUnifyOrOptionalEmpty(chThis, chOther);
                if (chUnifyOrOptionalEmpty == AASet.OptionalEmpty)                 //!!!const
                {
                    return(false);
                }
                aAASetSequence.Append(chUnifyOrOptionalEmpty);
            }

            int iHowMuchLongerDoesOtherStickOutComparedToThis = Math.Max(0, other.After.Count - iHowMuchDoesThisStickOut);

            aAASetSequence.AppendSubsequence(other.After, iHowMuchInCommon, iHowMuchLongerDoesOtherStickOutComparedToThis);
            int iHowMuchLongerDoesThisStickOutComparedToOther = Math.Max(0, iHowMuchDoesThisStickOut - other.After.Count);

            aAASetSequence.AppendSubsequence(After, After.Count - iHowMuchLongerDoesThisStickOutComparedToOther, iHowMuchLongerDoesThisStickOutComparedToOther);
            return(true);
        }
Exemple #3
0
        public bool IsLessGeneralThan(Disjunct other)
        {
            SpecialFunctions.CheckCondition(this != other);                      //!!! raise error
            SpecialFunctions.CheckCondition(FullAsString != other.FullAsString); //!!! raise error

            bool falseForSure;
            bool bAtLeastOneCharOfOtherIsMoreGeneral = false;

            CoreIsLessGeneralThan(other, out falseForSure, ref bAtLeastOneCharOfOtherIsMoreGeneral);
            if (falseForSure)
            {
                return(false);
            }

            BeforeOrAfterIsLessGeneralThan(Before, other.Before, out falseForSure, ref bAtLeastOneCharOfOtherIsMoreGeneral);
            if (falseForSure)
            {
                return(false);
            }

            BeforeOrAfterIsLessGeneralThan(After, other.After, out falseForSure, ref bAtLeastOneCharOfOtherIsMoreGeneral);
            if (falseForSure)
            {
                return(false);
            }
            ;

            return(bAtLeastOneCharOfOtherIsMoreGeneral);
        }
Exemple #4
0
        public Disjunct Right(int length)
        {
            SpecialFunctions.CheckCondition(length > 0);             //!!!raise error
            AASetSequence expression = FullAsAASetSequence.Subsequence(Before.Count + Core.Count - (int)length);
            Disjunct      disjunct   = Disjunct.GetInstance(expression.ToString(), PatchRegexFactory);

            return(disjunct);
        }
Exemple #5
0
        static public Disjunct GetInstance(string expression, PatchRegexFactory patchRegexFactory)
        {
            Disjunct disjunct = new Disjunct();

            disjunct.FullAsString      = expression;
            disjunct.PatchRegexFactory = patchRegexFactory;
            disjunct.SetLeftCoreRightRealizationAbstractionAndRegex();
            return(disjunct);
        }
Exemple #6
0
        /// 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>
        public void AppendUnifications(Disjunct other, ref ArrayList unifiedDisjunctStringList)
        {
            SpecialFunctions.CheckCondition(Core.Count <= other.Core.Count);             //!!!raise error

            for (int iPossiblePos = 0; iPossiblePos <= other.Core.Count - Core.Count; ++iPossiblePos)
            {
                AASetSequence unifiedDisjunctOrNull = UnificationAtPositionOrNull(other, iPossiblePos);
                if (unifiedDisjunctOrNull != null)
                {
                    unifiedDisjunctStringList.Add(unifiedDisjunctOrNull.ToString());
                }
            }
        }
Exemple #7
0
 private bool CoreUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence)
 {
     for (int iThisPos = 0; iThisPos < Core.Count; ++iThisPos)
     {
         AASet chThis         = Core[iThisPos];
         int   iOtherPos      = possiblePos + iThisPos;
         AASet chOther        = other.Core[iOtherPos];
         AASet chUnifyOrEmpty = AASetSequence.UnifyOrEmpty(chThis, chOther);
         if (chUnifyOrEmpty == AASet.Empty)                 //!!!const
         {
             return(false);
         }
         aAASetSequence.Append(chUnifyOrEmpty);
     }
     return(true);
 }
Exemple #8
0
        public Disjunct[][] SplitDisjuncts(int leftLength)
        {
            Debug.Assert(0 < leftLength && leftLength < CoreLength);

            Disjunct[][] rgrg = new Disjunct[DisjunctCollection.Length][];
            for (int iDisjunct = 0; iDisjunct < DisjunctCollection.Length; ++iDisjunct)
            {
                Disjunct disjunct = DisjunctCollection[iDisjunct];

                rgrg[iDisjunct] =
                    new Disjunct[] {
                    disjunct.Left(leftLength),
                    disjunct.Right(CoreLength - leftLength)
                };
            }
            return(rgrg);
        }
Exemple #9
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);
        }
Exemple #10
0
        private AASetSequence UnificationAtPositionOrNull(Disjunct other, int possiblePos)
        {
            AASetSequence aAASetSequence = AASetSequence.GetInstance();

            bool b =
                BeforeUnificationAtPosition(other, possiblePos, ref aAASetSequence) &&
                BeforeAndCoreUnificationAtPosition(other, possiblePos, ref aAASetSequence) &&
                CoreUnificationAtPosition(other, possiblePos, ref aAASetSequence) &&
                AfterAndCoreUnificationAtPosition(other, possiblePos, ref aAASetSequence) &&
                AfterUnificationAtPosition(other, possiblePos, ref aAASetSequence);

            if (b)
            {
                Debug.Assert(aAASetSequence[0] != AASet.OptionalAny && aAASetSequence[aAASetSequence.Count - 1] != AASet.OptionalAny);               // real assert - can't start or end with AASet.OptionalAny
            }

            return(b ? aAASetSequence : null);
        }
Exemple #11
0
        private void CoreIsLessGeneralThan(Disjunct other, out bool falseForSure, ref bool bAtLeastOneCharOfOtherIsMoreGeneral)
        {
            SpecialFunctions.CheckCondition(Core.Count == other.Core.Count);             //!!! raise error
            for (int i = 0; i < Core.Count; ++i)
            {
                AASet cMe    = Core[i];
                AASet cOther = other.Core[i];
                if (CoreIsMoreGeneralThan(cMe, cOther))
                {
                    falseForSure = true;

                    return;
                }
                else if (CoreIsMoreGeneralThan(cOther, cMe))
                {
                    bAtLeastOneCharOfOtherIsMoreGeneral = true;
                }
            }

            falseForSure = false;
            return;
        }
Exemple #12
0
 private bool BeforeAndCoreUnificationAtPosition(Disjunct other, int possiblePos, ref AASetSequence aAASetSequence)
 {
     for (int iCommon = 0; iCommon < possiblePos; ++iCommon)
     {
         AASet chOther   = other.Core[iCommon];
         int   iInBefore = Before.Count - possiblePos + iCommon;
         if (iInBefore >= 0)
         {
             AASet chThis         = Before[iInBefore];
             AASet chUnifyOrEmpty = FlankingAndCoreUnifyOrEmpty(chThis, chOther);
             if (chUnifyOrEmpty == AASet.Empty)                     //!!!const
             {
                 return(false);
             }
             aAASetSequence.Append(chUnifyOrEmpty);
         }
         else
         {
             aAASetSequence.Append(chOther);
         }
     }
     return(true);
 }
Exemple #13
0
        private void Concatenate(AASetSequence disjunctLeftString, Disjunct disjunctMiddle, AASetSequence disjunctRightString, ref ArrayList rgStringDisjuncts)
        {
            string newDisjunctString = string.Format("{0}{1}{2}", disjunctLeftString, disjunctMiddle.Core, disjunctRightString);

            rgStringDisjuncts.Add(newDisjunctString);
        }