//[orand]* \w* *is *\"([^\"]*)\" //https://regex101.com/ //[orand]* \w* *[is not]* *\"([^\"]*)\" //34534 34534 345645654A is "test" or 345645654A is"best" and terter is "fdkjghfd" or sfsd is not "rtre" //34534 34534 345645654A is not "test" and 345645654A is"best" and terter is "fdkjghfd" or sfsd is not "rtre" public static Expressions GetExpressionsForrPresentation(List <Question> listOfQuestions, string line) { try { //In the spreadhseet the response if enclosed in double quotes string regex = "(?'operator' or| and)? (?'question'\\w*) *(?'comparer'is|not|is not)? *\"(?'response'[^\"]*)\""; var clauses = from Match match in Regex.Matches(line, regex) select match; var expressions = clauses.Select(s => { string op = s.Groups["operator"].Success ? s.Groups["operator"].Value.Trim() : "and"; string questionId = s.Groups["question"].Success ? s.Groups["question"].Value.Trim() : "none"; string response = s.Groups["response"].Success ? s.Groups["response"].Value.Trim() : "none"; string comparer = s.Groups["comparer"].Success ? s.Groups["comparer"].Value.Trim() : "none"; var q = GetQuestionFromTreeByRef(listOfQuestions, questionId); var expression = new Expression() { Operator = op, QuestionId = q.Id, QuestionRef = q.Ref, ValueToCompareWith = response, Positive = Fuzzy.AreSimilar(comparer, "is"), }; return(expression); }); return(new Expressions(expressions)); } catch (InvalidOperationException ex) { throw new InvalidOperationException(ex.Message + Environment.NewLine + "expression text: " + line); } }
public bool Evaluate() { if (_GroupedExpression == null || _GroupedExpression.FirstOrDefault() == null) { return(true); } bool groupResult = true; foreach (var list in _GroupedExpression) { bool expResult = false; foreach (var exp in list) { //These are all 'or' so return as soon as one if (exp.Positive) { if (Fuzzy.AreSimilar(GetUserResponse(exp.QuestionId).Display, exp.ValueToCompareWith)) { expResult = true; continue; } else { break; } } else { if (!Fuzzy.AreSimilar(GetUserResponse(exp.QuestionId).Display, exp.ValueToCompareWith)) { expResult = true; continue; } else { break; } } } groupResult = groupResult && expResult; if (groupResult == false) { break; } } return(groupResult); }