# Path: epitran/exceptions.py
# class DatafileError(Exception):
#     pass
# 
# class MappingError(Exception):
#     pass
# 
# Path: epitran/ligaturize.py
# def ligaturize(text):
#     """Convert text to employ non-standard ligatures
# 
#     Args:
#         text (unicode): IPA text to Convert
# 
#     Return:
#         unicode: non-standard IPA text with phonetic ligatures for affricates
#     """
#     mapping = [(u't͡s', u'ʦ'),
#                (u't͡ʃ', u'ʧ'),
#                (u't͡ɕ', u'ʨ'),
#                (u'd͡z', u'ʣ'),
#                (u'd͡ʒ', u'ʤ'),
#                (u'd͡ʑ', u'ʥ'),]
#     for from_, to_ in mapping:
#         text = text.replace(from_, to_)
#     return text
# 
# Path: epitran/ppprocessor.py
# class PrePostProcessor(object):
#     def __init__(self, code, fix, rev):
#         """Constructs a pre/post-processor for orthographic/IPA strings
# 
#         This class reads processor files consisting of context-sensitive rules
#         and compiles them into regular expression objects that can then be used
#         to perform regex replacements in cascades that capture feeding and
#         bleeding.
# 
#         Args:
#             code (str): ISO 639-3 code and ISO 15924 code joined with a hyphen
#             fix (str): 'pre' for preprocessors, 'post' for postprocessors
#             rev (boolean): True for reverse transliterating pre/post-processors
#         """
#         self.rules = self._read_rules(code, fix, rev)
# 
#     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([])
# 
#     def process(self, word):
#         """Apply processor to an input string
# 
#         Args:
#             word (unicode): input string (orthographic or IPA)
# 
#         Returns:
#             unicode: output string with all rules applied in order
#         """
#         return self.rules.apply(word)
# 
# Path: epitran/puncnorm.py
# class PuncNorm(object):
#     def __init__(self):
#         """Constructs a punctuation normalization object"""
#         self.puncnorm = self._load_punc_norm_map()
# 
#     def _load_punc_norm_map(self):
#         """Load the map table for normalizing 'down' punctuation."""
#         path = pkg_resources.resource_filename(__name__, 'data/puncnorm.csv')
#         with open(path, 'rb') as f:
#             reader = csv.reader(f, encoding='utf-8', delimiter=str(','), quotechar=str('"'))
#             next(reader)
#             return {punc: norm for (punc, norm) in reader}
# 
#     def norm(self, text):
#         """Apply punctuation normalization to a string of text
# 
#         Args:
#             text (unicode): text to normalize_punc
# 
#         Returns:
#             unicode: text with normalized punctuation
#         """
#         new_text = []
#         for c in text:
#             if c in self.puncnorm:
#                 new_text.append(self.puncnorm[c])
#             else:
#                 new_text.append(c)
#         return ''.join(new_text)
# 
#     def __iter__(self):
#         return iter(self.puncnorm)
# 
#     def __getitem__(self, key):
#         return self.puncnorm[key]
# 
# Path: epitran/stripdiacritics.py
# class StripDiacritics(object):
#     def __init__(self, code):
#         """Constructs object to strip specified diacritics from text
# 
#         Args:
#             code (str): ISO 639-3 code and ISO 15924 code joined with a hyphen
#         """
#         self.diacritics = self._read_diacritics(code)
# 
#     def _read_diacritics(self, code):
#         diacritics = []
#         fn = os.path.join('data', 'strip', code + '.csv')
#         try:
#             abs_fn = pkg_resources.resource_filename(__name__, fn)
#         except KeyError:
#             return []
#         if os.path.isfile(abs_fn):
#             with open(abs_fn, 'rb') as f:
#                 reader = csv.reader(f, encoding='utf-8')
#                 for [diacritic] in reader:
#                     diacritics.append(diacritic)
#         return diacritics
# 
#     def process(self, word):
#         """Remove diacritics from an input string
# 
#         Args:
#             word (unicode): Unicode IPA string
# 
#         Returns:
#             unicode: Unicode IPA string with specified diacritics
#             removed
#         """
#         # word = unicodedata.normalize('NFD', word)
#         word = ''.join(filter(lambda x: x not in self.diacritics, word))
#         # return unicodedata.normalize('NFC', word)
#         return word


import logging
import os.path
import sys
import unicodedata
import pkg_resources
import regex as re
import panphon
import unicodecsv as csv
from collections import defaultdict
from epitran.exceptions import DatafileError, MappingError
from epitran.ligaturize import ligaturize
from epitran.ppprocessor import PrePostProcessor
from epitran.puncnorm import PuncNorm
from epitran.stripdiacritics import StripDiacritics
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)





logger = logging.getLogger('epitran')


if sys.version_info[0] == 3:
    def unicode(x):

