Ejemplo n.º 1
0
        private string SolveExpressionPrevValues()
        {
            string exp = _expression;

            foreach (Function func in _functions)
            {
                switch (func.Type)
                {
                case Function.FunctionType.SequentialIntFunction:
                    SequentialIntFunction sif = (SequentialIntFunction)func;
                    exp = exp.Replace(sif.Name, sif.PrevVal().ToString().PadLeft(sif.Padding, '0'));
                    break;

                case Function.FunctionType.SequentialCharFunction:
                    SequentialCharFunction scf = (SequentialCharFunction)func;
                    exp = exp.Replace(scf.Name, scf.PrevVal().ToString());
                    break;

                case Function.FunctionType.ConstantTextFunction:
                    ConstantTextFunction ctf = (ConstantTextFunction)func;
                    exp = exp.Replace(ctf.Name, ctf.Constant);
                    break;
                }
            }
            return(exp);
        }
Ejemplo n.º 2
0
        public string SolveExpressionFromBeginning(int iteration)
        {
            string exp = _expression;

            foreach (Function func in _functions)
            {
                switch (func.Type)
                {
                case Function.FunctionType.SequentialIntFunction:
                    SequentialIntFunction sif = (SequentialIntFunction)func;
                    exp = exp.Replace(sif.Name, sif.AllVals(iteration).Last <int>().ToString().PadLeft(sif.Padding, '0'));
                    break;

                case Function.FunctionType.SequentialCharFunction:
                    SequentialCharFunction scf = (SequentialCharFunction)func;
                    exp = exp.Replace(scf.Name, scf.AllVals(iteration).Last <char>().ToString());
                    break;

                case Function.FunctionType.ConstantTextFunction:
                    ConstantTextFunction ctf = (ConstantTextFunction)func;
                    exp = exp.Replace(ctf.Name, ctf.Constant);
                    break;
                }
            }
            return(exp);
        }
Ejemplo n.º 3
0
        public static Generalization[] Generate(string str1, string str2, TimeSpan time)
        {
            List <Generalization>         gens = new List <Generalization>();
            List <SequentialIntFunction>  sifs = new List <SequentialIntFunction>();
            List <SequentialCharFunction> scfs = new List <SequentialCharFunction>();
            List <ConstantTextFunction>   ctfs = new List <ConstantTextFunction>();
            string expression = string.Empty;

            // SequentialIntFunction
            if (SequentialIntFunction.Generate(str1, str2, out expression, out sifs))
            {
                //foreach (SequentialIntFunction func in sifs)
                //    gens.Add(new TextGeneralization(expression, func, str2));
                gens.Add(new TextGeneralization(expression, sifs.ToArray(), str2, time, 2));
            }
            // SequentialCharFunction
            if (SequentialCharFunction.Generate(str1, str2, out expression, out scfs))
            {
                //foreach (SequentialCharFunction func in scfs)
                //    gens.Add(new TextGeneralization(expression, func, str2));
                gens.Add(new TextGeneralization(expression, scfs.ToArray(), str2, time, 2));
            }
            // ConstantTextFunction
            if (ConstantTextFunction.Generate(str1, str2, out expression, out ctfs))
            {
                //foreach (ConstantTextFunction func in ctfs)
                //    gens.Add(new TextGeneralization(expression, func, str2));
                gens.Add(new TextGeneralization(expression, ctfs.ToArray(), str2, time, 2));
            }
            return(gens.ToArray());
        }
Ejemplo n.º 4
0
        public static Generalization[] Generate(string str1, string str2, TimeSpan time)
        {
            List <Generalization> gens = new List <Generalization>();

            bool   is_file;
            string folder1, folder2;

            if (Directory.Exists(str2))
            {
                is_file = false;
                folder1 = Directory.GetParent(str1).FullName;
                folder2 = Directory.GetParent(str2).FullName;
            }
            else
            {
                is_file = true;
                folder1 = Path.GetDirectoryName(str1);
                folder2 = Path.GetDirectoryName(str2);
            }

            // if both files have the same directory, then there might be a generalization
            if (folder1 == folder2)
            {
                List <SequentialIntFunction>  sifs = new List <SequentialIntFunction>();
                List <SequentialCharFunction> scfs = new List <SequentialCharFunction>();
                List <ConstantTextFunction>   ctfs = new List <ConstantTextFunction>();
                string expression = string.Empty;

                string file1 = Path.GetFileName(str1);
                string file2 = Path.GetFileName(str2);

                // SequentialIntFunction
                if (SequentialIntFunction.Generate(file1, file2, out expression, out sifs))
                {
                    //foreach (SequentialIntFunction func in sifs)
                    //    gens.Add(new FileCreateGeneralization(expression, func, str2));
                    gens.Add(new FileCreateGeneralization(expression, sifs.ToArray(), file2, time, 2));
                }
                // SequentialCharFunction
                if (SequentialCharFunction.Generate(file1, file2, out expression, out scfs))
                {
                    //foreach (SequentialCharFunction func in scfs)
                    //    gens.Add(new FileCreateGeneralization(expression, func, str2));
                    gens.Add(new FileCreateGeneralization(expression, scfs.ToArray(), file2, time, 2));
                }
                // ConstantTextFunction
                if (ConstantTextFunction.Generate(file1, file2, out expression, out ctfs))
                {
                    //foreach (ConstantTextFunction func in ctfs)
                    //    gens.Add(new FileCreateGeneralization(expression, func, str2));
                    gens.Add(new FileCreateGeneralization(expression, ctfs.ToArray(), file2, time, 2));
                }
            }
            return(gens.ToArray());
        }
