Convert the structure of the rules to facilitate the generating proccess.
352804
def get_sections
            symbolize! @rules
            raise "[body] section on YAML file is needed to generate the report." if @rules[:body].nil?
            @sections = {:page => @rules[:page], :body => @rules[:body], :defaults => @rules[:defaults], :groups => {}}
            @sections[:body][:settings][:groups].each { |group|  @sections[:groups][group.to_sym] = @rules[group.to_sym] } if has_groups?
        end
715953
function createRules() {
  const rules = {};
  sets.forEach((set) => {
    set.lngs.forEach((l) => {
      rules[l] = {
        numbers: set.nr,
        plurals: _rulesPluralsTypes[set.fc]
      };
    });
  });
  return rules;
}
548287
private void trainRuleOnInstance(int ruleID, Instance instance) {
        //System.out.println("Processor:"+this.processorId+": Rule:"+ruleID+" -> Counter="+counter);
		Iterator<ActiveRule> ruleIterator= this.ruleSet.iterator();
		while (ruleIterator.hasNext()) {
			ActiveRule rule = ruleIterator.next();
			if (rule.getRuleNumberID() == ruleID) {
				// Check (again) for coverage
				if (rule.isCovering(instance) == true) {
					double error = rule.computeError(instance); //Use adaptive mode error
                    boolean changeDetected = ((RuleActiveRegressionNode)rule.getLearningNode()).updateChangeDetection(error);
                    if (changeDetected == true) {
                            ruleIterator.remove();
                            
                            this.sendRemoveRuleEvent(ruleID);
                    } else {
                    	rule.updateStatistics(instance);
                    	if (rule.getInstancesSeen()  % this.gracePeriod == 0.0) {
                    		if (rule.tryToExpand(this.splitConfidence, this.tieThreshold) ) {
                    			rule.split();
                    			
                    			// expanded: update Aggregator with new/updated predicate
                    			this.sendPredicate(rule.getRuleNumberID(), rule.getLastUpdatedRuleSplitNode(), 
        								(RuleActiveRegressionNode)rule.getLearningNode());
                    		}	
                    		
                    	}
                    	
                    }
				}
				
				return;
			}
		}
	}
191031
def prepare(self, rule):
        
        if self.parser:
            rule = self.parser.parse(rule)
        if self.compiler:
            rule = self.compiler.compile(rule)
        return rule
