/*
Rules are sorted in descending order of "specificity".
So we order first by SURT, exact-match,
then group, then policy.
540029
public int compareTo(Rule o) {
    	
    	int i; 
        
        i = doCompare(this.getSurt(), o.getSurt());
        
        if (i != 0) {
        	return i;
        }
        
        // exact matches come after non-exact
    	i = doCompare(this.getExactMatch(), o.getExactMatch());
    	
        if (i != 0) {
        	return i;
        }
        
    	// Compare by accessGroup, specific accessGroups take precedence
    	i = doCompare(this.getWho(), o.getWho());
        
        if (i != 0) {
        	return i;
        }         

        // if we're still equal try capture date start
    	i = doCompare(this.getCaptureStart(), o.getCaptureStart());
        
        if (i != 0) {
        	return i;
        }    	

        // and retrieval date
    	i = doCompare(this.getRetrievalStart(), o.getRetrievalStart());

        if (i != 0) {
        	return i;
        }    	
    	
    	i = doCompare(this.getSecondsSinceCapture(), o.getSecondsSinceCapture());
            
        return i;
    }
628966
public function order($rule, $order = null){
		if($this->validateConditions())
			return $this;

		$this->resetState();

		if(is_array($rule) || $rule instanceof Traversable){
			foreach($rule as $key => $val){
				$this->order($key, $val);
			}
			return $this;
		}
		$this->sorting[] = array($rule, $order);

		return $this;
	}
409124
def first_set
      first = steps[0]

      if first.is_a?(Rule)
        return first.first_set
      elsif first
        return [first]
      else
        return []
      end
    end
977610
@Override
	public List<CPRule> findByGroupId(long groupId) {
		return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}
892140
function getSortedRuleValues(grammar) {
  return Object.keys(grammar.rules).sort().map(function(name) { return grammar.rules[name]; });
}
926260
function filterValidRule(rule) {
  return (rule.hasOwnProperty('match')&&typeof rule.match === "object")
  && (rule.hasOwnProperty('use') && (
    typeof rule.use === "object"
    || typeof rule.use === "function"
  ))
  && (
    (rule.match.hasOwnProperty('request'))
    || (rule.match.hasOwnProperty('base'))
  )
}
778477
private void executeGroup(RuleSet ruleSet, Group group, Severity parentSeverity) throws RuleException {
        if (!executedGroups.contains(group)) {
            ruleVisitor.beforeGroup(group, getEffectiveSeverity(group, parentSeverity, parentSeverity));
            for (Map.Entry<String, Severity> conceptEntry : group.getConcepts().entrySet()) {
                applyConcepts(ruleSet, conceptEntry.getKey(), parentSeverity, conceptEntry.getValue());
            }
            for (Map.Entry<String, Severity> groupEntry : group.getGroups().entrySet()) {
                executeGroups(ruleSet, groupEntry.getKey(), parentSeverity, groupEntry.getValue());
            }
            Map<String, Severity> constraints = group.getConstraints();
            for (Map.Entry<String, Severity> constraintEntry : constraints.entrySet()) {
                validateConstraints(ruleSet, constraintEntry.getKey(), parentSeverity, constraintEntry.getValue());
            }
            ruleVisitor.afterGroup(group);
            executedGroups.add(group);
        }
    }
967582
private void lsUpdateGroup(final int isa, final int first, final int last) {
        final int[] SA = this.SA;

        int a, b;
        int t;

        for (a = first; a < last; ++a) {
            if (0 <= SA[a]) {
                b = a;
                do {
                    SA[isa + SA[a]] = a;
                } while (++a < last && 0 <= SA[a]);
                SA[b] = b - a;
                if (last <= a) {
                    break;
                }
            }
            b = a;
            do {
                SA[a] = ~SA[a];
            } while (SA[++a] < 0);
            t = a;
            do {
                SA[isa + SA[b]] = t;
            } while (++b <= a);
        }
    }
3222
function RouteRule_match(rgx, str) {
        var group, matched, data = [];
        if (Type.isString(rgx)) {
            rgx = this.toRegex(rgx);
        }
        if (Type.isObject(rgx) && Type.isRegExp(rgx.regex)) {
            if (rgx.group && rgx.group.length) {
                group = rgx.group;
                matched = core.match(rgx.regex, str).shift();
                if (Type.isArray(matched)) {
                    matched = matched.slice(1, matched.length - 2);
                    group.forEach(function (item) {
                        data.push({
                            key: item.isNamed ? item.key : false,
                            index: item.index,
                            value: matched[item.index]
                        });
                    });
                }
            } else {
                return core.match(rgx.regex, str);
            }
        } else if (Type.isRegExp(rgx)) {
            return core.match(rgx, str);
        }
        return data;
    }
993530
function seq() {
        var rules = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            rules[_i - 0] = arguments[_i];
        }
        var rs = rules.map(RuleTypeToRule);
        if (rs.length == 0)
            throw new Error("At least one rule is expected when calling `seq`");
        if (rs.length == 1)
            return rs[0];
        var rule1 = rs[0];
        var rule2 = seq.apply(void 0, rs.slice(1));
        if (rule1.nonAdvancing && rule2 instanceof Advance)
            return new AdvanceIf(rule1);
        else
            return new Sequence(rule1, rule2);
    }
611292
function (businessRule) {
    if (!businessRule || !_.isObject(businessRule)) {
      var err = new Error('Please inject a valid businessRule object!');
      debug(err);
      throw err;
    }

    if (this.businessRules.indexOf(businessRule) < 0) {
      businessRule.defineAggregate(this);
      this.businessRules.push(businessRule);
      this.businessRules = _.sortBy(this.businessRules, function(br) {
        return br.priority;
      });
    }
  }
249936
function precedenceAdjustmentSpecification(word){
    var regex_rules = [
        /^be(.*)lah$/,
        /^be(.*)an$/,
        /^me(.*)i$/,
        /^di(.*)i$/,
        /^pe(.*)i$/,
        /^ter(.*)i$/,
    ];

    for(var i in regex_rules){
        if(word.match(regex_rules[i])){
            return true;
        }
    }
    return false;
}
160722
def match(self, rule):
        
        if len(self.filters) == 0:
            return True

        for filter in self.filters:
            if filter.match(rule):
                return True
        return False
1360858
def _rule_compare(rule1, rule2):
    '''
    
    '''

    commonkeys = set(rule1.keys()).intersection(rule2.keys())
    for key in commonkeys:
        if rule1[key] != rule2[key]:
            return False
    return True
2896
function applyRules(_string, _ruleSet, _skip) {

      if(_skip.indexOf(_string.toLowerCase()) === -1) {
        var i = 0, rule;
        while(rule = _ruleSet[i++]) {
          if(_string.match(rule[0])) {
            return _string.replace(rule[0], rule[1]);
          }
        }
      }

      return _string;
    }
1080840
function checkGroup(query, group) {
    if (group instanceof Array) {
      // check each condition from group
      for ( var c in group) {
        check(query, group[c]);
      }
    }
  }
820560
private AbstractRule processRule(RulesTextProvider textProvider)
    {
    	log.debug("processRule");
    	int start = textProvider.getPos();
        Rule rule = new Rule();
        LoadCommonRuleData(rule,textProvider);
        textProvider.addTOCElement(null, rule.getDescription(), start, textProvider.getPos(), TYPE_RULE);
        exactOrError("{",textProvider);
        
        if (!exact("if",textProvider))
            throw new ParserException("expected 'if' in a rule: ",textProvider);
        // Condition
        Expression condition = processCondition(textProvider);
        rule.addCondition(condition);
        exactOrError("{",textProvider);
        while (!exact("}",textProvider))
        {
            Expression action = processAction(textProvider);
            exact(";",textProvider);
            rule.addAction(action);
        }
        exact("}",textProvider);

        return rule;
    }