def _create_repeat_rule(self, merge_rule): merge_rule = merge_rule.prepare_for_merger() alts = [RuleRef(rule=merge_rule) ] # +[RuleRef(rule=sm) for sm in selfmod] single_action = Alternative(alts) sequence = Repetition(single_action, min=1, max=self._max_repetitions, name=CCRMerger2._SEQ) original = Alternative(alts, name=CCRMerger2._ORIGINAL) terminal = Alternative(alts, name=CCRMerger2._TERMINAL) class RepeatRule(CompoundRule): spec = "[<" + CCRMerger2._ORIGINAL + "> original] " + \ "[<" + CCRMerger2._SEQ + ">] " + \ "[terminal <" + CCRMerger2._TERMINAL + ">]" extras = [sequence, original, terminal] def _process_recognition(self, node, extras): _original = extras[ CCRMerger2. _ORIGINAL] if CCRMerger2._ORIGINAL in extras else None _sequence = extras[ CCRMerger2._SEQ] if CCRMerger2._SEQ in extras else None _terminal = extras[ CCRMerger2. _TERMINAL] if CCRMerger2._TERMINAL in extras else None if _original is not None: _original.execute() if _sequence is not None: for action in _sequence: action.execute() if _terminal is not None: _terminal.execute() return RepeatRule(name=self._get_new_rule_name())
def _create_repeat_rule(self, rule): SEQ = "caster_base_sequence" alts = [RuleRef(rule=rule)] single_action = Alternative(alts) max = CCRMerger.MAX_REPETITIONS class RepeatRule(CompoundRule): spec = "<%s>" % SEQ extras = [Repetition(single_action, min=1, max=max, name=SEQ)] def _process_recognition(self, node, extras): for action in extras[SEQ]: action.execute() return RepeatRule(name="Repeater" + MergeRule.get_merge_name())
def _create_nested_rule(self, rule): alts = [RuleRef(rule=rule)] #+[RuleRef(rule=sm) for sm in selfmod] single_action = Alternative(alts) bef = Repetition(single_action, min=1, max=8, name="before") aft = Repetition(single_action, min=1, max=8, name="after") seq1 = Repetition(single_action, min=1, max=6, name="sequence1") seq2 = Repetition(single_action, min=1, max=6, name="sequence2") sing1 = Alternative(alts, name="singleton1") sing2 = Alternative(alts, name="singleton2") if rule.nested.extras is None: rule.nested.extras = [bef, aft, seq1, seq2, sing1, sing2] else: rule.nested.extras.extend([bef, aft, seq1, seq2, sing1, sing2]) nested = rule.nested() return nested
def _create_repeat_rule(self, rule): ORIGINAL, SEQ, TERMINAL = "original", "caster_base_sequence", "terminal" alts = [RuleRef(rule=rule)] #+[RuleRef(rule=sm) for sm in selfmod] single_action = Alternative(alts) max = SETTINGS["max_ccr_repetitions"] sequence = Repetition(single_action, min=1, max=max, name=SEQ) original = Alternative(alts, name=ORIGINAL) terminal = Alternative(alts, name=TERMINAL) class RepeatRule(CompoundRule): spec = "[<" + ORIGINAL + "> original] [<" + SEQ + ">] [terminal <" + TERMINAL + ">]" extras = [sequence, original, terminal] def _process_recognition(self, node, extras): original = extras[ORIGINAL] if ORIGINAL in extras else None sequence = extras[SEQ] if SEQ in extras else None terminal = extras[TERMINAL] if TERMINAL in extras else None if original is not None: original.execute() if sequence is not None: for action in sequence: action.execute() if terminal is not None: terminal.execute() rules = [] rules.append(RepeatRule(name="Repeater" + MergeRule.get_merge_name())) if rule.nested is not None: bef = Repetition(single_action, min=1, max=8, name="before") aft = Repetition(single_action, min=1, max=8, name="after") seq1 = Repetition(single_action, min=1, max=6, name="sequence1") seq2 = Repetition(single_action, min=1, max=6, name="sequence2") sing1 = Alternative(alts, name="singleton1") sing2 = Alternative(alts, name="singleton2") if rule.nested.extras is None: rule.nested.extras = [bef, aft, seq1, seq2, sing1, sing2] else: rule.nested.extras.extend([bef, aft, seq1, seq2, sing1, sing2]) nested = rule.nested() rules.append(nested) return rules
def _create_repeat_rule(self, rule): ORIGINAL, SEQ, TERMINAL = "original", "caster_base_sequence", "terminal" alts = [RuleRef(rule=rule)]#+[RuleRef(rule=sm) for sm in selfmod] single_action = Alternative(alts) max = settings.SETTINGS["miscellaneous"]["max_ccr_repetitions"] sequence = Repetition(single_action, min=1, max=max, name=SEQ) original = Alternative(alts, name=ORIGINAL) terminal = Alternative(alts, name=TERMINAL) class RepeatRule(CompoundRule): spec = "[<"+ORIGINAL+"> original] [<" + SEQ + ">] [terminal <"+TERMINAL+">]" extras = [ sequence, original, terminal ] def _process_recognition(self, node, extras): original = extras[ORIGINAL] if ORIGINAL in extras else None sequence = extras[SEQ] if SEQ in extras else None terminal = extras[TERMINAL] if TERMINAL in extras else None if original is not None: original.execute() if sequence is not None: for action in sequence: action.execute() if terminal is not None: terminal.execute() return RepeatRule(name="Repeater"+MergeRule.get_merge_name())