# Path: shorttext/generators/charbase/char2vec.py
# def initSentenceToCharVecEncoder(textfile, encoding=None):
#     """ Instantiate a class of SentenceToCharVecEncoder from a text file.
# 
#     :param textfile: text file
#     :param encoding: encoding of the text file (Default: None)
#     :return: an instance of SentenceToCharVecEncoder
#     :type textfile: file
#     :type encoding: str
#     :rtype: SentenceToCharVecEncoder
#     """
#     dictionary = Dictionary(map(lambda line: [c for c in line], textfile_generator(textfile, encoding=encoding)))
#     return SentenceToCharVecEncoder(dictionary)
# 
# Path: shorttext/utils/classification_exceptions.py
# class OperationNotDefinedException(Exception):
#     def __init__(self, opname):
#         self.message = 'Operation '+opname+' not defined'


import re
import string
import numpy as np
from functools import reduce
from shorttext.generators.charbase.char2vec import initSentenceToCharVecEncoder
from shorttext.utils.classification_exceptions import OperationNotDefinedException
            if len(word) > 1:
                idx = np.random.randint(0, len(word))
                w = word[:idx] + word[(idx+1):]
            else:
                w = word
            bin_all = self.concatchar_encoder.encode_spelling(w).transpose()
        elif opt=='INSERT':
            ins_idx = np.random.randint(0, len(word)+1)
            ins_char = np.random.choice([c for c in string.ascii_lowercase])
            w = word[:ins_idx] + ins_char + word[ins_idx:]
            bin_all = self.concatchar_encoder.encode_spelling(w).transpose()
        elif opt=='REPLACE':
            rep_idx = np.random.randint(0, len(word))
            rep_char = np.random.choice([c for c in string.ascii_lowercase])
            w = word[:rep_idx] + rep_char + w[(rep_idx+1):]
            bin_all = self.concatchar_encoder.encode_spelling(w).transpose()
        else:
            raise OperationNotDefinedException('NOISE-'+opt)
        return np.array([ np.repeat(np.array([bin_all]), 3, axis=0).reshape((1, len(self.concatchar_encoder)*3))[0] ]).transpose(), w

    def jumble_char(self, word, opt, unchanged=False):
        if opt=='WHOLE':
            return self.jumble_char_whole(word, unchanged=unchanged)
        elif opt=='BEG':
            return self.jumble_char_beg(word, unchanged=unchanged)
        elif opt=='END':
            return self.jumble_char_end(word, unchanged=unchanged)
        elif opt=='INT':
            return self.jumble_char_int(word, unchanged=unchanged)
        else:

# Path: shorttext/generators/charbase/char2vec.py
# def initSentenceToCharVecEncoder(textfile, encoding=None):
#     """ Instantiate a class of SentenceToCharVecEncoder from a text file.
# 
#     :param textfile: text file
#     :param encoding: encoding of the text file (Default: None)
#     :return: an instance of SentenceToCharVecEncoder
#     :type textfile: file
#     :type encoding: str
#     :rtype: SentenceToCharVecEncoder
#     """
#     dictionary = Dictionary(map(lambda line: [c for c in line], textfile_generator(textfile, encoding=encoding)))
#     return SentenceToCharVecEncoder(dictionary)
# 
# Path: shorttext/utils/classification_exceptions.py
# class OperationNotDefinedException(Exception):
#     def __init__(self, opname):
#         self.message = 'Operation '+opname+' not defined'


# Path: shorttext/spell/binarize.py
import re
import string
import numpy as np
from functools import reduce
from shorttext.generators.charbase.char2vec import initSentenceToCharVecEncoder
from shorttext.utils.classification_exceptions import OperationNotDefinedException

            if len(word) > 1:
                idx = np.random.randint(0, len(word))
                w = word[:idx] + word[(idx+1):]
            else:
                w = word
            bin_all = self.concatchar_encoder.encode_spelling(w).transpose()
        elif opt=='INSERT':
            ins_idx = np.random.randint(0, len(word)+1)
            ins_char = np.random.choice([c for c in string.ascii_lowercase])
            w = word[:ins_idx] + ins_char + word[ins_idx:]
            bin_all = self.concatchar_encoder.encode_spelling(w).transpose()
        elif opt=='REPLACE':
            rep_idx = np.random.randint(0, len(word))
            rep_char = np.random.choice([c for c in string.ascii_lowercase])
            w = word[:rep_idx] + rep_char + w[(rep_idx+1):]
            bin_all = self.concatchar_encoder.encode_spelling(w).transpose()
        else:
            raise OperationNotDefinedException('NOISE-'+opt)
        return np.array([ np.repeat(np.array([bin_all]), 3, axis=0).reshape((1, len(self.concatchar_encoder)*3))[0] ]).transpose(), w

    def jumble_char(self, word, opt, unchanged=False):
        if opt=='WHOLE':
            return self.jumble_char_whole(word, unchanged=unchanged)
        elif opt=='BEG':
            return self.jumble_char_beg(word, unchanged=unchanged)
        elif opt=='END':
            return self.jumble_char_end(word, unchanged=unchanged)
        elif opt=='INT':
            return self.jumble_char_int(word, unchanged=unchanged)
        else:

            raise OperationNotDefinedException('JUMBLE-'+opt)