Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16903


Ignore:
Timestamp:
05/07/19 11:59:07 (6 years ago)
Author:
chaider
Message:

#2971 Added variable definition without escape chars

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs

    r16900 r16903  
    3838          var targetConstraint = trimmedLine.Substring(start, end-start);
    3939          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*([\[\]])");
    4141          if (match.Success) {
    42             if (match.Groups.Count != 8) {
     42            if (match.Groups.Count != 10) {
    4343              throw new ArgumentException("The given target-constraint is not complete!");
    4444            } 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              }
    4549              if (target != "") {
    46                 if (match.Groups[1].Value.Trim() != target) {
     50                if (targetVariable != target) {
    4751                  throw new ArgumentException("The given target variable is not in the given dataset!");
    4852                }
    4953              }
    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);
    5256              var expression = "Target:" + match.Groups[0].Value;
    5357              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() == "]";
    5761              var isDerivation = false;
    5862              var numberOfDerivation = 0;
     
    6973        } else if (trimmedLine.StartsWith("d") || trimmedLine.StartsWith("\u2202")) {
    7074          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*([\[\]])");
    7276
    7377          if (match.Success) {
    74             if (match.Groups.Count != 13) {
     78            if (match.Groups.Count != 17) {
    7579              throw new ArgumentException("The given derivation-constraint is not complete");
    7680            } 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              }
    7790              if (target != "") {
    78                 if (match.Groups[3].Value != target)
     91                if (derivationTarget != target)
    7992                  throw new ArgumentException("The given target variable is not given in the dataset!");
    8093              }
    8194
    8295              if (variables != null && variables.Any()) {
    83                 if (variables.All(v => v != match.Groups[6].Value.Trim())) {
     96                if (variables.All(v => v != derivationVariable)) {
    8497                  throw new ArgumentException("The given variable does not exist in the dataset!");
    8598                }
    8699              }
    87100
    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() == "")
    90103                  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())
    92105                  throw new ArgumentException("Derivation number is not equal on both sides!");
    93106              }
    94107
    95               var lowerBound = ParseIntervalBounds(match.Groups[9].Value);
    96               var upperBound = ParseIntervalBounds(match.Groups[11].Value);
     108              var lowerBound = ParseIntervalBounds(match.Groups[13].Value);
     109              var upperBound = ParseIntervalBounds(match.Groups[15].Value);
    97110              var expression = match.Groups[0].Value;
    98               var parsedTarget = match.Groups[3].Value.Trim();
     111              var parsedTarget = derivationTarget;
    99112              var isDerivation = true;
    100               var inclLowerBound = match.Groups[8].Value.Trim() == "[";
    101               var inclUpperBound = match.Groups[12].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;
    103116              var numberOfDerivation = ParseDerivationCount(match.Groups[2].Value.Trim());
    104117              var interval = new Interval(lowerBound, upperBound);
Note: See TracChangeset for help on using the changeset viewer.