def _read_rule_set(path: str) -> RewriteRule:
    logging.info("reading rewrite rules from %r", path)
    entries = lexicon_reader.read_lexicon_entries(path)  # might throw IOError.

    for index, entry in entries.items():
      try:
        lexicon_validator.validate(entry)
      except lexicon_validator.InvalidLexiconEntryError as error:
        raise MorphotacticsCompilerError(
            f"Lexicon entry at line {index} of '{path}' is illformed. {error}")

    return lexicon_parser.parse(list(entries.values()))
예제 #2
0
 def test_success(self, _, basename, expected):
   path = os.path.join(_TESTDATA_DIR, f"{basename}.tsv")
   actual = reader.read_lexicon_entries(path)
   self.assertDictEqual(expected, actual)
예제 #3
0
 def test_raises_exception(self, _, path, exception):
   with self.assertRaises(exception):
     reader.read_lexicon_entries(path)