TODO: Optimize groups of rules with non-empty prefix into some sort of decision tree
353483
function update(evt) {
                if (evt && evt.defaultPrevented) return;

                function check(rule) {
                    var handled = rule($injector, $location);

                    if (!handled) return false;
                    if (isString(handled)) $location.replace().url(handled);
                    return true;
                }
                var n = rules.length, i;

                for (i = 0; i < n; i++) {
                    if (check(rules[i])) return;
                }
                // always check otherwise last to allow dynamic updates to the set of rules
                if (otherwise) check(otherwise);
            }
1187209
private function extractRules()
    {
        // Keep in mind we don't support recursive directories (or cache the results)
        $possibleModels = glob(Strata::getSRCPath() . "Model" . DIRECTORY_SEPARATOR . "*.php");
        $this->batchModelFileRegistrationAttempt((array)$possibleModels);

        $possibleTaxonomies = glob(Strata::getSRCPath() . "Model" . DIRECTORY_SEPARATOR . "Taxonomy" . DIRECTORY_SEPARATOR . "*.php");
        $this->batchTaxonomyFileRegistrationAttempt((array)$possibleTaxonomies);
    }
242243
def _bin(g):
    """"""
    new_rules = []
    for rule in g.rules:
        if len(rule.rhs) > 2:
            new_rules += _split(rule)
        else:
            new_rules.append(rule)
    return Grammar(new_rules)
700107
def prefix(*kinds):
    """"""
    def wrap(fn):
        try:
            fn.prefix_kinds.extend(kinds)
        except AttributeError:
            fn.prefix_kinds = list(kinds)
        return fn
    return wrap
577354
def all
      rules = []

      raw.each do |type, details|
        # Add general rules
        Array(details['prefix']).each do |prefix|
          rules.push({
            prefix: prefix.to_s,
            length: details['length'],
            type:   type
          })
        end

        # Process each country
        Array(details['countries']).each do |country, prefixes|
          # Add a rule for each prefix
          Array(prefixes).each do |prefix|
            rules.push({
              prefix: prefix.to_s,
              length: details['length'],
              type:   type,
              country: country,
            })
          end
        end

      end

      # Sort by prefix length
      rules.sort { |x, y|  y[:prefix].length <=> x[:prefix].length }
    end
90717
def optimize(self):
        """"""
        subpattern = None
        if (self.content is not None and
            len(self.content) == 1 and len(self.content[0]) == 1):
            subpattern = self.content[0][0]
        if self.min == 1 and self.max == 1:
            if self.content is None:
                return NodePattern(name=self.name)
            if subpattern is not None and  self.name == subpattern.name:
                return subpattern.optimize()
        if (self.min <= 1 and isinstance(subpattern, WildcardPattern) and
            subpattern.min <= 1 and self.name == subpattern.name):
            return WildcardPattern(subpattern.content,
                                   self.min*subpattern.min,
                                   self.max*subpattern.max,
                                   subpattern.name)
        return self
