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()))
Esempio n. 2
0
 def test_success(self, _, entries, expected_pbtxt):
     actual = parser.parse(entries)
     expected = rule_pb2.RewriteRuleSet()
     text_format.Parse(expected_pbtxt, expected)
     self.assertEqual(expected, actual)