# Path: epitran/exceptions.py
# class DatafileError(Exception):
#     pass
# 
# class MappingError(Exception):
#     pass
# 
# Path: epitran/ligaturize.py
# def ligaturize(text):
#     """Convert text to employ non-standard ligatures
# 
#     Args:
#         text (unicode): IPA text to Convert
# 
#     Return:
#         unicode: non-standard IPA text with phonetic ligatures for affricates
#     """
#     mapping = [(u't͡s', u'ʦ'),
#                (u't͡ʃ', u'ʧ'),
#                (u't͡ɕ', u'ʨ'),
#                (u'd͡z', u'ʣ'),
#                (u'd͡ʒ', u'ʤ'),
#                (u'd͡ʑ', u'ʥ'),]
#     for from_, to_ in mapping:
#         text = text.replace(from_, to_)
#     return text
# 
# Path: epitran/ppprocessor.py
# class PrePostProcessor(object):
#     def __init__(self, code, fix, rev):
#         """Constructs a pre/post-processor for orthographic/IPA strings
# 
#         This class reads processor files consisting of context-sensitive rules
#         and compiles them into regular expression objects that can then be used
#         to perform regex replacements in cascades that capture feeding and
#         bleeding.
# 
#         Args:
#             code (str): ISO 639-3 code and ISO 15924 code joined with a hyphen
#             fix (str): 'pre' for preprocessors, 'post' for postprocessors
#             rev (boolean): True for reverse transliterating pre/post-processors
#         """
#         self.rules = self._read_rules(code, fix, rev)
# 
#     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([])
# 
#     def process(self, word):
#         """Apply processor to an input string
# 
#         Args:
#             word (unicode): input string (orthographic or IPA)
# 
#         Returns:
#             unicode: output string with all rules applied in order
#         """
#         return self.rules.apply(word)
# 
# Path: epitran/puncnorm.py
# class PuncNorm(object):
#     def __init__(self):
#         """Constructs a punctuation normalization object"""
#         self.puncnorm = self._load_punc_norm_map()
# 
#     def _load_punc_norm_map(self):
#         """Load the map table for normalizing 'down' punctuation."""
#         path = pkg_resources.resource_filename(__name__, 'data/puncnorm.csv')
#         with open(path, 'rb') as f:
#             reader = csv.reader(f, encoding='utf-8', delimiter=str(','), quotechar=str('"'))
#             next(reader)
#             return {punc: norm for (punc, norm) in reader}
# 
#     def norm(self, text):
#         """Apply punctuation normalization to a string of text
# 
#         Args:
#             text (unicode): text to normalize_punc
# 
#         Returns:
#             unicode: text with normalized punctuation
#         """
#         new_text = []
#         for c in text:
#             if c in self.puncnorm:
#                 new_text.append(self.puncnorm[c])
#             else:
#                 new_text.append(c)
#         return ''.join(new_text)
# 
#     def __iter__(self):
#         return iter(self.puncnorm)
# 
#     def __getitem__(self, key):
#         return self.puncnorm[key]
# 
# Path: epitran/stripdiacritics.py
# class StripDiacritics(object):
#     def __init__(self, code):
#         """Constructs object to strip specified diacritics from text
# 
#         Args:
#             code (str): ISO 639-3 code and ISO 15924 code joined with a hyphen
#         """
#         self.diacritics = self._read_diacritics(code)
# 
#     def _read_diacritics(self, code):
#         diacritics = []
#         fn = os.path.join('data', 'strip', code + '.csv')
#         try:
#             abs_fn = pkg_resources.resource_filename(__name__, fn)
#         except KeyError:
#             return []
#         if os.path.isfile(abs_fn):
#             with open(abs_fn, 'rb') as f:
#                 reader = csv.reader(f, encoding='utf-8')
#                 for [diacritic] in reader:
#                     diacritics.append(diacritic)
#         return diacritics
# 
#     def process(self, word):
#         """Remove diacritics from an input string
# 
#         Args:
#             word (unicode): Unicode IPA string
# 
#         Returns:
#             unicode: Unicode IPA string with specified diacritics
#             removed
#         """
#         # word = unicodedata.normalize('NFD', word)
#         word = ''.join(filter(lambda x: x not in self.diacritics, word))
#         # return unicodedata.normalize('NFC', word)
#         return word


# Path: epitran/simple.py
import logging
import os.path
import sys
import unicodedata
import pkg_resources
import regex as re
import panphon
import unicodecsv as csv
from collections import defaultdict
from epitran.exceptions import DatafileError, MappingError
from epitran.ligaturize import ligaturize
from epitran.ppprocessor import PrePostProcessor
from epitran.puncnorm import PuncNorm
from epitran.stripdiacritics import StripDiacritics

# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)





logger = logging.getLogger('epitran')


if sys.version_info[0] == 3:
    def unicode(x):

        return x