664511
public void expandeRule(RuleClassification rl, Instance inst, int ruleIndex) {
		int remainder = (int)Double.MAX_VALUE;
		int numInstanciaObservers = (int)rl.obserClassDistrib.sumOfValues();		// Number of instances for this rule observers.
		this.updateRuleAttribStatistics(inst, rl, ruleIndex);
	    if (numInstanciaObservers != 0 && this.gracePeriodOption.getValue() != 0) {
	        	 remainder = (numInstanciaObservers) % (this.gracePeriodOption.getValue());    
	        }
        if (remainder == 0){
        	this.saveBestValGlobalEntropy = new ArrayList<ArrayList<Double>>();
			this.saveBestGlobalEntropy = new DoubleVector();
			this.saveTheBest = new ArrayList<Double>();
			this.minEntropyTemp = Double.MAX_VALUE;
			this.minEntropyNominalAttrib = Double.MAX_VALUE;
	        theBestAttributes(inst, rl.observers);		// The best value of entropy for each attribute.
            boolean HB = checkBestAttrib(numInstanciaObservers, rl.observers, rl.obserClassDistrib);		// Check if the best attribute value is really the best.
    		if (HB == true) {
    			double attributeValue = this.saveTheBest.get(3);
    			double symbol = this.saveTheBest.get(2);		// =, <=, > (0.0, -1.0, 1.0).
    			double value = this.saveTheBest.get(0);		// Value of the attribute.
    			this.pred = new Predicates(attributeValue, symbol, value);
    			int countPred = 0;
    			for (int i = 0; i < rl.predicateSet.size(); i++) {		// Checks if the new predicate is not yet in the predicateSet. 
					 if (this.pred.getSymbol() == 0.0) {		// Nominal Attribute.
						 if (rl.predicateSet.get(i).getAttributeValue() != this.pred.getAttributeValue()) {
							 countPred = countPred + 1;
						 }
					 }
					 else {
						 if (rl.predicateSet.get(i).getAttributeValue() != this.pred.getAttributeValue() 
								 || rl.predicateSet.get(i).getSymbol() != this.pred.getSymbol() 
								 || rl.predicateSet.get(i).getValue() != this.pred.getValue()) {
							 countPred = countPred+1;
							 }
						 }
					 }
    			if (countPred == rl.predicateSet.size()) {
    				int countDifPred = 0;
					ArrayList<Predicates> predicSetTemp = new ArrayList<Predicates>();
					for (int x = 0; x < rl.predicateSet.size(); x++) {
						predicSetTemp.add(rl.predicateSet.get(x));
					 }
					predicSetTemp.add(this.pred);
					for (int f = 0; f < this.ruleSet.size(); f++) {
						int countDifPredTemp = 0;
						if (this.ruleSet.get(f).predicateSet.size() == predicSetTemp.size()) {
							for(int x = 0; x < this.ruleSet.get(f).predicateSet.size(); x++) {
								if (this.ruleSet.get(f).predicateSet.get(x).getAttributeValue() == predicSetTemp.get(x).getAttributeValue() 
										&& this.ruleSet.get(f).predicateSet.get(x).getSymbol() == predicSetTemp.get(x).getSymbol() 
										&& this.ruleSet.get(f).predicateSet.get(x).getValue() == predicSetTemp.get(x).getValue()) {
									countDifPredTemp = countDifPredTemp+1;
									}
								}
							if (countDifPredTemp == predicSetTemp.size()) {
								break;
								}else{
									countDifPred = countDifPred + 1;
									}
							}else{
						countDifPred = countDifPred + 1;
						}
						}
					if (countDifPred == this.ruleSet.size()) {
						if (this.pred.getSymbol() == 0.0) {
							initializeRuleStatistics(rl, pred, inst);
			    			} else if (this.pred.getSymbol() == 1.0) {
			    				int countIqualPred = 0;
			    				for (int f = 0; f < rl.predicateSet.size(); f++) {
			    					if (this.pred.getAttributeValue() == rl.predicateSet.get(f).getAttributeValue()
			    							&& this.pred.getSymbol() == rl.predicateSet.get(f).getSymbol()) {
			    						countIqualPred = countIqualPred + 1;
			    						if (this.pred.getValue() > rl.predicateSet.get(f).getValue()) {
			    							rl.predicateSet.remove(f);
			    							initializeRuleStatistics(rl, pred, inst);
	    				    				}
			    						}
			    					}
			    				if (countIqualPred == 0) {
			    					initializeRuleStatistics(rl, pred, inst);
	    				    		}
			    				}else{
	    						 int countIqualPred = 0;
	    						 for (int f = 0; f < rl.predicateSet.size(); f++) {
	    							 if (this.pred.getAttributeValue() == rl.predicateSet.get(f).getAttributeValue()
	    									 && this.pred.getSymbol() == rl.predicateSet.get(f).getSymbol()) {
	    								 countIqualPred = countIqualPred + 1;
	    								 if (this.pred.getValue() < rl.predicateSet.get(f).getValue()) {
	    									 rl.predicateSet.remove(f);
	    									 initializeRuleStatistics(rl, pred, inst);
	    				    				 }
	    								 }
	    							 }
	    						 if (countIqualPred == 0) {
	    							 initializeRuleStatistics(rl, pred, inst);
	    							 }
	    						 }
						}
					}
    			}
    		}
        }
444216
def _iterClass(cls, prefix=''):
    
    iterableRules = [(prefix, cls, cls.app.url_map.iter_rules())]
    for prefix, currentClass, i in iter(iterableRules):
        for rule in i:
            converted = dumpRule(currentClass, rule, prefix)
            if converted.branch:
                continue

            if converted.subKlein:
                clsDown = namedAny(converted.subKlein)
                iterableRules.append((converted.rulePath, clsDown, clsDown.app.url_map.iter_rules()))

            yield converted
