Example #1
0
def receive_input():
    global app, smart_home
    expression_ast = ast_bld.build(start=lxr.GrammarVariable.EXPRESSION.value)
    user_input = app.stringBox('Atentu', 'Mi atentas')
    _, parsed_input = expression_ast.parse(user_input).evaluate(smart_home)
    smart_home.set_return_value(
        parsed_input if parsed_input is not None else user_input)
Example #2
0
 def ast(self):
     return ast_bld.build(start=domsagxo.compilation.definitions.
                          GrammarVariable.PROGRAM.value)
Example #3
0
def build_house(clock_type=ClockType.REAL, house_type=HouseType.HOUSE):
    global ast, smart_home, app
    lxr.build()
    ast = ast_bld.build()
    if clock_type is ClockType.REAL:
        smart_home = Domsagxo()
        smart_home.start_scheduler()
    else:
        simulative_time = MockClock()
        scheduler = Horaro(time_function=simulative_time.get_current_time,
                           delay_function=simulative_time.increase_time)
        smart_home = Domsagxo(scheduler)
    smart_home.method_dict['haltu'] = smart_home.scheduler.runSetTime
    smart_home.method_dict['anoncu'] = announce_in_multimedia
    smart_home.method_dict['atentu'] = receive_input
    with gui("virtuala domo", showIcon=False) as app:
        app.addLabel("title", "Welcome to Domsagxo", colspan=2)
        app.setLabelBg("title", "green")
        create_clock("horaro", 0, 2)

        if house_type is HouseType.HOUSE:
            with app.labelFrame("Enirejo", 1, 2, 1):
                create_door("antauxa pordo", 0, 0)
                create_efficient_bulb("enirlumo", 1, 0)
            with app.labelFrame("Koridoro", 1, 0, 2):
                create_efficient_bulb("koridora lumo")
                create_speaker("parolilo", 0, 1)
            with app.labelFrame("Oficejo", 2, 2, 1, 1):
                create_efficient_bulb("laborlampo")
                create_air_conditioner("ofica klimatizilo", 1, 0)
            with app.labelFrame("Necesejo", 2):
                create_efficient_bulb("necesa lumo")
                create_boiler("doma kaldrono", 1, 0)
            with app.labelFrame("dormcxambro", 2, 1):
                create_efficient_bulb("dormlumo")
        else:
            with app.labelFrame("Koridoro", colspan=2):
                light_bulbs = []
                for i in range(100):
                    light_bulbs += [
                        create_efficient_bulb(f"{i + 1:03d}",
                                              row=int(i / 10),
                                              col=(i % 10))
                    ]
                smart_home.variables["ampoloj"] = light_bulbs
            with app.labelFrame("salono", row=2, colspan=2):
                smart_home.variables["sxambalulo"] = create_efficient_bulb(
                    "sxambalulo")

            def turn_light_on_if_prime(number):
                if is_prime(number):
                    smart_home.variables['sxambalulo'].turnOn()
                else:
                    smart_home.variables['sxambalulo'].turnOff()

            smart_home.method_dict['cxuprimu'] = turn_light_on_if_prime

        app.addLabel("l9", "speech:")
        app.addTextArea("Speech", row=3, column=1, colspan=2)

        app.addLabel("20", "reply:")
        app.addLabel("Reply", "Speech", row=4, column=1, colspan=2)

        app.addButton("Submit", execute_speech, row=5, column=1)
        app.addButton("Cancel", app.stop, row=5, column=2)
        app.enableEnter(execute_speech)
        app.bindKey("<Escape>", app.stop)
        app.setStopFunction(lambda: True
                            if smart_home.stop_scheduler() else True)
Example #4
0
        "PERIOD": '.',
        "DELIM": ',',
    }
    return name_to_token[
        token_name] if token_name in name_to_token else token_name


def convert_raw_token_to_tex(raw_token):
    actual_token = convert_name_to_token(raw_token[1:]).replace("_", " ")
    return ("\\term{" + actual_token +
            "}") if raw_token.startswith('T') else ("\\<" + actual_token + ">")


if __name__ == "__main__":
    print("building grammar")
    build(start=GrammarVariable.PROGRAM.value)

    parse_rules = {}

    print("parsing grammar rules")
    with open("esperanto/src/compilation/parser.out", 'r') as input_file:
        for line in input_file.readlines():
            if line.startswith("Rule "):
                line_parts = line.split()
                if line_parts[2].startswith("S'"):
                    continue
                lhs = convert_raw_token_to_tex(line_parts[2])
                rhs = [
                    convert_raw_token_to_tex(token) for token in line_parts[4:]
                ]
                if lhs not in parse_rules:
Example #5
0
 def relation_ast(self):
     return ast_bld.build(start=GrammarVariable.RELATION.value)
Example #6
0
 def esperantifier(self):
     return Esperantifier(Domsagxo(), ast.build())
Example #7
0
 def ast(self):
     return ast_bld.build()
Example #8
0
 def ast(self):
     return ast_bld.build(start=domsagxo.compilation.definitions.
                          GrammarVariable.ROUTINE_DEFINITION.value)