Changeset 17146 for branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Timestamp:
- 07/22/19 13:39:09 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
r16957 r17146 28 28 public static class IntervalConstraintsParser { 29 29 30 public static IEnumerable<IntervalConstraint> ParseInput(string input, string target = "", IEnumerable<string> variables = null) { 31 var lines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); 30 public static IEnumerable<IntervalConstraint> ParseInput(string inputText, string target, IEnumerable<string> variables) { 31 32 if (string.IsNullOrEmpty(inputText)) throw new ArgumentNullException("No input text has been provided."); 33 if (string.IsNullOrEmpty(target)) throw new ArgumentNullException("No target variable has been provided."); 34 if (variables == null) throw new ArgumentNullException("No variables have been provided."); 35 if (!variables.Any()) throw new ArgumentException("Varialbes are empty."); 36 37 var lines = inputText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); 32 38 foreach (var line in lines) { 33 39 var trimmedLine = line.TrimStart(); … … 36 42 var start = "Target:".Length; 37 43 var end = trimmedLine.Length; 38 var targetConstraint = trimmedLine.Substring(start, end -start);44 var targetConstraint = trimmedLine.Substring(start, end - start); 39 45 var match = Regex.Match(targetConstraint, 40 46 @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[\]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])"); 41 47 if (match.Success) { 42 48 if (match.Groups.Count != 10) { 43 throw new ArgumentException("The given target-constraint is not complete!");49 throw new ArgumentException("The target-constraint is not complete."); 44 50 } else { 45 51 var targetVariable = match.Groups[1].Value.Trim(); … … 47 53 targetVariable = targetVariable.Substring(1, targetVariable.Length - 2); 48 54 } 49 if (target != "") { 50 if (targetVariable != target) { 51 throw new ArgumentException("The given target variable is not in the given dataset!"); 52 } 55 56 if (targetVariable != target) { 57 throw new ArgumentException($"The target variable {targetVariable} does not match the provided target {target}."); 53 58 } 59 54 60 var lowerBound = ParseIntervalBounds(match.Groups[6].Value); 55 61 var upperBound = ParseIntervalBounds(match.Groups[8].Value); … … 68 74 } 69 75 } else { 70 throw new ArgumentException("The inserted target constraint is not valid !");76 throw new ArgumentException("The inserted target constraint is not valid."); 71 77 } 72 78 //Check for derivation … … 77 83 if (match.Success) { 78 84 if (match.Groups.Count != 17) { 79 throw new ArgumentException("The given derivation-constraint is not complete ");85 throw new ArgumentException("The given derivation-constraint is not complete."); 80 86 } else { 81 87 var derivationTarget = match.Groups[3].Value.Trim(); … … 88 94 derivationVariable = derivationVariable.Substring(1, derivationVariable.Length - 2); 89 95 } 90 if (target != "") { 91 if (derivationTarget != target)92 throw new ArgumentException("The given target variable is not given in the dataset!");96 97 if (derivationTarget != target) { 98 throw new ArgumentException($"The target variable {derivationTarget} does not match the provided target {target}."); 93 99 } 94 100 95 if (variables != null && variables.Any()) { 96 if (variables.All(v => v != derivationVariable)) { 97 throw new ArgumentException("The given variable does not exist in the dataset!"); 98 } 101 if (variables.All(v => v != derivationVariable)) { 102 throw new ArgumentException($"The given variable {derivationVariable} does not exist in the dataset."); 99 103 } 100 104 101 105 if (match.Groups[2].Value.Trim() != "" || match.Groups[11].Value.Trim() != "") { 102 106 if (match.Groups[2].Value.Trim() == "" || match.Groups[11].Value.Trim() == "") 103 throw new ArgumentException("Number of derivation has to be written on both sides !");107 throw new ArgumentException("Number of derivation has to be written on both sides."); 104 108 if (match.Groups[2].Value.Trim() != match.Groups[11].Value.Trim()) 105 throw new ArgumentException("Derivation number is not equal on both sides !");109 throw new ArgumentException("Derivation number is not equal on both sides."); 106 110 } 107 111 … … 122 126 } 123 127 } else { 124 throw new ArgumentException("The inserted derivation constraint is not valid !");128 throw new ArgumentException("The inserted derivation constraint is not valid."); 125 129 } 126 130 //Check for comment
Note: See TracChangeset
for help on using the changeset viewer.