Ignore:
Timestamp:
07/22/19 13:39:09 (5 months ago)
Author:
mkommend
Message:

#2971: Renamed views and updated error messages in constraint parser.

File:
1 edited

Legend:

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

    r16957 r17146  
    2828  public static class IntervalConstraintsParser {
    2929
    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);
    3238      foreach (var line in lines) {
    3339        var trimmedLine = line.TrimStart();
     
    3642          var start = "Target:".Length;
    3743          var end = trimmedLine.Length;
    38           var targetConstraint = trimmedLine.Substring(start, end-start);
     44          var targetConstraint = trimmedLine.Substring(start, end - start);
    3945          var match = Regex.Match(targetConstraint,
    4046            @"(['](.*)[']|(.*[^\s]))\s*(\bin\b)\s*([\[\]])\s*(\S*)\s*(\.{2})\s*(\S*)\s*([\[\]])");
    4147          if (match.Success) {
    4248            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.");
    4450            } else {
    4551              var targetVariable = match.Groups[1].Value.Trim();
     
    4753                targetVariable = targetVariable.Substring(1, targetVariable.Length - 2);
    4854              }
    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}.");
    5358              }
     59
    5460              var lowerBound = ParseIntervalBounds(match.Groups[6].Value);
    5561              var upperBound = ParseIntervalBounds(match.Groups[8].Value);
     
    6874            }
    6975          } else {
    70             throw new ArgumentException("The inserted target constraint is not valid!");
     76            throw new ArgumentException("The inserted target constraint is not valid.");
    7177          }
    7278          //Check for derivation
     
    7783          if (match.Success) {
    7884            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.");
    8086            } else {
    8187              var derivationTarget = match.Groups[3].Value.Trim();
     
    8894                derivationVariable = derivationVariable.Substring(1, derivationVariable.Length - 2);
    8995              }
    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}.");
    9399              }
    94100
    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.");
    99103              }
    100104
    101105              if (match.Groups[2].Value.Trim() != "" || match.Groups[11].Value.Trim() != "") {
    102106                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.");
    104108                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.");
    106110              }
    107111
     
    122126            }
    123127          } else {
    124             throw new ArgumentException("The inserted derivation constraint is not valid!");
     128            throw new ArgumentException("The inserted derivation constraint is not valid.");
    125129          }
    126130          //Check for comment
Note: See TracChangeset for help on using the changeset viewer.