Esempio n. 1
0
        override public void DoIt(Greedy greedy)
        {
            string u = Unification.ToString();

            Debug.Assert(u[0] != '.' && u[u.Length - 1] != '.');           // real assert should have AASet.OptionalAny at start or end
            //Debug.Assert(Combinable is Component || greedy.UnusedPatches.Contains(Combinable)); // real assert
            Component.ReplaceWithUnification(Combinable, Unification);
            Combinable.RemoveMeFromTablesAndUpdate(greedy, Component);
        }
Esempio 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 PatchString);             //!!!raise error
     if (other.ToString().IndexOf(String) >= 0)
     {
         return(other);
     }
     else
     {
         return(null);
     }
 }
Esempio 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);
     }
 }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        override public PatchPattern UnifyOnRightOrNull(int overlap, PatchPattern other)
        {
            SpecialFunctions.CheckCondition(overlap < CoreLength && overlap < other.CoreLength); //!!!raise error
            SpecialFunctions.CheckCondition(other is PatchString);                               //!!!raise error

            string[] rgsOther = SplitRight(other.ToString(), overlap);
            string[] rgsMe    = SplitLeft(String, overlap);

            if (rgsOther[1] != rgsMe[0])
            {
                return(null);
            }

            string sUnification = rgsOther[0] + String;

            PatchPattern patchPattern = PatchStringFactory.GetInstance(sUnification);

            return(patchPattern);
        }
Esempio n. 6
0
        public MergeInPatch(Component component, Combinable combinable, PatchPattern unification)
        {
            string u = unification.ToString();

            Debug.Assert(u[0] != '.' && u[u.Length - 1] != '.');           // real assert should have AASet.OptionalAny at start or end

            Component   = component;
            Combinable  = combinable;
            Unification = unification;
            if (combinable is Patch)
            {
                _LengthIncrease = unification.FullLength - component.FullLength;
                Debug.Assert(_LengthIncrease >= 0);                 // real assert
                _ScoreImprovement = combinable.Weight;
            }
            else
            {
                //!!!we don't distinish between a merge that reduces the length more or less
                Debug.WriteLine("A merge of two components has been found");
                _LengthIncrease = Unification.FullLength - (Component.FullLength + Combinable.FullLength);
                Debug.Assert(_LengthIncrease < 0);
                _ScoreImprovement = 0;
            }
        }