619290
function processRules(rules) {


		if (rules !== undefined) {

			rCount = rules.length;

			//reduce common declarations amongst children into parent
			if (OPTIONS.new_reduce_common_into_parent) {


				var directParents = [];
				var hierachy = [];
				var hierachyKeys = [];
				var hierachyLen = 0;
				var selectedHierachyLevel = 0;
				var commonParentsIdx = -1;
				var commonParentsKeys = [];
				var commonParents = [];
				var commonParentsLen = 0;
				var commonParent = '';
				var commonParent2 = '';
				var commonParentTotal = 0;
				var commonParentDeclarations = [];
				var commonLineage = '';
				var newParentDeclarations = [];
				var processedCommonParentsChildren = [];
				var classLineage = '';
				var parentClassLineage = '';
				var lineageLabel = '';
				var tmpDeclarations = [];

				for (i = 0; i < rCount; ++i) {

					///rules
					//group classes - create hierarchy
					if (rules[i].selectors !== undefined) {
						for (j = 0; j < rules[i].selectors.length; j++) { //each comma delimited
							
							if (rules[i].selectors[j].indexOf('.') != -1) {

								classLineage = rules[i].selectors[j].split(' ');
								parentClassLineage = classLineage.slice(0); //clone
								parentClassLineage.pop();
								parentClassLineage = parentClassLineage.join(' ');

								if (parentClassLineage !== undefined && parentClassLineage != '') {

									if (directParents[parentClassLineage] !== undefined) {
										directParents[parentClassLineage].push({
											selector: rules[i].selectors[j],
											index: i
										});
									} else {
										directParents[parentClassLineage] = [{
											selector: rules[i].selectors[j],
											index: i
										}];	
									}
									
								}


								for (k = 0; k < classLineage.length; k++) { //depth of hierachy

									if (k > 0) {
										lineageLabel = '';

										for (l = k; l > 0; l--) {
											lineageLabel += classLineage[k-l] + ' ';	
										}
										lineageLabel += classLineage[k];	

										if (hierachy[lineageLabel] === undefined) {
											hierachy[lineageLabel] = 0;
										}

										hierachy[lineageLabel] += 1;

									} else {

										if (hierachy[classLineage[k]] === undefined) {
											hierachy[classLineage[k]] = 0;
										}

										hierachy[classLineage[k]] += 1;
									}
								} //end of for
							} //end of if
						} //end of for
					}
				}

				function sortHierachy(obj) {
					var keys = Object.keys(obj);
					keys.sort(function(a,b){return b.length-a.length})
					hierachy = [];
					for (i = 0; i < keys.length; i++) {

						hierachy[keys[i]] = obj[keys[i]];


						Object.keys(directParents).forEach(function(key, index, val) {
						  
						  if (this[key].length > 1) {
							  for (j = 0; j < this[key].length; j++) {

							  	if (keys[i] == this[key][j].selector) {

								  	if (OPTIONS.verbose) { console.log(success('Process - Rules - Group Common Parent Rule : ' + keys[i] ));}
								  	commonParentsKeys.push({
								  		selector: key,
								  		index: this[key][j].index,
								  		childSelector: keys[i]
								  	});
								  }
							  }
							}

						}, directParents);
					}
					return hierachy;
				}
				sortHierachy(hierachy);
				hierachyKeys = Object.keys(hierachy);
				hierachyLen = hierachyKeys.length;
				selectedHierachyLevel = 0;
				commonParentsLen = commonParentsKeys.length;

				// get declarations
				for (i = 0; i < commonParentsKeys.length; i++) {

					if (rules[commonParentsKeys[i].index].declarations !== undefined) {

						for (j = 0; j < rules[commonParentsKeys[i].index].declarations.length; j++) {

							if (commonParentDeclarations[rules[commonParentsKeys[i].index].declarations[j].property + '_' + rules[commonParentsKeys[i].index].declarations[j].value] !== undefined) {

								commonParentDeclarations[rules[commonParentsKeys[i].index].declarations[j].property + '_' + rules[commonParentsKeys[i].index].declarations[j].value].count += 1;

							} else {
								commonParentDeclarations[rules[commonParentsKeys[i].index].declarations[j].property + '_' + rules[commonParentsKeys[i].index].declarations[j].value] = {

									property: rules[commonParentsKeys[i].index].declarations[j].property,
									value: rules[commonParentsKeys[i].index].declarations[j].value,
									count: 1,
									selector: rules[commonParentsKeys[i].index].selectors,
									selectorIndex: commonParentsKeys[i].index,
									commonParent: commonParentsKeys[i].selector
								};
							}
						}

					}

				}

				Object.keys(commonParentDeclarations).forEach(function(val, index, key) {

					if (this[val].count == directParents[this[val].commonParent].length) {

						if (newParentDeclarations[this[val].commonParent] !== undefined) {
							newParentDeclarations[this[val].commonParent].declarations.push({
								type: 'declaration',
								property: this[val].property,
								value: this[val].value
							});
						} else {
							newParentDeclarations[this[val].commonParent] = {
								declarations: [{
									type: 'declaration',
									property: this[val].property,
									value: this[val].value
								}],
								selectorIndex: this[val].selectorIndex
							};
						}

						commonParents.push(this[val].commonParent);
					}

				}, commonParentDeclarations);


				commonParentsLen = commonParentsKeys.length;

				for (i = 0; i < commonParentsLen; i++) {

					Object.keys(newParentDeclarations).forEach(function(key, index) {

						if (commonParentsKeys[i] !== undefined && commonParentsKeys[i].selector == key) {

						  if (rules[commonParentsKeys[i].index] !== undefined && rules[commonParentsKeys[i].index].declarations !== undefined) {
						  	
						  	//clone declarations
						  	tmpDeclarations = rules[commonParentsKeys[i].index].declarations.slice(0); //clone
						  	dCount = tmpDeclarations.length;
							  
						  	for (j = 0; j < this[key].declarations.length; j++) { //each parent declaration

							  	//remove declarations
							  	for (k = 0; k < dCount; k++) { //each child declaration

							  		if (
							  			this[key].declarations[j] !== undefined
							  			&& this[key].declarations[j].type == 'declaration'
							  			&& this[key].declarations[j].property == tmpDeclarations[k].property
							  			&& this[key].declarations[j].value == tmpDeclarations[k].value
							  		) {
							  			tmpDeclarations.splice(k, 1); 
							  			k -= 1;
							  			dCount-=1;
							  		}
							  	} //end of k loop

							  } //end of j loop
							  
							  if (tmpDeclarations.length == 0) {

							  	//remove whole rule
							  	rules.splice(commonParentsKeys[i].index, 1);
							  	i-=1;
							  	commonParentsLen-=1;

							  } else {
							  	//update declarations
							  	rules[commonParentsKeys[i].index].declarations = tmpDeclarations;
							  }
								  	
						  }
						}
					  
					}, newParentDeclarations);
				} //end of i loop

				//Create Common Parents
				Object.keys(newParentDeclarations).forEach(function(key, index) {
				  
				  rules.splice( ((this[key].selectorIndex-1 < 0) ? this[key].selectorIndex : this[key].selectorIndex-1), 0, {
						type : 'rule',
						selectors: [key],
						declarations: this[key].declarations
					});

				}, newParentDeclarations);

				//some cleanup
				directParents = [];
				hierachy = [];
				hierachyKeys = [];
				commonParentsKeys = [];
				commonParents = [];
				commonParentDeclarations = [];
				newParentDeclarations = [];
				processedCommonParentsChildren = [];
				tmpDeclarations = [];
				
				//reset rules count
				rCount = rules.length;

			} //end of reduce common declarations amongst children into parent





			for (i = 0; i < rCount; ++i) {

				////comments
				//checking declarations for comments
				if (rules[i] !== undefined && rules[i].declarations !== undefined) {
					declarations = rules[i].declarations;
					dCount = declarations.length;

					for (j = 0; j < dCount; ++j) {

						//check for empty properties
						if (rules[i].declarations[j].value == '') {
							summary.empty_declarations.push({
								'selectors': rules[i].selectors,
								'property': rules[i].declarations[j]
							});
						}

						//remove comments in declarations - for turning off comments
						if (OPTIONS.trim_comments || OPTIONS.trim) {
							if (declarations[j] !== undefined && declarations[j].type == 'comment') {
								if (OPTIONS.verbose) { console.log(info('Process - Rules - Remove Comment')); }
								rules[i].declarations.splice(j, 1);
								j-=1;
								dCount-=1;
							}
						}
					}
				}

				//remove comments in root - for turning off comments
				if (OPTIONS.trim_comments || OPTIONS.trim) {
					if (rules[i] !== undefined && rules[i].type == 'comment') {
						if (OPTIONS.verbose) { console.log(info('Process - Rules - Remove Comment')); }
						rules.splice(i, 1);
						i-=1;
						rCount-=1;
					}
				}
				////end of comments


				////rules
				//remove duplicate root rules
				for (j = i+1; j < rCount; ++j) {
					// console.log(j, rCount)
					//root rules
					//rule selector
					if (rules[i] !== undefined 
						// && rules[i].type == 'rule'
						&& rules[i].selectors !== undefined 
						&& rules[j] !== undefined && rules[j].selectors !== undefined) {

						//duplicate rule found
						if (rules[i].selectors.toString() == rules[j].selectors.toString()) {

							//remove previous comment in root
							if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
								if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {

									rules.splice(i-1, 1);
									i-=1;
									j-=1;
									rCount-=1;
								}
							}

							if (OPTIONS.verbose) { console.log(success('Process - Rules - Group Duplicate Rule : ' + (rules[j].selectors ? rules[j].selectors.join(', ') : '')));}

							//copy + reduce
							summary.stats.summary.noDuplicateRules += 1;
							if ( j < i && (j-i) > 1 ) { //check comparison distance
								summary.duplicate_rules.push({
									'selectors': (rules[i].type == 'page') ? '@page' : rules[i].selectors,
									'position': rules[i].position
								});
								rules[j].declarations = rules[j].declarations.concat(rules[i].declarations);
								rules.splice(i, 1);
							} else {
								summary.duplicate_rules.push({
									'selectors': (rules[j].type == 'page') ? '@page' : rules[j].selectors,
									'position': rules[j].position
								});
								rules[i].declarations = rules[i].declarations.concat(rules[j].declarations);
								rules.splice(j, 1);
							}
							i-=1;
							j-=1;
							rCount-=1;				

						}
					} //end of rule selector

					//media selector - it could affect evaluation sequence
					if (rules[i] !== undefined && rules[i].type == 'media' 
						&& rules[i].media !== undefined 
						&& rules[j] !== undefined && rules[j].media !== undefined
						&& OPTIONS.bypass_media_rules != true
					) {

						//duplicate rule found
						if (rules[i].media.toString() == rules[j].media.toString()) {

							//remove previous comment in root
							if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
								if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {

									rules.splice(i-1, 1);
									i-=1;
									j-=1;
									rCount-=1;
								}
							}

							if (OPTIONS.verbose) { console.log(info('Process - Rules - @media - Group Duplicate Rule : ' + (rules[j].selectors ? rules[j].selectors.join(', ') : ''))); }

							//copy + reduce
							summary.stats.summary.noDuplicateRules += 1;
							if ( j < i && (j-i) > 1 ) { //check comparison distance
								summary.duplicate_rules.push({
									'selectors': '@media ' + rules[i].media,
									'position': rules[i].position
								});
								rules[j].rules = rules[j].rules.concat(rules[i].rules);
								rules.splice(i, 1);
							} else {
								summary.duplicate_rules.push({
									'selectors': '@media ' + rules[j].media,
									'position': rules[j].position
								});
								rules[i].rules = rules[i].rules.concat(rules[j].rules);
								rules.splice(j, 1);
							}
							i-=1;
							j-=1;
							rCount-=1;
						}
					} 
					//end of media selector

					//document selector
					if (rules[i] !== undefined && rules[i].type == 'document' 
						&& rules[i].document !== undefined 
						&& rules[j] !== undefined && rules[j].document !== undefined) {

						//duplicate rule found
						if (rules[i].document.toString() == rules[j].document.toString()) {

							//remove previous comment in root
							if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
								if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {

									rules.splice(i-1, 1);
									i-=1;
									j-=1;
									rCount-=1;
								}
							}

							if (OPTIONS.verbose) { console.log(success('Process - Rules - @document - Group Duplicate Rule : ' + (rules[j].selectors ? rules[j].selectors.join(', ') : ''))); }

							//copy + reduce
							summary.stats.summary.noDuplicateRules += 1;
							if ( j < i && (j-i) > 1 ) { //check comparison distance
								summary.duplicate_rules.push({
									'selectors': '@document ' + rules[i].document,
									'position': rules[i].position
								});
								rules[j].rules = rules[j].rules.concat(rules[i].rules);
								rules.splice(i, 1);
							} else {
								summary.duplicate_rules.push({
									'selectors': '@document ' + rules[j].document,
									'position': rules[j].position
								});
								rules[i].rules = rules[i].rules.concat(rules[j].rules);
								rules.splice(j, 1);
							}
							i-=1;
							j-=1;
							rCount-=1;
							
						}
					} //end of document selector

					//supports selector
					if (rules[i] !== undefined && rules[i].type == 'supports' 
						&& rules[i].supports !== undefined 
						&& rules[j] !== undefined && rules[j].supports !== undefined) {

						//duplicate rule found
						if (rules[i].supports.toString() == rules[j].supports.toString()) {

							//remove previous comment in root
							if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
								if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {

									rules.splice(i-1, 1);
									i-=1;
									j-=1;
									rCount-=1;
								}
							}

							
							if (OPTIONS.verbose) { console.log(success('Process - Rules - @supports - Group Duplicate Rule : ' + (rules[j].supports ? rules[j].supports : ''))); }

							//copy + reduce
							summary.stats.summary.noDuplicateRules += 1;
							if ( j < i && (j-i) > 1 ) { //check comparison distance
								summary.duplicate_rules.push({
									'selectors': '@supports ' + rules[i].supports,
									'position': rules[i].position
								});
								rules[j].rules = rules[j].rules.concat(rules[i].rules);
								rules.splice(i, 1);
							} else {
								summary.duplicate_rules.push({
									'selectors': '@supports ' + rules[j].supports,
									'position': rules[j].position
								});
								rules[i].rules = rules[i].rules.concat(rules[j].rules);
								rules.splice(j, 1);
							}
							i-=1;
							j-=1;
							rCount-=1;
							

						}
					} //end of supports selector



				} //end of j
				////end of rules


				////declarations
				//reduce root delcarations by property name and by duplicate values
				if (rules[i] !== undefined 
					&& (rules[i].type == 'rule' || (rules[i].type == 'page' && OPTIONS.bypass_page_rules == false))
				) {

					declarationsNameCounts = [];

					dCount = rules[i].declarations.length;

					//declarations duplicate check
					for (l = 0; l < dCount; ++l) {

						if (rules[i].declarations[l].type == 'declaration') {
							if (declarationsNameCounts[rules[i].declarations[l].property] !== undefined) {
								declarationsNameCounts[rules[i].declarations[l].property] += 1;
							} else {
								declarationsNameCounts[rules[i].declarations[l].property] = 1;
							}
						}
					} //end of declarations duplicate check


					//reduce according to values
					declarationsValueCounts = [];
					valKey = '';
					//detect duplicate values
					for (key in declarationsNameCounts) {

			      if (!reduceRulesListName.includes(key)) { //only properties not in list


							for (l = 0; l < dCount; ++l) {

								if (
									rules[i].declarations[l].type == 'declaration'
									&& rules[i].declarations[l].property == key
								) {
									hash = crypto.createHash('sha256');
									hash.update(rules[i].declarations[l].property + rules[i].declarations[l].value);
									
									valKey = hash.digest('hex');

									if (declarationsValueCounts[valKey] !== undefined) {
										declarationsValueCounts[valKey].id += ',' + l;
										declarationsValueCounts[valKey].count += 1;
									} else {
										declarationsValueCounts[valKey] = {
											id : l,
											count : 1
										}
									}
								}
							}
			      }
			    }

			    //remove duplicate declarations by duplicate values
			    declarationsValueCountsCount = Object.keys(declarationsValueCounts).length;

			    amountRemoved = 1;

					for (key in declarationsValueCounts) {
			      if (declarationsValueCounts.hasOwnProperty(key)) {


			      	if (declarationsValueCounts[key].count > 1) {
			      		duplicate_ids = declarationsValueCounts[key].id.split(',');

			      		amountRemoved = 1; //shift the ids by the amount removed
								for (l = 0; l < duplicate_ids.length-1; ++l) { // -1 to leave last behind

									//remove previous comment above declaration to be removed
									if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {

										if (rules[i].declarations[duplicate_ids[l]-1] !== undefined && rules[i].declarations[duplicate_ids[l]-1].type == 'comment') {

											rules[i].declarations.splice(duplicate_ids[l]-1, 1);
											dCount-=1;

											//adjust removal ids by amount already removed
											if (duplicate_ids[l] !== undefined) {
												duplicate_ids[l] -= amountRemoved; //shift the ids by the amount removed
											}
											amountRemoved += 1;
										}
									}

									if (OPTIONS.verbose) { console.log(success('Process - Declaration - Group Duplicate Declarations : ' + (rules[i].selectors ? rules[i].selectors.join(', ') : '') + ' - ' + (rules[i].declarations[l]!==undefined?rules[i].declarations[l].property:''))); }

									summary.duplicate_declarations.push(rules[i].declarations[duplicate_ids[l]]);
									summary.stats.summary.noDuplicateDeclarations += 1;
									rules[i].declarations.splice(duplicate_ids[l], 1);
									dCount-=1;

									//adjust removal ids by amount already removed
									if (duplicate_ids[l+1] !== undefined) {
										duplicate_ids[l+1] -= amountRemoved; //shift the ids by the amount removed

										//shift all the ids of the declarations afterwards
										for (key2 in declarationsValueCounts) {
											if (declarationsValueCounts.hasOwnProperty(key2) && (key2 != key)) {

												if (typeof declarationsValueCounts[key2].id == 'number') {
													duplicate_ids = [];
													duplicate_ids[0] = declarationsValueCounts[key2].id;
												} else {
													duplicate_ids = declarationsValueCounts[key2].id.split(',');	
												}
							      		
							      		for (l = 0; l < duplicate_ids.length; ++l) {
							      			
													if (duplicate_ids[l] !== undefined) {
								      			duplicate_ids[l] -= amountRemoved;
								      		}
							      		}
							      		declarationsValueCounts[key2].id = duplicate_ids.join();
											}
										}
										//end of shifting all ids

									}
									amountRemoved += 1;
								}

				      } //end of if
			      } //end of if
			    } //end of for in
					//end of reduce according to values

					for (k = 0; k < reduceRulesListNameCount; ++k) {

						//declarations reduction
						for (key in declarationsNameCounts) {
				      if (declarationsNameCounts.hasOwnProperty(key)) {

								if (declarationsNameCounts[key] > 1) {

									for (l = 0; l < dCount; ++l) {
										if (rules[i].declarations[l].type == 'declaration') {

											if (
												rules[i].declarations[l].property == key 
												&& declarationsNameCounts[key] > 1 //leave behind 1
											) {

												//reduce according to list
												if (rules[i].declarations[l].property == reduceRulesListName[k]) { 
													
													// console.log(declarationsNameCounts[key])
													// console.log(key)
													// console.log(rules[i].declarations[l].property)
													// console.log(reduceRulesListName[k])

													//remove previous comment above declaration to be removed
													if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
														if (rules[i].declarations[l-1] !== undefined && rules[i].declarations[l-1].type == 'comment') {

															rules[i].declarations.splice(l-1, 1);
															l-=1;
															dCount-=1;
														}
													}

													if (OPTIONS.verbose) { console.log(success('Process - Declaration - Group Duplicate Declarations : ' + (rules[i].selectors ? rules[i].selectors.join(', ') : '') + ' - ' + (rules[i].declarations[l]!==undefined?rules[i].declarations[l].property:''))); }

													// console.log(rules[i].declarations[l].value.indexOf('!important') !== -1)
													// console.log(rules[i].declarations[l].value)
													// console.log(rules[i].declarations[l+1].value)

													//prioritises !important declarations
													if (rules[i].declarations[l].value.indexOf('!important') !== -1) {
														
														summary.duplicate_declarations.push(rules[i].declarations[l+1]);
														summary.stats.summary.noDuplicateDeclarations += 1;
														rules[i].declarations.splice(l+1, 1);

													} else {

														summary.duplicate_declarations.push(rules[i].declarations[l]);
														summary.stats.summary.noDuplicateDeclarations += 1;
														rules[i].declarations.splice(l, 1);
													}

													l-=1;
													dCount-=1;
													declarationsNameCounts[key] -= 1;
												}
											}
										}
									}
								}
							}
						}
					} //end of reduce root declarations by property name

				} //end of rule check



				//reduce root declarations by selector
				selectorPropertiesList = [];
				declarationsCounts = [];
				for (k = 0; k < reduceRulesListSelectorCount; ++k) {

					if (rules[i] !== undefined 
						&& rules[i].type == 'rule'
					) {

						if (rules[i].selectors !== undefined && rules[i].selectors.toString() === reduceRulesListSelector[k]) {
						
							dCount = rules[i].declarations.length;

							//detect declarations duplicates
							for (l = 0; l < dCount; ++l) {
								if (rules[i].declarations[l].type == 'declaration'
								) {
									if (declarationsCounts[rules[i].declarations[l].property] !== undefined) {
										declarationsCounts[rules[i].declarations[l].property] += 1;
									} else {
										declarationsCounts[rules[i].declarations[l].property] = 1;
									}
								}
							} //end of declarations duplicate check

							// declarations reduction
							for (key in declarationsCounts) {
					      if (declarationsCounts.hasOwnProperty(key)) {

									if (declarationsCounts[key] > 1) {

										for (l = 0; l < dCount; ++l) {
											if (rules[i].declarations[l].type == 'declaration') {

												selectorPropertiesList = reduceRulesListSelectorPName[reduceRulesListSelector[k]];
												
												if (selectorPropertiesList !== undefined) { //specific in selector

													if (rules[i].declarations[l].property == key 
														&& (selectorPropertiesList.indexOf(rules[i].declarations[l].property) != -1)
														&& declarationsCounts[key] > 1) { //leave behind 1

														//remove previous comment above declaration to be removed
														if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
															if (rules[i].declarations[l-1] !== undefined && rules[i].declarations[l-1].type == 'comment') {

																rules[i].declarations.splice(l-1, 1);
																l-=1;
																dCount-=1;
															}
														}

														if (OPTIONS.verbose) { console.log(success('Process - Declaration - Group Duplicate Declarations : ' + (rules[i].selectors ? rules[i].selectors.join(', ') : '') + ' - ' + (rules[i].declarations[l]!==undefined?rules[i].declarations[l].property:''))); }
														summary.duplicate_declarations.push(rules[i].declarations[l]);
														summary.stats.summary.noDuplicateDeclarations += 1;
														rules[i].declarations.splice(l, 1);
														l-=1;
														dCount-=1;
														declarationsCounts[key] -= 1;
													}

												} else { //all in selector

													if (rules[i].declarations[l].property == key 
														&& declarationsCounts[key] > 1) { //leave behind 1

														//remove previous comment above declaration to be removed
														if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
															if (rules[i].declarations[l-1] !== undefined && rules[i].declarations[l-1].type == 'comment') {

																rules[i].declarations.splice(l-1, 1);
																l-=1;
																dCount-=1;
															}
														}

														if (OPTIONS.verbose) { console.log(success('Process - Declaration - Group Duplicate Declarations : ' + (rules[i].selectors ? rules[i].selectors.join(', ') : '') + ' - ' + (rules[i].declarations[l]!==undefined?rules[i].declarations[l].property:''))); }
														summary.duplicate_declarations.push(rules[i].declarations[l]);
														summary.stats.summary.noDuplicateDeclarations += 1;
														rules[i].declarations.splice(l, 1);
														l-=1;
														dCount-=1;
														declarationsCounts[key] -= 1;
													}
												}
											}
										}
									}

					      }
					    } //end of declarations reduction

						} //end of if
					} //end of if				
				} //end of reduce root declarations by selector

				////end of declarations




				////empty nodes
				//remove empty @sign keyframes
				if (rules[i] != undefined && rules[i].keyframes !== undefined && rules[i].keyframes.length == 0) {

					//remove previous comment in root
					if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
						if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {
							if (OPTIONS.verbose) { console.log(info('Process - @keyframes - Remove comment : ' + (rules[i].keyframes ? rules[i].keyframes.join(', ') : ''))); }
							rules.splice(i-1, 1);
							i-=1;
							rCount-=1;
						}
					}
					
					if (OPTIONS.verbose) { console.log(info('Process - @keyframes - Remove Empty Rule : ' + (rules[i].keyframes ? rules[i].keyframes.join(', ') : ''))); }

					rules.splice(i, 1);
					i-=1;
					rCount-=1;
				}

				//remove empty @sign media
				if (rules[i] !== undefined && rules[i].type == 'media' 
					&& rules[i].rules.length == 0) {

					//remove previous comment in root
					if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
						if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {
							if (OPTIONS.verbose) { console.log(info('Process - @media - Remove comment : ' + (rules[i].media ? rules[i].media : ''))); }
							rules.splice(i-1, 1);
							i-=1;
							rCount-=1;
						}
					}
					if (OPTIONS.verbose) { console.log(info('Process - @media - Remove Empty Rule : ' + (rules[i].media ? rules[i].media : ''))); }
					rules.splice(i, 1);
					i-=1;
					rCount-=1;
				}

				//remove empty @sign document
				if (rules[i] !== undefined && rules[i].type == 'document' 
					&& rules[i].rules.length == 0) {

					//remove previous comment in root
					if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
						if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {
							if (OPTIONS.verbose) { console.log(info('Process - @document - Remove comment : ' + (rules[i].document ? rules[i].document : ''))); }
							rules.splice(i-1, 1);
							i-=1;
							rCount-=1;
						}
					}

					if (OPTIONS.verbose) { console.log(info('Process - @document - Remove Empty Rule : ' + (rules[i].document ? rules[i].document : ''))); }
					rules.splice(i, 1);
					i-=1;
					rCount-=1;
				}

				//remove empty @sign supports
				if (rules[i] !== undefined && rules[i].type == 'supports' 
					&& rules[i].rules.length == 0) {

					//remove previous comment in root
					if (OPTIONS.trim_removed_rules_previous_comment || OPTIONS.trim) {
						if (rules[i-1] !== undefined && rules[i-1].type == 'comment') {
							if (OPTIONS.verbose) { console.log(info('Process - @supports - Remove comment : ' + (rules[i].supports ? rules[i].supports : ''))); }
							rules.splice(i-1, 1);
							i-=1;
							rCount-=1;
						}
					}

					if (OPTIONS.verbose) { console.log(info('Process - @supports - Remove Empty Rule : ' + (rules[i].supports ? rules[i].supports : ''))); }
					rules.splice(i, 1);
					i-=1;
					rCount-=1;
				}
				////end of empty nodes



			} //end of i

		} //end of undefined
	}
