def run_generation(self, adapter_str=None): """" Runs the generation of all intents and writes them out to the output file(s) using the adapter `adapter` if one is provided. @pre: the parsing has been done. """ if adapter_str is None: adapter = self.adapter else: adapter = adapter_factory.create_adapter(adapter_str) self.generator = Generator() synonyms = AST.get_or_create().get_entities_synonyms() if os.path.exists(self.output_dir_path): if self.force_overwriting or self._ask_confirmation(): shutil.rmtree(self.output_dir_path) else: print_DBG("Aborting generation. Exiting without any change.") return train_examples = list(self.generator.generate_train()) if train_examples: adapter.write(os.path.join(self.output_dir_path, "train"), train_examples, synonyms) test_examples = list(self.generator.generate_test(train_examples)) if test_examples: adapter.write(os.path.join(self.output_dir_path, "test"), test_examples, synonyms) print_DBG("Generation over")
def run(self, template_filepath): parser = Parser(template_filepath) parser.parse() self.generator = Generator(parser) self.train_examples = list(self.generator.generate_train()) self.test_examples = list(self.generator.generate_test())
def run_generation(self, adapter_str=None): """" Runs the generation of all intents and writes them out to the output file(s) using the adapter `adapter` if one is provided. @pre: the parsing has been done. """ if adapter_str is None: adapter = self.adapter else: adapter = adapter_factory.create_adapter(adapter_str) self.generator = Generator(self.parser) synonyms = self.generator.get_entities_synonyms() if os.path.exists(self.output_dir_path): shutil.rmtree(self.output_dir_path) train_examples = list(self.generator.generate_train()) if train_examples: adapter.write(os.path.join(self.output_dir_path, "train"), train_examples, synonyms) test_examples = list(self.generator.generate_test(train_examples)) if test_examples: adapter.write(os.path.join(self.output_dir_path, "test"), test_examples, synonyms) print_DBG("Generation over")
def run(self, template_filepath): with io.open(template_filepath, 'r') as in_file: parser = Parser(in_file) parser.parse() self.generator = Generator(parser) self.train_examples = list(self.generator.generate_train()) self.test_examples = list(self.generator.generate_test())
def run(self, template_filepath): AST.reset_instance() parser = Parser(template_filepath) parser.parse() self.generator = Generator() self.train_examples = list(self.generator.generate_train()) self.test_examples = list(self.generator.generate_test())
def main(): argument_parser = argparse.ArgumentParser( description="Generates Rasa NLU datasets from a template file", add_help=True) argument_parser.add_argument("input", help="Path to template file", type=str) argument_parser.add_argument("-o", "--out", dest="output", required=False, help="Output file path", type=str, default=None) if len(sys.argv[1:]) == 0: argument_parser.print_help() argument_parser.exit() args = argument_parser.parse_args() template_file_path = args.input dir_path = os.path.dirname(template_file_path) output_filename = DEFAULT_OUTPUT_FILENAME if args.output: output_filename = args.output output_file_path = os.path.join(dir_path, output_filename) testing_filename = DEFAULT_TESTING_DATASET_FILENAME testing_file_path = os.path.join(dir_path, testing_filename) with io.open(template_file_path, 'r') as in_file: parser = Parser(in_file) parser.parse() # parser.printDBG() print("") generator = Generator(output_file_path, testing_file_path, parser) generator.generate()
def main(): # pylint: disable=bad-continuation argument_parser = argparse.ArgumentParser( description="Chatette v" + __version__ + " -- " + "Generates NLU datasets from template files", epilog="SimGus -- 2018 -- Released under MIT license", prog="Chatette", add_help=True) argument_parser.add_argument("input", type=str, help="Path to master template file") argument_parser.add_argument("-o", "--out", dest="output", required=False, type=str, default=None, help="Output directory path") argument_parser.add_argument("-s", "--seed", dest="seed", required=False, type=str, default=None, help="Seed for the random generator " + "(any string without spaces will work)") argument_parser.add_argument("-l", "--local", dest="local", required=False, action="store_true", default=False, help="Change the base directory for output " + "files from the current working directory " + "to the directory containing the template " + "file") argument_parser.add_argument("-a", "--adapter", dest="adapter", required=False, type=str, default="rasa", help="Write adapter. Possible values: " + "['rasa', 'jsonl']") argument_parser.add_argument("-v", "--version", action="version", version="%(prog)s v" + __version__, help="Print the version number of the module") if len(sys.argv[1:]) == 0: argument_parser.print_help() argument_parser.exit() args = argument_parser.parse_args() template_file_path = args.input if args.local: dir_path = os.path.dirname(template_file_path) else: dir_path = os.getcwd() if args.output is None: dir_path = os.path.join(dir_path, "output") else: dir_path = os.path.join(dir_path, args.output) # Initialize the random number generator if args.seed is not None: random_seed(args.seed) with io.open(template_file_path, 'r') as in_file: parser = Parser(in_file) parser.parse() # parser.print_DBG() if args.adapter == 'rasa': # pylint: disable=redefined-variable-type adapter = RasaAdapter() elif args.adapter == 'jsonl': # pylint: disable=redefined-variable-type adapter = JsonListAdapter() else: raise ValueError("Unknown adapter was selected") generator = Generator(parser) synonyms = generator.get_entities_synonyms() train_examples = list(generator.generate_train()) if train_examples: adapter.write(os.path.join(dir_path, "train"), train_examples, synonyms) test_examples = list(generator.generate_test(train_examples)) if test_examples: adapter.write(os.path.join(dir_path, "test"), test_examples, synonyms) print_DBG("Generation over")