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); }
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); }
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()); }
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()); }
public static bool Generate(string str1, string str2, out string expression, out List <SequentialIntFunction> functions) { expression = string.Empty; functions = new List <SequentialIntFunction>(); List <Pair <Pair <int, string>, Pair <int, string> > > diffs = Diff.DiffString(str1, str2); if (diffs.Count > 0 /*&& Diff.IsDiffNumerical(diffs)*/) { //if (diffs[0].Second.Second == "2") // System.Windows.Forms.MessageBox.Show("woot"); Regex regex = new Regex(@"[0-9]+"); MatchCollection mcol1 = regex.Matches(str1); MatchCollection mcol2 = regex.Matches(str2); if (mcol1.Count != mcol2.Count || mcol1.Count == 0) { return(false); } expression = str2; int val1, val2, padding, pos1, pos2; string f_name = string.Empty, to_replace = 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, SequentialIntFunction> funcs_to_add = new Dictionary <int, SequentialIntFunction>(); for (int i = 1; i <= diffs.Count; i++) { Pair <Pair <int, string>, Pair <int, string> > diff = diffs[i - 1]; f_name = "§" + i.ToString(); //to_replace = diff.Second.Second; //val1 = Int32.Parse(diff.First.Second); //pos1 = diff.First.First; //val2 = Int32.Parse(diff.Second.Second); //pos2 = diff.Second.First; //padding = 0; val1 = val2 = pos1 = pos2 = padding = 0; to_replace = string.Empty; int offset = 0; for (int n = 0; n < mcol2.Count; n++) { Match match1 = mcol1[n]; Match match2 = mcol2[n]; padding = match2.Length; if (diff.Second.First >= match2.Index && diff.Second.First <= (match2.Index + match2.Length - 1) && diff.Second.First + diff.Second.Second.Length - 1 <= match2.Index + match2.Length - 1 && diff.First.First >= match1.Index && diff.First.First <= (match1.Index + match1.Length - 1) && diff.First.First + diff.First.Second.Length - 1 <= match1.Index + match1.Length - 1) { if (match1.Value.Length > 9) { offset = match1.Value.Length - 9; } else { offset = 0; } val1 = Int32.Parse(match1.Value.Substring(offset)); pos1 = match1.Index + offset; if (match2.Value.Length > 9) { offset = match2.Value.Length - 9; } else { offset = 0; } val2 = Int32.Parse(match2.Value.Substring(offset)); pos2 = match2.Index + offset; to_replace = match2.Value.Substring(offset); break; } else { int result; if (!Int32.TryParse(diff.First.Second, out result) && !Int32.TryParse(diff.Second.Second, out result)) { return(false); } } } if (pos1 == pos2 && to_replace != string.Empty) { //expression = expression.Replace(to_replace, f_name); SequentialIntFunction func = new SequentialIntFunction(f_name, val2, val2 - val1, padding, 0, 2); //if (!functions.Contains(func)) // functions.Add(func); if (!positions_to_replace.Contains(pos2)) { positions_to_replace.Add(pos2); fpositions_to_replace.Add(pos2, pos2 + to_replace.Length - 1); 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); } }
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()); }