1198905
def pattern_convert(grammar, raw_node_info):
    """"""
    type, value, context, children = raw_node_info
    if children or type in grammar.number2symbol:
        return pytree.Node(type, children, context=context)
    else:
        return pytree.Leaf(type, value, context=context)
839336
def parse(self, generator):
        """"""
        gen = iter(generator)
        for line in gen:
            block = {}
            for rule in self.rules:
                if rule[0](line):
                    block = rule[1](line, gen)
                    break
            yield block
130646
def _generate_standard_transitions(cls):
        """"""
        allowed_transitions = cls.context.get_config('transitions', {})
        for key, transitions in allowed_transitions.items():
            key = cls.context.new_meta['translator'].translate(key)

            new_transitions = set()
            for trans in transitions:
                if not isinstance(trans, Enum):
                    trans = cls.context.new_meta['translator'].translate(trans)
                new_transitions.add(trans)

            cls.context.new_transitions[key] = new_transitions

        for state in cls.context.states_enum:
            if state not in cls.context.new_transitions:
                cls.context.new_transitions[state] = set()
1327709
def to_pb(self):
        
        union = table_v2_pb2.GcRule.Union(rules=[rule.to_pb() for rule in self.rules])
        return table_v2_pb2.GcRule(union=union)
1277643
def convert_requirements(requirements):
    """"""
    for req in requirements:
        parsed_requirement = pkg_resources.Requirement.parse(req)
        spec = requires_to_requires_dist(parsed_requirement)
        extras = ",".join(parsed_requirement.extras)
        if extras:
            extras = "[%s]" % extras
        yield (parsed_requirement.project_name + extras + spec)
