Evaluates a rule over a set of facts through
restriction of the rule's causes.
@param rule
@param facts
@returns {Array}
181905
function(rule, facts) {
        var mappingList = this.getMappings(rule, facts),
            consequences = [], deferred = q.defer();

        try {
            this.checkOperators(rule, mappingList);
            
            for (var i = 0; i < mappingList.length; i++) {
                if (mappingList[i]) {
                    // Replace mappings on all consequences
                    for (var j = 0; j < rule.consequences.length; j++) {                        
                        consequences.push(this.substituteFactVariables(mappingList[i], rule.consequences[j], [], rule));
                        
                    }
                }
            }
            deferred.resolve(consequences);
        } catch(e) {
            deferred.reject(e);
        }

        return deferred.promise;
    }
1190670
function (ruleObject) {
		var name = null;

		for (var k in ruleObject) {
			if (ruleObject.hasOwnProperty(k)) {
				name = k;
				break;
			}
		}

		return Rule.create(name, ruleObject[name]);
	}
337107
function _getRule(attribute, rules) {
    rules = rules || [];

    if ( ! rules[attribute]) {
      return;
    }

    for(var i in rules[attribute]) {
      var value = rules[attribute][i];
      parsedRule = _parseRule(rule);

      if (in_array(parsedRule.rule, rules))
        return [parsedRule.rule, parsedRule.parameters];
    }
  }
745238
function(rs, facts, doTagging, resolvedImplicitFactSet) {
        var deferred = q.defer(), promises = [], cons = [], filteredFacts;
        for (var key in rs) {            
            if (doTagging) {
                promises.push(this.evaluateThroughRestrictionWithTagging(rs[key], facts, resolvedImplicitFactSet));
            } else {
                promises.push(this.evaluateThroughRestriction(rs[key], facts));
            }
        }
        try {                    
            q.all(promises).then(function (consTab) {                
                for (var i = 0; i < consTab.length; i++) {
                    cons = cons.concat(consTab[i]);
                }
                deferred.resolve({cons: cons});
            });
        } catch(e) {
            deferred.reject(e);
        }
        return deferred.promise;
    }
975981
function getRuleOptionsSchema(rule) {
    const schema = rule.schema || rule.meta && rule.meta.schema;

    // Given a tuple of schemas, insert warning level at the beginning
    if (Array.isArray(schema)) {
        if (schema.length) {
            return {
                type: "array",
                items: schema,
                minItems: 0,
                maxItems: schema.length
            };
        }
        return {
            type: "array",
            minItems: 0,
            maxItems: 0
        };

    }

    // Given a full schema, leave it alone
    return schema || null;
}
1076606
function _explodeRules(rules) {
    for (var i in rules) {
      if (is_string(rules[i])) {
        rules[i] = rules[i].split('|');
      }
    }
    return rules;
  }
1336585
function(rule) {
      var ans = arguments[1] !== undefined ? [arguments[1]] : [],
          state;
      while (true) {
        state = this.bt.current_state();
        try { ans.push(rule.call(this)) } 
        catch (f) {
          this.bt.catch_mismatch(f);
          this.bt.restore(state);
          break;
        }
      }
      return ans
    }
615705
def evaluate(attributes = {})
      return true unless rules.any?
      if evaluation_logic == 'any'
        !!rules.detect { |rule| rule.evaluate(attributes) }
      else
        rules.each do |rule|
          return false unless rule.evaluate(attributes)
        end
        true
      end
    end
1123757
private void simplify(PatternRule rule, List<String> xmlLines) {
    List<Integer> linesToRemove = new ArrayList<>();
    String currentRuleId = null;
    Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*");
    String expectedSubId = rule.getSubId();
    int lineCount = 0;
    int subRuleCount = 0;
    int removedCount = 0;
    boolean inRuleGroup = false;
    String newRegex = null;
    boolean inAntiPattern = false;
    for (lineCount = 0; lineCount < xmlLines.size(); lineCount++) {
    //for (String xmlLine : xmlLines) {
      String xmlLine = xmlLines.get(lineCount);
      if (xmlLine.contains("<rulegroup")) {
        subRuleCount = 0;
        inRuleGroup = true;
      } else if (xmlLine.contains("</rulegroup>")) {
        subRuleCount = 0;
        inRuleGroup = false;
      } else if ((xmlLine.contains("<rule ")||xmlLine.contains("<rule>")) && inRuleGroup) {
        subRuleCount++;
      }
      Matcher m = pattern.matcher(xmlLine);
      if (m.matches()) {
        currentRuleId = m.group(1);
      }
      if (currentRuleId != null && !currentRuleId.equals(rule.getId())) {
        continue;
      }
      if (!inRuleGroup) {
        subRuleCount = 1;
      }
      if (!expectedSubId.equals("0") && !expectedSubId.equals(String.valueOf(subRuleCount))) {
        continue;
      }
      if (xmlLine.matches(".*<antipattern.*")) {
        inAntiPattern = true;
      }
      if (inAntiPattern) {
        continue;
      }
      if (xmlLine.matches(".*</antipattern.*")) {
        inAntiPattern = false;
        continue;
      }
      if (xmlLine.matches(".*<(token|pattern).*") || xmlLine.matches("\\s*</?marker>.*")) {
        linesToRemove.add(lineCount);
      }
      if (xmlLine.matches(".*</pattern.*")) {
        linesToRemove.add(lineCount);
        int lastTokenIndent = xmlLine.indexOf("<");
        newRegex = Strings.repeat(" ", lastTokenIndent) + getRegex(rule);
      }
    }
    Collections.reverse(linesToRemove); // start from end, as we need to remove items
    for (Integer s : linesToRemove) {
      xmlLines.remove(s.intValue());
      removedCount++;
    }
    if (removedCount == 0) {
      System.err.println("No line removed: " + rule + "[" + expectedSubId + "]");
    } else {
      xmlLines.add(linesToRemove.get(linesToRemove.size()-1), newRegex);
      touchedRulesCount++;
    }
  }
