How to use the epitran.rules.Rules function in epitran

To help you get started, we’ve selected a few epitran examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmort27 / epitran / epitran / epihan.py View on Github external
def __init__(self, ligatures=False, cedict_file=None, rules_file='pinyin-to-ipa.txt'):
        """Construct epitran object for Traditional Chinese

        Args:
            ligatures (bool): if True, use ligatures instead of standard IPA
            cedict_file (str): path to CC-CEDict dictionary file
            rules_file (str): name of file with rules for converting pinyin to
                              IPA
        """
        if not cedict_file:
            raise MissingData('Please specify a location for the CC-CEDict file.')
        rules_file = os.path.join('data', 'rules', rules_file)
        rules_file = pkg_resources.resource_filename(__name__, rules_file)
        self.cedict = cedict.CEDictTrie(cedict_file, traditional=True)
        self.rules = rules.Rules([rules_file])
        self.regexp = re.compile(r'\p{Han}')
github dmort27 / epitran / epitran / ppprocessor.py View on Github external
def _read_rules(self, code, fix, rev):
        assert fix in ['pre', 'post']
        code += '_rev' if rev else ''
        fn = os.path.join('data', fix, code + '.txt')
        try:
            abs_fn = pkg_resources.resource_filename(__name__, fn)
        except KeyError:
            return Rules([])
        if os.path.isfile(abs_fn):
            return Rules([abs_fn])
        else:
            return Rules([])
github dmort27 / epitran / epitran / epihan.py View on Github external
"""Construct epitran object for Chinese

        Args:
            ligatures (bool): if True, use ligatures instead of standard IPA
            cedict_file (str): path to CC-CEDict dictionary file
            rules_file (str): name of file with rules for converting pinyin to
                              IPA
        """
        # If no cedict_file is specified, raise and error
        if not cedict_file:
            raise MissingData('Please specify a location ' +
                              'for the CC-CEDict file.')
        rules_file = os.path.join('data', 'rules', rules_file)
        rules_file = pkg_resources.resource_filename(__name__, rules_file)
        self.cedict = cedict.CEDictTrie(cedict_file)
        self.rules = rules.Rules([rules_file])
        self.regexp = re.compile(r'\p{Han}')
github dmort27 / epitran / epitran / ppprocessor.py View on Github external
def _read_rules(self, code, fix, rev):
        assert fix in ['pre', 'post']
        code += '_rev' if rev else ''
        fn = os.path.join('data', fix, code + '.txt')
        try:
            abs_fn = pkg_resources.resource_filename(__name__, fn)
        except KeyError:
            return Rules([])
        if os.path.isfile(abs_fn):
            return Rules([abs_fn])
        else:
            return Rules([])