コード例 #1
0
        public PatchPattern ToPatchPattern()
        {
            SpecialFunctions.CheckCondition(DisjunctAASetSequenceCollection.Count > 0); //!!!raise error
            SpecialFunctions.CheckCondition(sbCurrentDisjunct.Count == 0);              //!!!raise error
            PatchPattern patchPattern = PatchPatternFactory.GetInstance(DisjunctAASetSequenceCollection.Keys);

            return(patchPattern);
        }
コード例 #2
0
        override public PatchPattern UnifyOnRightOrNull(int overlap, PatchPattern other)
        {
            SpecialFunctions.CheckCondition(overlap < CoreLength && overlap < other.CoreLength); //!!!raise error
            SpecialFunctions.CheckCondition(other is PatchRegex);                                //!!!raise error

            ArrayList rgrgOther = SplitRight((PatchRegex)other, overlap);
            ArrayList rgrgMe    = SplitLeft(overlap);


            ArrayList rgOuts = new ArrayList();

            foreach (PatchRegex[] rgOther in rgrgOther)
            {
                foreach (PatchRegex[] rgMe in rgrgMe)
                {
                    PatchRegex unification = (PatchRegex)rgMe[0].UnifyOrNull(rgOther[1]);


                    if (unification != null)
                    {
                        PatchPattern patchPattern;
                        if (!unification.AnyFlanking())
                        {
                            patchPattern = Concatenate(rgOther[0], unification, rgMe[1]);
                            Debug.Assert(patchPattern != null);
                        }
                        else
                        {
                            patchPattern = ReunifyWithFlanking(rgOther[0], unification, rgMe[1]);
                        }
                        if (patchPattern != null)
                        {
                            rgOuts.Add(patchPattern);
                        }
                        if (rgOuts.Count >= DisjunctLimit)
                        {
                            goto SkipOutEarly;
                        }
                    }
                }
            }
            SkipOutEarly :;
            if (rgOuts.Count == 0)
            {
                return(null);
            }
            else if (rgOuts.Count == 1)
            {
                return((PatchPattern)rgOuts[0]);
            }
            else
            {
                return(MergePatchPatterns(rgOuts, PatchRegexFactory));
            }
        }
コード例 #3
0
        private static List <PatchPattern> PatchPatternCollection(Greedy greedy)
        {
            List <PatchPattern> rg = new List <PatchPattern>();

            foreach (Component component in greedy.Components)
            {
                PatchPattern patchPattern = component.PatchPattern();
                rg.Add(patchPattern);
            }
            return(rg);
        }
コード例 #4
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);
     }
 }
コード例 #5
0
        private static List <PatchPattern> PatchPatternCollection(VaccineAsString vaccineUncompressed)
        {
            List <PatchPattern> rg = new List <PatchPattern>();

            PatchPatternFactory aPatchPatternFactory = PatchPatternFactory.GetFactory("strings");

            foreach (string componentAsString in vaccineUncompressed.NiceStringCollection())
            {
                PatchPattern patchPattern = aPatchPatternFactory.GetInstance(componentAsString);
                rg.Add(patchPattern);
            }
            return(rg);
        }
コード例 #6
0
 private Patch GetPatchFromCollection(PatchPattern patchPattern)
 {
     if (PatchPatternToPatch.ContainsKey(patchPattern))
     {
         return((Patch)PatchPatternToPatch[patchPattern]);
     }
     else
     {
         Patch aPatch = Patch.GetInstance(patchPattern, 0.0);
         PatchPatternToPatch.Add(patchPattern, aPatch);
         return(aPatch);
     }
 }
コード例 #7
0
        private void Add(Patch aPatch)
        {
            PatchPattern patchPattern = aPatch.PatchPattern();

            if (PatchPatternToPatch.ContainsKey(patchPattern))
            {
                Patch previous = (Patch)PatchPatternToPatch[patchPattern];
                previous.Weight += aPatch.Weight;
            }
            else
            {
                PatchPatternToPatch.Add(patchPattern, aPatch);
            }
        }