Ejemplo n.º 5
0
        public static bool Generate(string str1, string str2, out string expression, out List <SequentialCharFunction> functions)
        {
            expression = string.Empty;
            functions  = new List <SequentialCharFunction>();
            List <Pair <Pair <int, string>, Pair <int, string> > > diffs = Diff.DiffString(str1, str2);

            if (diffs.Count > 0 && Diff.IsDiffChar(diffs))
            {
                expression = str2;
                int    val1, val2, pos1, pos2;
                string f_name = string.Empty;

                List <int>               positions_to_replace         = new List <int>();
                Dictionary <int, int>    fpositions_to_replace        = new Dictionary <int, int>();
                Dictionary <int, string> tokens_to_replace            = new Dictionary <int, string>();
                Dictionary <int, SequentialCharFunction> funcs_to_add = new Dictionary <int, SequentialCharFunction>();

                for (int i = 1; i <= diffs.Count; i++)
                {
                    Pair <Pair <int, string>, Pair <int, string> > diff = diffs[i - 1];
                    f_name = diff.Second.Second.Substring(0, diff.Second.Second.Length - 1) + "§" + i.ToString();
                    val1   = (int)diff.First.Second[diff.First.Second.Length - 1];
                    pos1   = diff.First.First;
                    val2   = (int)diff.Second.Second[diff.Second.Second.Length - 1];
                    pos2   = diff.Second.First;
                    if (pos1 == pos2)
                    {
                        //expression = expression.Replace(diff.Second.Second, f_name);
                        SequentialCharFunction func = new SequentialCharFunction(f_name, (char)val2, val2 - val1, 0, 2);
                        //functions.Add(new SequentialCharFunction(f_name, (char)val2, val2 - val1, 0, 2));
                        if (!positions_to_replace.Contains(pos2))
                        {
                            positions_to_replace.Add(pos2);
                            fpositions_to_replace.Add(pos2, pos2);
                            tokens_to_replace.Add(pos2, f_name);
                            funcs_to_add.Add(pos2, func);
                        }
                    }
                }

                // add functions by its correct order
                positions_to_replace.Sort();
                foreach (int pos in positions_to_replace)
                {
                    functions.Add(funcs_to_add[pos]);
                }
                // replace text beginning from the end of the string
                positions_to_replace.Reverse();
                foreach (int pos in positions_to_replace)
                {
                    expression = SystemCore.SystemAbstraction.StringUtilities.StringUtility.ReplaceBetweenPositions(expression, pos, fpositions_to_replace[pos], tokens_to_replace[pos]);
                }
            }
            if (functions.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static Generalization[] Generate(string str1, string str2, TimeSpan time)
        {
            List <Generalization> gens = new List <Generalization>();

            bool   is_file;
            string folder1, folder2;

            if (Directory.Exists(str2))
            {
                is_file = false;
                folder1 = Directory.GetParent(str1).FullName;
                folder2 = Directory.GetParent(str2).FullName;
            }
            else
            {
                is_file = true;
                folder1 = Path.GetDirectoryName(str1);
                folder2 = Path.GetDirectoryName(str2);
            }

            // if both files have the same directory, then there might be a generalization
            if (folder1 == folder2)
            {
                List <ConstantFileFunction>    cff  = new List <ConstantFileFunction>();
                List <ConstantFileFunctionEx>  cffe = new List <ConstantFileFunctionEx>();
                List <SequentialIntFunction>   sifs = new List <SequentialIntFunction>();
                List <SequentialCharFunction>  scfs = new List <SequentialCharFunction>();
                List <ConstantFileExtFunction> cfef = new List <ConstantFileExtFunction>();
                List <ConstantTextFunction>    ctfs = new List <ConstantTextFunction>();
                string expression = string.Empty;

                string file1 = Path.GetFileNameWithoutExtension(str1);
                string file2 = Path.GetFileNameWithoutExtension(str2);

                List <string> extensions = new List <string>();

                // detect which file extensions show the operations be applied to
                if (is_file)
                {
                    if (Path.GetExtension(str1) == Path.GetExtension(str2) && Path.GetExtension(str1) != string.Empty)
                    {
                        extensions.Add(Path.GetExtension(str2));
                    }
                    extensions.Add(".*");
                }

                // SequentialIntFunction
                if (SequentialIntFunction.Generate(file1, file2, out expression, out sifs))
                {
                    gens.Add(new FileDeleteGeneralization(expression, sifs.ToArray(), str2, time, 2));
                }
                // SequentialCharFunction
                if (SequentialCharFunction.Generate(file1, file2, out expression, out scfs))
                {
                    gens.Add(new FileDeleteGeneralization(expression, scfs.ToArray(), str2, time, 2));
                }
                // ConstantFileFunction
                if (ConstantFileFunction.Generate(file1, file2, folder2, extensions.ToArray(), out expression, out cff))
                {
                    gens.Add(new FileDeleteGeneralization(expression, cff.ToArray(), str2, time, 2));
                }
                // ConstantFileFunctionEx
                if (ConstantFileFunctionEx.Generate(file1, file2, folder2, extensions.ToArray(), out expression, out cffe))
                {
                    gens.Add(new FileDeleteGeneralization(expression, cffe.ToArray(), str2, time, 2));
                }
                // ConstantFileExtFunction
                if (ConstantFileExtFunction.Generate(folder2, extensions.ToArray(), out expression, out cfef))
                {
                    gens.Add(new FileDeleteGeneralization(expression, cfef.ToArray(), str2, time, 2));
                }
                // ConstantTextFunction
                if (ConstantTextFunction.Generate(file1, file2, out expression, out ctfs))
                {
                    gens.Add(new FileDeleteGeneralization(expression, ctfs.ToArray(), str2, time, 2));
                }
            }
            return(gens.ToArray());
        }