94383
def _set_rules(self, rules: dict, overwrite=True):
        """"""

        if not isinstance(rules, dict):
            raise TypeError('rules must be an instance of dict or Rules,'
                            'got %r instead' % type(rules))

        if overwrite:
            self.rules = Rules(rules, self.default_rule)
        else:
            self.rules.update(rules)
1151567
def translate(patterns, *, flags=0):
    """"""

    flags = _flag_transform(flags)
    return _wcparse.translate(_wcparse.split(patterns, flags), flags)
1005134
def prepare_rules(self, attributes = [], ip_ranges = [], params = {}):
        
        for filename in self.rule_definitions:
            if filename in self.rules:
                for rule in self.rules[filename]:
                    rule.set_definition(self.rule_definitions, attributes, ip_ranges, params)
            else:
                self.rules[filename] = []
                new_rule = Rule(filename, self.rule_type, {'enabled': False, 'level': 'danger'})
                new_rule.set_definition(self.rule_definitions, attributes, ip_ranges, params)
                self.rules[filename].append(new_rule)
1336916
def _compile_rules(self):
        """"""
        for state, table in self.RULES.items():
            patterns = list()
            actions = list()
            nextstates = list()
            for i, row in enumerate(table):
                if len(row) == 2:
                    pattern, _action = row
                    nextstate = None
                elif len(row) == 3:
                    pattern, _action, nextstate = row
                else:
                    fstr = "invalid RULES: state {}, row {}"
                    raise CompileError(fstr.format(state, i))
                patterns.append(pattern)
                actions.append(_action)
                nextstates.append(nextstate)
            reobj = re.compile('|'.join("(" + p + ")" for p in patterns))
            self._rules[state] = (reobj, actions, nextstates)