コード例 #8
0
        static private Move BestAbsorbedBy(Component component, Combinable combinable)
        {
            PatchPattern unification = component.PatchPattern().UnifyOrNull(combinable.PatchPattern());

            if (unification != null)
            {
                Move bestMove = new MergeInPatch(component, combinable, unification);
                return(bestMove);
            }
            else
            {
                return(null);
            }
        }
コード例 #9
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);
     }
 }
コード例 #10
0
 public override PatchPattern GetInstance(string expression)
 {
     if (ExpressionToPatchPattern.ContainsKey(expression))
     {
         PatchPattern patchPattern = (PatchPattern)ExpressionToPatchPattern[expression];
         return(patchPattern);
     }
     else
     {
         PatchPattern patchPattern = new PatchString(expression, this);
         SpecialFunctions.CheckCondition(patchPattern.ToString() == expression, "PatchPattern expression is not in standard form.");                 //!!!raise error
         ExpressionToPatchPattern.Add(expression, patchPattern);
         return(patchPattern);
     }
 }
コード例 #11
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);
            }
        }
コード例 #12
0
        static private Move BestRightLeftOrNull(Component component, Combinable combinable, PatchPattern main, PatchPattern other)
        {
            int lengthOfShorter = Math.Min(main.CoreLength, other.CoreLength);


            for (int overlap = lengthOfShorter - 1; overlap > 0; --overlap)
            {
                PatchPattern unification = other.UnifyOnRightOrNull(overlap, main);
                if (unification != null)
                {
                    Move aMove = new MergeInPatch(component, combinable, unification);
                    return(aMove);
                }
            }

            return(null);
        }
コード例 #13
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);
        }
コード例 #14
0
        static public PatchTable GetInstanceFromFile(PatchPatternFactory patchPatternFactory,
                                                     TextReader patchTableTextReader, string scorerName)
        {
            PatchTable patchTable = new PatchTable();

            patchTable.PatchTableScorer = PatchTableScorer.GetInstance(scorerName);

            foreach (Dictionary <string, string> row in SpecialFunctions.TabFileTable(patchTableTextReader, "Patch\tWeight", false))
            {
                PatchPattern patchPattern = patchPatternFactory.GetInstance(row["Patch"]);
                double       weight       = double.Parse(row["Weight"]);
                patchTable.SetMaxPatchLength(patchPattern);
                Patch patch = Patch.GetInstance(patchPattern, weight);
                patchTable.Add(patch);
            }

            patchTable.CreateSortedArrays();

            return(patchTable);
        }
コード例 #15
0
        static public PatchTable GetInstance(Dictionary <string, double> patchToWeight, string protein, string vaccineCriteriaName)
        {
            PatchTable patchTable = new PatchTable();

            patchTable.PatchTableScorer = PatchTableScorer.GetInstance("normal");

            PatchPatternFactory patchPatternFactory = PatchPatternFactory.GetFactory("strings");

            patchTable.PatchPatternToPatch = new Dictionary <PatchPattern, Patch>();
            foreach (KeyValuePair <string, double> patchAndWeight in patchToWeight)
            {
                string       patchAsString = patchAndWeight.Key;
                double       weight        = patchAndWeight.Value;
                PatchPattern patchPattern  = patchPatternFactory.GetInstance(patchAsString);
                Patch        aPatch        = Patch.GetInstance(patchPattern, weight);
                patchTable.Add(aPatch);
            }

            patchTable.CreateSortedArrays();

            return(patchTable);
        }
コード例 #16
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;
            }
        }
コード例 #17
0
 abstract public PatchPattern UnifyOnRightOrNull(int overlap, PatchPattern other);
コード例 #18
0
 abstract public PatchPattern UnifyOrNull(PatchPattern other);
コード例 #19
0
 public void ReplaceWithUnification(Combinable combinable, PatchPattern unification)
 {
     _patchPattern = unification;
     Weight       += combinable.Weight;
 }
コード例 #20
0
 private void SetMaxPatchLength(PatchPattern patchPattern)
 {
     MaxPatchLength = Math.Max(MaxPatchLength, patchPattern.MaxLength);
 }
コード例 #21
0
 public void AddComponent(PatchPattern patchPattern)
 {
     AddComponent(patchPattern.FullRealization());
 }