118333
def parse_python(classifiers):
    """"""
    prefix = 'Programming Language :: Python ::'
    python_classifiers = [c.split('::')[2].strip() for c in classifiers if c.startswith(prefix)]
    return ', '.join([c for c in python_classifiers if parse_version(c)])
328424
function (parts, indent, prefix) {
        var lines = [];
        var line = [];

        var lineLength = !!prefix ? prefix.length - 1: indent.length - 1;

        parts.forEach(function (part) {
          if (lineLength + 1 + part.length > textWidth) {
            lines.push(indent + line.join(' '));
            line = [];
            lineLength = indent.length - 1;
          }
          line.push(part);
          lineLength += part.length + 1;
        });

        if (line) {
          lines.push(indent + line.join(' '));
        }
        if (prefix) {
          lines[0] = lines[0].substr(indent.length);
        }
        return lines;
      }
98054
function allGrammarRules() {
        return Object.keys(Myna.allRules).sort().map(function (k) { return Myna.allRules[k]; });
    }
1353607
def _match_lhs(cp, rules):
    """"""
    rule_matches = []
    for rule in rules:
        reactant_pattern = rule.rule_expression.reactant_pattern
        for rule_cp in reactant_pattern.complex_patterns:
            if _cp_embeds_into(rule_cp, cp):
                rule_matches.append(rule)
                break
    return rule_matches
999967
function (rules) {

    var parsedRules = {};
    rules = this._flattenObject(rules);

    for (var attribute in rules) {

      var rulesArray = rules[attribute];

      this._parseRulesCheck(attribute, rulesArray, parsedRules);
    }
    return parsedRules;


  }
1012100
def _check_self_nonterminals(self, optimized):
        
        # print 'BFS Dictionary Update - Self Non Terminals'
        find = 0
        for nt in self.grammar.grammar_nonterminals_map:
            for i in self.grammar.grammar_nonterminals_map[nt]:
                if (self.grammar.grammar_rules[i][0] not in self.resolved\
                    or self.grammar.grammar_rules[i][0] == 'S') \
                    and isinstance(self.grammar.grammar_rules[i][1], (set, tuple)):
                    # All rules are in CNF form, so first check the A -> BC rules
                    part_a = None
                    if optimized and self._check_self_to_empty(
                            self.grammar.grammar_rules[i][1][0]):
                        part_a = ''
                    elif self.grammar.grammar_rules[i][1][0] in self.resolved:
                        part_a = self.resolved[self.grammar.grammar_rules[i][1][0]]
                    part_b = None
                    if optimized and self._check_self_to_empty(
                            self.grammar.grammar_rules[i][1][1]):
                        part_b = ''
                    elif self.grammar.grammar_rules[i][1][1] in self.resolved:
                        part_b = self.resolved[self.grammar.grammar_rules[i][1][1]]
                    if part_a is not None and part_b is not None:
                        self.resolved[self.grammar.grammar_rules[i][0]] = part_a + part_b
                        # print 'Non Terminals Resolving
                        # '+self.g.Rules[i][0]+": "+
                        # self.Resolved[self.g.Rules[i][0]]
                        if self._checkfinal(self.grammar.grammar_rules[i][0]):
                            return self.resolved[self.grammar.grammar_rules[i][0]]
                        if self.grammar.grammar_rules[i][0] not in self.bfs_queue:
                            self.bfs_queue.append(self.grammar.grammar_rules[i][0])
                        find = 1

        if find == 1:
            return 1
        return 0
892140
function getSortedRuleValues(grammar) {
  return Object.keys(grammar.rules).sort().map(function(name) { return grammar.rules[name]; });
}
210162
def InterpolateGrouping(self, pattern):
    """"""
    components = []
    offset = 0
    for match in GROUPING_PATTERN.finditer(pattern):
      components.append([pattern[offset:match.start()]])

      # Expand the attribute into the set of possibilities:
      alternatives = match.group(1).split(",")
      components.append(set(alternatives))
      offset = match.end()

    components.append([pattern[offset:]])
    # Now calculate the cartesian products of all these sets to form all
    # strings.
    for vector in itertools.product(*components):
      yield u"".join(vector)
709943
def prefix(tokens, operator_table):
    """"""
    operator, matched_tokens = operator_table.prefix.match(tokens)
    if operator:
        return TokenMatch(operator, None, matched_tokens)