Ejemplo n.º 1
0
def get_facade():
    if not Facade.was_instantiated():
        facade = \
            Facade(
                "tests/unit-testing/cli/interactive_commands/toilets.chatette",
                "tests/unit-testing/cli/interactive_commands/", None, False,
                None
            )
        facade.run_parsing()
    return Facade.get_or_create()
Ejemplo n.º 2
0
    def _add_rule(self, unit_type, unit_name, variation_name, rule_str):
        parser = Facade.get_or_create().parser
        rule_tokens = parser.lexer.lex("\t" + rule_str)
        rule = parser._parse_rule(rule_tokens[1:])

        unit = AST.get_or_create()[unit_type][unit_name]
        unit.add_rule(rule, variation_name)

        self.print_wrapper.write(
            "Rule successfully added to " + unit_type.name + " '" + \
            unit_name + "'."
        )
Ejemplo n.º 3
0
    def execute(self):
        """
        Implements the command `parse`,
        parsing a new template file using the current parser.
        """
        if len(self.command_tokens) <= 1:
            self.print_wrapper.error_log("Missing template file path\nUsage: " +
                                         "'parse <file_path>'")
            return
        file_path = self.command_tokens[1]

        if Facade.was_instantiated():
            facade = Facade.get_or_create()
            facade.parse_file(file_path)
        else:
            facade = Facade(file_path)
            facade.run_parsing()
Ejemplo n.º 4
0
def new_facade():
    if Facade.was_instantiated():
        print("reset facade")
        facade = \
            Facade.reset_system(
                "tests/unit-testing/cli/interactive_commands/toilets.chatette",
                "tests/unit-testing/cli/interactive_commands/", None, False,
                None
            )
    else:
        print("new facade")
        facade = \
            Facade(
                "tests/unit-testing/cli/interactive_commands/toilets.chatette",
                "tests/unit-testing/cli/interactive_commands/", None, False,
                None
            )
    facade.run_parsing()
    return Facade.get_or_create()
Ejemplo n.º 5
0
def generate(file):
    facade = Facade.get_or_create(directory_chatette + '/' + file,
                                  directory_chatette + '/output',
                                  adapter_str="rasa")
    facade.run()
Ejemplo n.º 6
0
    def execute(self):
        """
        Implements the command `generate` which generates all possible examples
        of a certain unit, formatted according to a certain adapter.
        """
        if not Facade.was_instantiated():
            self.print_wrapper.error_log(
                "Cannot generate anything. No file was parsed.")
            return
        facade = Facade.get_or_create()
        if len(self.command_tokens) == 1:
            facade.run_generation()
            return
        if len(self.command_tokens) == 2:
            try:
                facade.run_generation(self.command_tokens[1])
            except ValueError:
                self.print_wrapper.write("Unknown adapter: '" +
                                         self.command_tokens[1] + "'")
            return
        if len(self.command_tokens) < 4:
            self.print_wrapper.error_log("Missing some arguments\nUsage: " +
                                         self.usage_str)
            return

        adapter_str = self.command_tokens[1]
        try:
            adapter = create_adapter(adapter_str)
        except ValueError:
            self.print_wrapper.error_log("Unknown adapter '" + adapter_str +
                                         "'.")

        if len(self.command_tokens) == 5:
            try:
                self.nb_examples = int(self.command_tokens[-1])
            except ValueError:
                self.print_wrapper.error_log(
                    "The number of examples to be generated is invalid: " + \
                    "it must be an integer (no other characters allowed)."
                )
                return

        unit_type = \
            CommandStrategy.get_unit_type_from_str(self.command_tokens[2])
        if unit_type is None:
            self.print_wrapper.error_log("Unknown unit type: '" +
                                         str(self.command_tokens[2]) + "'.")
            return

        unit_regex = self.get_regex_name(self.command_tokens[3])
        if unit_regex is None:
            print("no regex")
            try:
                [unit_name, variation_name] = \
                    CommandStrategy.split_exact_unit_name(
                        self.command_tokens[3]
                    )
            except SyntaxError:
                self.print_wrapper.error_log(
                    "Unit identifier couldn't be interpreted. " + \
                    "Did you mean to escape some hashtags '#'?"
                )
                return
            self._generate_unit(adapter, unit_type, unit_name, variation_name)
        else:
            count = 0
            for unit_name in self.next_matching_unit_name(
                    unit_type, unit_regex):
                self._generate_unit(adapter, unit_type, unit_name)
                count += 1
            if count == 0:
                self.print_wrapper.write("No " + unit_type.name + " matched.")
        self.finish_execution()