Changeset 16903
- Timestamp:
- 05/07/19 11:59:07 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs
r16900 r16903 38 38 var targetConstraint = trimmedLine.Substring(start, end-start); 39 39 var match = Regex.Match(targetConstraint, 40 @" ['](.*)[']\s*(\bin\b)\s*([\[\]])\s*(\S*)\s*(..)\s*(\S*)\s*([\[\]])");40 @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[\]])\s*(\S*)\s*(..)\s*(\S*)\s*([\[\]])"); 41 41 if (match.Success) { 42 if (match.Groups.Count != 8) {42 if (match.Groups.Count != 10) { 43 43 throw new ArgumentException("The given target-constraint is not complete!"); 44 44 } else { 45 var targetVariable = match.Groups[1].Value.Trim(); 46 if (match.Groups[1].Value.Trim().StartsWith("'") && match.Groups[1].Value.Trim().EndsWith("'")) { 47 targetVariable = targetVariable.Substring(1, targetVariable.Length - 2); 48 } 45 49 if (target != "") { 46 if ( match.Groups[1].Value.Trim()!= target) {50 if (targetVariable != target) { 47 51 throw new ArgumentException("The given target variable is not in the given dataset!"); 48 52 } 49 53 } 50 var lowerBound = ParseIntervalBounds(match.Groups[ 4].Value);51 var upperBound = ParseIntervalBounds(match.Groups[ 6].Value);54 var lowerBound = ParseIntervalBounds(match.Groups[6].Value); 55 var upperBound = ParseIntervalBounds(match.Groups[8].Value); 52 56 var expression = "Target:" + match.Groups[0].Value; 53 57 var parsedTarget = match.Groups[1].Value.Trim(); 54 var variable = match.Groups[1].Value.Trim();55 var inclLowerBound = match.Groups[ 3].Value.Trim() == "[";56 var inclUpperBound = match.Groups[ 7].Value.Trim() == "]";58 var variable = targetVariable; 59 var inclLowerBound = match.Groups[5].Value.Trim() == "["; 60 var inclUpperBound = match.Groups[9].Value.Trim() == "]"; 57 61 var isDerivation = false; 58 62 var numberOfDerivation = 0; … … 69 73 } else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("\u2202")) { 70 74 var match = Regex.Match(trimmedLine, 71 @"([d∂])([²³]?)\s* ['](.*)[']\s*(\/)\s*([d∂])\s*['](.*)[']\s*([²³]?)\s*\bin\b\s*([\[\]])\s*(\S*)\s*(..)\s*(\S*)\s*([\[\]])");75 @"([d∂])([²³]?)\s*(['](.*)[']|(.*[^\s]))\s*(\/)\s*([d∂])\s*(['](.*)[']|(.*[^\s²³]))\s*([²³]?)\s*\bin\b\s*([\[\]])\s*(\S*)\s*(..)\s*(\S*)\s*([\[\]])"); 72 76 73 77 if (match.Success) { 74 if (match.Groups.Count != 1 3) {78 if (match.Groups.Count != 17) { 75 79 throw new ArgumentException("The given derivation-constraint is not complete"); 76 80 } else { 81 var derivationTarget = match.Groups[3].Value.Trim(); 82 var derivationVariable = match.Groups[8].Value.Trim(); 83 84 if (match.Groups[3].Value.Trim().StartsWith("'") && match.Groups[3].Value.Trim().EndsWith("'")) { 85 derivationTarget = derivationTarget.Substring(1, derivationTarget.Length - 2); 86 } 87 if (match.Groups[8].Value.Trim().StartsWith("'") && match.Groups[8].Value.Trim().EndsWith("'")) { 88 derivationVariable = derivationVariable.Substring(1, derivationVariable.Length - 2); 89 } 77 90 if (target != "") { 78 if ( match.Groups[3].Value!= target)91 if (derivationTarget != target) 79 92 throw new ArgumentException("The given target variable is not given in the dataset!"); 80 93 } 81 94 82 95 if (variables != null && variables.Any()) { 83 if (variables.All(v => v != match.Groups[6].Value.Trim())) {96 if (variables.All(v => v != derivationVariable)) { 84 97 throw new ArgumentException("The given variable does not exist in the dataset!"); 85 98 } 86 99 } 87 100 88 if (match.Groups[2].Value.Trim() != "" || match.Groups[ 7].Value.Trim() != "") {89 if (match.Groups[2].Value.Trim() == "" || match.Groups[ 7].Value.Trim() == "")101 if (match.Groups[2].Value.Trim() != "" || match.Groups[11].Value.Trim() != "") { 102 if (match.Groups[2].Value.Trim() == "" || match.Groups[11].Value.Trim() == "") 90 103 throw new ArgumentException("Number of derivation has to be written on both sides!"); 91 if (match.Groups[2].Value.Trim() != match.Groups[ 7].Value.Trim())104 if (match.Groups[2].Value.Trim() != match.Groups[11].Value.Trim()) 92 105 throw new ArgumentException("Derivation number is not equal on both sides!"); 93 106 } 94 107 95 var lowerBound = ParseIntervalBounds(match.Groups[ 9].Value);96 var upperBound = ParseIntervalBounds(match.Groups[1 1].Value);108 var lowerBound = ParseIntervalBounds(match.Groups[13].Value); 109 var upperBound = ParseIntervalBounds(match.Groups[15].Value); 97 110 var expression = match.Groups[0].Value; 98 var parsedTarget = match.Groups[3].Value.Trim();111 var parsedTarget = derivationTarget; 99 112 var isDerivation = true; 100 var inclLowerBound = match.Groups[ 8].Value.Trim() == "[";101 var inclUpperBound = match.Groups[1 2].Value.Trim() == "]";102 var variable = match.Groups[6].Value.Trim();113 var inclLowerBound = match.Groups[12].Value.Trim() == "["; 114 var inclUpperBound = match.Groups[16].Value.Trim() == "]"; 115 var variable = derivationVariable; 103 116 var numberOfDerivation = ParseDerivationCount(match.Groups[2].Value.Trim()); 104 117 var interval = new Interval(lowerBound, upperBound);
Note: See TracChangeset
for help on using the changeset viewer.