Exemplo n.º 1
0
 public void EndDisjunct()
 {
     SetAndCheckCoreLength();
     DisjunctAASetSequenceCollection[sbCurrentDisjunct.ToString()] = null;
     sbCurrentDisjunct = AASetSequence.GetInstance();
     CoreLengthSoFar   = 0;
 }
        public AASetSequence ReverseClone()
        {
            AASetSequence rc = AASetSequence.GetInstance();

            for (int i = this.Count - 1; i >= 0; --i)
            {
                rc.Add(this[i]);
            }
            return(rc);
        }
        public AASetSequence Subsequence(int start)
        {
            AASetSequence aAASetSequence = AASetSequence.GetInstance();

            for (int i = start; i < Count; ++i)
            {
                aAASetSequence.Append(this[i]);
            }
            return(aAASetSequence);
        }
        public AASetSequence Subsequence(int start, int length)
        {
            AASetSequence aAASetSequence = AASetSequence.GetInstance();

            for (int i = start; i < start + length; ++i)
            {
                aAASetSequence.Append(this[i]);
            }
            return(aAASetSequence);
        }
//		private AASetSequence(int size) : base(size)
//		{
//			for(int i = 0; i < size; ++i)
//			{
//				Add(null);
//			}
//		}
        public static AASetSequence Concatenate(params AASetSequence[] aaSetSequenceParams)
        {
            AASetSequence result = AASetSequence.GetInstance();

            foreach (AASetSequence aAASetSequence in aaSetSequenceParams)
            {
                result.Append(aAASetSequence);
            }
            return(result);
        }
        static public AASetSequence GetInstance(AASetSequence aAASetSequence)
        {
            AASetSequence r = AASetSequence.GetInstance();

            foreach (AASet aaSet in aAASetSequence)
            {
                r.Add(aaSet);
            }
            return(r);
        }
Exemplo n.º 7
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.º 8
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);
        }
Exemplo n.º 9
0
        private AASetSequence UnifyWithAfterOrNullLongerShorter(AASetSequence longer, AASetSequence shorter)
        {
            Debug.Assert(longer.Count >= shorter.Count);             // real assert
            AASetSequence sb = AASetSequence.GetInstance(longer);

            for (int i = 0; i < shorter.Count; ++i)
            {
                AASet chShorter      = shorter[i];
                AASet chLonger       = longer[i];
                AASet chUnifyOrEmpty = UnifyOrBoundWithFlanking(chShorter, chLonger);
                if (chUnifyOrEmpty == AASet.Empty)
                {
                    return(null);
                }
                sb[i] = chUnifyOrEmpty;
            }
            return(sb);
        }
Exemplo n.º 10
0
        private void SetLeftCoreRightRealizationAbstractionAndRegex()
        {
            Before = AASetSequence.GetInstance();
            Core   = AASetSequence.GetInstance();
            After  = AASetSequence.GetInstance();


            StringBuilder sbCoreRealization = new StringBuilder();
            StringBuilder sbFullRealization = new StringBuilder();
            StringBuilder sbRegex           = new StringBuilder();

            CharEnumerator charEnumerator = FullAsString.GetEnumerator();

            // Read 1st char
            bool bOK = charEnumerator.MoveNext();
            char ch  = char.MinValue;

            if (bOK)
            {
                ch = charEnumerator.Current;
            }

            // Read before part
            while (bOK)
            {
                if (!(ch == '.' || (char.IsLetter(ch) && !char.IsUpper(ch))))
                {
                    break;
                }
                AASet aaSet = Before.AppendGroundOrEdge(ch);
                sbRegex.Append(AASetSequence.ToRegexString(aaSet));

                char fullRealizationChar = AASetSequence.ToFlankingRealizationChar(aaSet);
                sbFullRealization.Append(fullRealizationChar);

                bOK = charEnumerator.MoveNext();
                if (bOK)
                {
                    ch = charEnumerator.Current;
                }
            }

            // Read main part
            while (bOK)
            {
                if (ch == '.' || (char.IsLetter(ch) && !char.IsUpper(ch)))
                {
                    break;
                }

                if (char.IsLetter(ch) && char.IsUpper(ch))
                {
                    AASet aaSet = Core.AppendGround(ch);
                    char  coreRealizationChar = AASetSequence.ToCoreRealizationChar(aaSet);
                    Debug.Assert(ch == coreRealizationChar);                     //!!!real assert
                    sbCoreRealization.Append(coreRealizationChar);
                    sbFullRealization.Append(coreRealizationChar);
                    sbRegex.Append(AASetSequence.ToRegexString(aaSet));
                }
                else
                {
                    SpecialFunctions.CheckCondition(ch == '[');                     //!!!raise error
                    // Read [xyz]
                    StringBuilder sbCharSet = new StringBuilder();
                    bOK = charEnumerator.MoveNext();
                    SpecialFunctions.CheckCondition(bOK);                     //!!!raise error
                    ch = charEnumerator.Current;
                    while (ch != ']')
                    {
                        sbCharSet.Append(ch);
                        bOK = charEnumerator.MoveNext();
                        SpecialFunctions.CheckCondition(bOK);                         //!!!raise error
                        ch = charEnumerator.Current;
                    }
                    SpecialFunctions.CheckCondition(sbCharSet.Length > 0);                     //!!!raies error
                    AASet aaSet = Core.AppendGroundSet(sbCharSet.ToString());
                    char  coreRealizationChar = AASetSequence.ToCoreRealizationChar(aaSet);
                    sbCoreRealization.Append(coreRealizationChar);
                    sbFullRealization.Append(coreRealizationChar);
                    sbRegex.Append(AASetSequence.ToRegexString(aaSet));
                }


                bOK = charEnumerator.MoveNext();
                if (bOK)
                {
                    ch = charEnumerator.Current;
                }
            }

            // Read after part
            while (bOK)
            {
                if (!(ch == '.' || (char.IsLetter(ch) && !char.IsUpper(ch))))
                {
                    break;
                }
                AASet aaSet = After.AppendGroundOrEdge(ch);
                sbRegex.Append(AASetSequence.ToRegexString(aaSet));

                char fullRealizationChar = AASetSequence.ToFlankingRealizationChar(aaSet);
                sbFullRealization.Append(fullRealizationChar);

                bOK = charEnumerator.MoveNext();
                if (bOK)
                {
                    ch = charEnumerator.Current;
                }
            }

            FullAsAASetSequence = AASetSequence.Concatenate(Before, Core, After);
            CoreRealization     = sbCoreRealization.ToString();
            FullRealization     = sbFullRealization.ToString();
            RegexString         = sbRegex.ToString();
        }