diff --git a/CHANGELOG.md b/CHANGELOG.md index e2f10d2a..72d2d0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed +- Parser opened file upon being created rather than when starting to parse, leading to parsing of the same file several types after resetting the system (issue [#28](https://github.com/SimGus/Chatette/issues/28)) - One escapable character was missing, leading to escape character not being removed for `]` (issue [#27](https://github.com/SimGus/Chatette/issues/27)) ## [1.6.1] - 2019-11-11 diff --git a/TODOs.md b/TODOs.md index 76920ed7..fefde5d5 100644 --- a/TODOs.md +++ b/TODOs.md @@ -75,6 +75,7 @@ - [ ] replace `print` by `six.print_`? - [ ] add more unit tests +- [ ] refactor facade (and its interactions with parser, generator and adapter) ### Improve performance - [ ] cache the possible number of generatable examples for each unit diff --git a/chatette/facade.py b/chatette/facade.py index e8a6c5e3..1892ef11 100644 --- a/chatette/facade.py +++ b/chatette/facade.py @@ -33,6 +33,7 @@ def __init__(self, master_file_path, output_dir_path=None, adapter_str="rasa", base_filepath=None, local=False, seed=None, force_overwriting=False ): + self.master_file_path = master_file_path if local: self.output_dir_path = os.path.dirname(master_file_path) else: @@ -57,7 +58,7 @@ def __init__(self, adapter_str, base_filepath ) - self.parser = Parser(master_file_path) + self.parser = Parser() self.generator = None @classmethod @@ -91,14 +92,13 @@ def run(self): def run_parsing(self): """Executes the parsing alone.""" - self.parser.parse() + self.parser.parse_file(self.master_file_path) def parse_file(self, file_path): """ Parses the new template file at `file_path` with the current parser. """ - self.parser.open_new_file(file_path) - self.parser.parse() + self.parser.parse_file(file_path) def run_generation(self, adapter_str=None): """" diff --git a/chatette/parsing/parser.py b/chatette/parsing/parser.py index 86fe13b1..e2563bdf 100644 --- a/chatette/parsing/parser.py +++ b/chatette/parsing/parser.py @@ -35,7 +35,7 @@ class Parser(object): - def __init__(self, master_file_path): + def __init__(self, master_file_path=None): if ( master_file_path is not None and not isinstance(master_file_path, string_types) @@ -47,7 +47,7 @@ def __init__(self, master_file_path): self._master_filepath = master_file_path self.input_file_manager = \ - InputFileManager.get_or_create(master_file_path) + InputFileManager.get_or_create() self.lexer = Lexer() self.ast = AST.get_or_create() @@ -77,12 +77,14 @@ def open_new_file(self, filepath): print_warn(err_msg) - def parse(self): + def parse_file(self, file_path): """ - Parses the template file(s) and translates them into an AST. + Parses the template file(s) at `file_path` + and translates them into an AST. """ + self.open_new_file(file_path) print_DBG( - "Parsing master file: " + \ + "Parsing file: " + \ self.input_file_manager.get_current_file_name() ) diff --git a/tests/system-testing/test_system.py b/tests/system-testing/test_system.py index c01bf2b5..5a25eefb 100644 --- a/tests/system-testing/test_system.py +++ b/tests/system-testing/test_system.py @@ -43,8 +43,8 @@ def get_or_create(): def run(self, template_filepath): AST.reset_instance() - parser = Parser(template_filepath) - parser.parse() + parser = Parser() + parser.parse_file(template_filepath) self.generator = Generator() self.train_examples = list(self.generator.generate_train())