312663
def process(self, rules, uio, prevxn=None):
        """"""
        self.apply_outcomes(self.match_rules(rules), uio, prevxn=prevxn)
731366
function prepareRules(options, rules, defaultDir) {
  rules = u.findRules(options, rules, defaultDir);
  var anyStartRules = [];
  var anyEndRules = [];
  var typeToRules = {'': anyStartRules, 'end': anyEndRules};

  rules.forEach(function (rule) {
    var ruleTypes = rule.type || [];
    ruleTypes = Array.isArray(ruleTypes) ? ruleTypes : [ruleTypes];
    if (ruleTypes.length === 0) {
      ruleTypes.push('');
    }
    ruleTypes.forEach(function (ruleType) {
      if (ruleType === '') {
        anyStartRules.push(rule);
        // add this any rule to the end of any typed start rule lists
        Object.keys(typeToRules).forEach(function (key) {
          if (key !== '' && key !== 'end' && key.substring(0,4) !== 'end-') {
            typeToRules[key].push(rule);
          }
        });
      } else if (ruleType === 'end') {
        anyEndRules.push(rule);
        // add this any rule to the end of any typed end rule lists
        Object.keys(typeToRules).forEach(function (key) {
          if (key !== '' && key.substring(0,4) === 'end-') {
            typeToRules[key].push(rule);
          }
        });
      } else {
        if (!(ruleType in typeToRules)) {
          typeToRules[ruleType] = [];
          if (ruleType.substring(0,4) !== 'end-') {
            // put all preceding any start rules first
            typeToRules[ruleType] = [].concat(anyStartRules);
          } else {
            // put all preceding any end rules first
            typeToRules[ruleType] = [].concat(anyEndRules);
          }
        }
        typeToRules[ruleType].push(rule);
      }
    });
  });

  return typeToRules;
}
142574
private function process()
    {
        $inputs = $this->inputs;
        $rules = $this->rules;
        $attributes = $this->attributes;
        $filters = $this->filters;
        $messages = $this->messages;

        foreach ($rules as $name => $rule) {
            // Check for a subrule syntax: rule[key].
            if (preg_match('/(.+)'.preg_quote($this->delimiters[0]).'(.+)'.preg_quote($this->delimiters[1]).'/', $name, $matches)) {
                $realName = $matches[1];
                $subName = $matches[2];

                if (! isset($inputs[$realName]) or ! is_array($inputs[$realName])) continue;

                // An all modifier is found: rule[*].
                if ($subName == '*') {
                    $subInputs = $inputs[$realName];

                    foreach ($subInputs as $subKey => $subValue) {
                        $inputs[$realName.'_'.$subKey] = $subValue;

                        $rules = $this->fixRules($rules, $rule, $name, $realName, $subKey);
                        $messages = $this->fixMessages($messages, $name, $realName, $subKey);

                        if (isset($attributes[$name])) {
                            $attributes = $this->fixRules($attributes, $attributes[$name], $name, $realName, $subKey);
                        }

                        if (isset($filters[$name])) {
                            $filters = $this->fixRules($filters, $filters[$name], $name, $realName, $subKey);
                        }
                    }

                    $messages = $this->removeMessage($messages);

                    unset($inputs[$realName]);
                    unset($rules[$name]);

                    if (isset($attributes[$name])) {
                        unset($attributes[$name]);
                    }

                    if (isset($filters[$name])) {
                        unset($filters[$name]);
                    }
                }
                // A specific subrule is found.
                elseif (isset($inputs[$realName][$subName])) {
                    $rules[$realName.'_'.$subName] = $rule;
                    $inputs[$realName.'_'.$subName] = $inputs[$realName][$subName];
                    $rules = $this->fixRules($rules, $rule, $name, $realName, $subName);

                    if (isset($attributes[$name])) {
                        $attributes = $this->fixRules($attributes, $attributes[$name], $name, $realName, $subName);
                        unset($attributes[$name]);
                    }

                    if (isset($filters[$name])) {
                        $filters = $this->fixRules($filters, $filters[$name], $name, $realName, $subName);
                        unset($filters[$name]);
                    }

                    unset($rules[$name]);
                    unset($inputs[$realName][$subName]);

                    if (! count($inputs[$realName])) {
                        unset($inputs[$realName]);
                    }

                    $messages = $this->fixMessages($messages, $name, $realName, $subName);
                    $messages = $this->removeMessage($messages);
                }
            }
        }

        $this->inputs = $inputs;
        $this->rules = $rules;
        $this->attributes = $attributes;
        $this->filters = $filters;
        $this->messages = $messages;
    }