304065
function _getRule (neighbourhood) {
    var currentState = null
    var currentRule = [...rule]
    neighbourhoods.forEach(function (hood, index) {
      if (hood === neighbourhood) {
        currentState = currentRule[index]
      }
    })

    return currentState
  }
366384
protected function evaluate($rule, array $context = [])
    {
        try {
            $ruleValue = $this->getValueFromRule($rule);
        } catch (\Exception $e) {
            $this->setError('Error attempting to get a value from a rule.');

            return false;
        }

        try {
            $contextValue = $this->getValueFromContext($rule, $context);
        } catch (\Exception $e) {
            $this->setError('Error attempting to get a value from context.');

            return false;
        }

        $result = $this->evaluateRuleAgainstContext($rule, $contextValue, $ruleValue);
        if (!$result) {
            $this->setError(
                $rule->field.' did not '.$rule->operator.' '.$ruleValue.' (actual value was '.$contextValue.')'
            );
        }

        return $result;
    }
937388
def evaluate_rule(self, rule, value, target):
        """"""
        def evaluate(expr):
            if expr in LOGICAL_OPERATORS.values():
                return expr
            rvalue = self.get_value_for_expr(expr, target)
            if rvalue is None:
                return False  # ignore this result
            return expr['op'](value, rvalue)

        evaluated = [evaluate(expr) for expr in rule['exprs']]
        while len(evaluated) > 1:
            lhs, logical_op, rhs = (evaluated.pop(0) for _ in range(3))
            evaluated.insert(0, logical_op(lhs, rhs))

        return evaluated[0]
72973
public void setRules(java.util.Collection<Rule> rules) {
        if (rules == null) {
            this.rules = null;
            return;
        }

        this.rules = new java.util.ArrayList<Rule>(rules);
    }
895123
function overrideRules(rules, patch) {
  return rules.map(ruleToPatch => {
    let rule = patch(ruleToPatch);
    if (rule.rules) {
      rule = { ...rule, rules: overrideRules(rule.rules, patch) };
    }
    if (rule.oneOf) {
      rule = { ...rule, oneOf: overrideRules(rule.oneOf, patch) };
    }
    return rule;
  });
}
966542
function(fact, ruleFact, mapping, constants, rule) {
        var localMapping = {};
    
        // Checks and update localMapping if matches     
        if (!this.factElemMatches(fact.predicate, ruleFact.predicate, mapping, localMapping)) {
            return false;
        }        
        if (!this.factElemMatches(fact.object, ruleFact.object, mapping, localMapping)) {
            return false;
        }
        if (!this.factElemMatches(fact.subject, ruleFact.subject, mapping, localMapping)) {
            return false;
        }
        
        emitter.emit('rule-fired', rule.name);        

        // If an already existing uri has been mapped...
        for (var key in localMapping) {
            if(constants.indexOf(localMapping[key]) !== -1) {
                return false;
            }
        }

        // Merges local and global mapping
        for (var mapKey in mapping) {
            if (mapKey == '__facts__') {
                localMapping[mapKey] = Utils.uniques(mapping[mapKey], [fact]);
            } else {
                for (key in localMapping) {
                    if (mapping[mapKey] == localMapping[key]) {
                        if (mapKey != key) {
                            return false;
                        }
                    }
                }
                localMapping[mapKey] = mapping[mapKey];
            }
        }

        // The new mapping is updated
        return localMapping;    
    }
863360
function RuleTypeToRule(rule) {
        if (rule instanceof Rule)
            return rule;
        if (typeof (rule) === "string")
            return text(rule);
        if (typeof (rule) === "boolean")
            return rule ? Myna.truePredicate : Myna.falsePredicate;
        throw new Error("Invalid rule type: " + rule);
    }
1055205
function getRule(commitlintConfig, ruleName) {
	const rule = commitlintConfig.rules[ruleName];

	if (rule) {
		return {
			raw: rule,
			level: rule[0],
			applicable: rule[1],
			value: rule[2],
		};
	}
}