def __init__(self, name=None, zero=False, default=None): name = str(name) int_name = "_Number_int_" + name if zero: int_min = 0 else: int_min = 1 single = Integer(None, int_min, self._int_max) ser_name = "_Number_ser_" + name item = Integer(None, 0, 100) if zero: series = Repetition(item, 1, self._ser_len) else: first = Integer(None, 1, 100) repetition = Repetition(item, 0, self._ser_len - 1) series = Sequence([first, repetition]) children = [single, series] Alternative.__init__(self, children, name=name, default=default)
class Year(Alternative): alts = [ IntegerRef("year", 2000, 2100), Compound( spec="<century> <year>", extras=[Integer("century", 20, 21), IntegerRef("year", 10, 100)], value_func=lambda n, e: e["century"] * 100 + e["year"]), Compound( spec="<century> <year>", extras=[Integer("century", 19, 20), IntegerRef("year", 1, 100)], value_func=lambda n, e: e["century"] * 100 + e["year"]), ] def __init__(self, name): Alternative.__init__(self, name=name, children=self.alts)
def __init__(self, name, min, max, default=None): content = language.ShortIntegerContent content.builders[1] = MapIntBuilder({ "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9, }) element = Integer(None, min, max, content=content) RuleWrap.__init__(self, name, element, default=default)
class MilitaryTime(Compound): spec = "<hour> (hundred | (oh | zero) <min_1_10> | <min_10_60>)" extras = [ Integer("hour", 0, 25), IntegerRef("min_1_10", 1, 10), IntegerRef("min_10_60", 10, 60), ] def __init__(self, name): Compound.__init__(self, name=name, spec=self.spec, extras=self.extras) def value(self, node): hour = node.get_child_by_name("hour").value() if node.has_child_with_name("min_1_10"): minute = node.get_child_by_name("min_1_10").value() elif node.has_child_with_name("min_10_60"): minute = node.get_child_by_name("min_10_60").value() else: minute = 0 return time(hour, minute)
def _build_element(self): return Integer(content=IntegerContent, min=0, max=10**12 - 1)
def _build_element(self): from dragonfly.language.en.number import IntegerContent return Integer(content=IntegerContent, min=3, max=14)
def _build_element(self): from dragonfly.language.en.short_number import ShortIntegerContent return Integer(content=ShortIntegerContent, min=0, max=10000)
def _build_element(self): return Integer(content=IntegerContent, min=23, max=47)
def __init__(self, name, min, max, default=None): element = Integer(None, min, max, content=IntegerContent) RuleWrap.__init__(self, name, element, default=default)