Converts (transliterates) greek letters to latin equivalents.
776444
def latinize(value):
    
    def replace_double_character(match):
        search = ('Θ Χ Ψ '
                  'θ χ ψ '
                  'ΟΥ ΑΥ ΕΥ '
                  'Ου Αυ Ευ '
                  'ου αυ ευ').split()
        replace = ('TH CH PS '
                   'th ch ps '
                   'OU AU EU '
                   'Ou Au Eu '
                   'ou au eu').split()
        matched = match.group(0)
        if matched in search:
            return replace[search.index(matched)]
        return matched

    search = 'ΑΒΓΔΕΖΗΙΚΛΜΝΞΟΠΡΣΣΤΥΦΩαβγδεζηικλμνξοπρσςτυφω'
    replace = 'AVGDEZIIKLMNXOPRSSTUFOavgdeziiklmnxoprsstyfo'

    def replace_greek_character(match):
        matched = list(match.group(0))
        value = map(lambda l: replace[search.find(l)], matched)
        return ''.join(value)

    return re.sub(r'[{0}]+'.format(search),
                  replace_greek_character, re.sub(
        r'([ΘΧΨθχψ]+|ΟΥ|ΑΥ|ΕΥ|Ου|Αυ|Ευ|ου|αυ|ευ)',
        replace_double_character,
        remove_accents(value)))
742614
def normalize_text(self, txt):
        ""
        # - for TTF unicode fonts: unicode object (utf8 encoding)
        # - for built-in fonts: string instances (latin 1 encoding)
        if self.unifontsubset and isinstance(txt, str) and not PY3K:
            txt = txt.decode('utf8')
        elif not self.unifontsubset and isinstance(txt, unicode) and not PY3K:
            txt = txt.encode('latin1')
        return txt
904623
def _transliterate (self, text, outFormat):
        
        result = []
        text = self._preprocess(text)
        i = 0
        while i < len(text):
            if text[i].isspace(): 
                result.append(text[i])
                i = i+1
            else: 
                chr = self._getNextChar(text, i)
                try:
                    result.append(self[chr].unichr)
                except KeyError:
                    result.append(_unrecognised(chr))
                i = i + len(chr)
        return result
972125
def clean_asciidoc(text):
    
    """
    text = re.sub(r'(\b|^)[\[_*]{1,2}([a-zA-Z0-9])', r'"\2', text)
    text = re.sub(r'([a-zA-Z0-9])[\]_*]{1,2}', r'\1"', text)
    return text
565681
def _translate(unistr, table):
    ''''''
    if type(unistr) is str:
        try:
            unistr = unistr.decode('utf-8')
        # Python 3 returns AttributeError when .decode() is called on a str
        # This means it is already unicode.
        except AttributeError:
            pass
    try:
        if type(unistr) is not unicode:
            return unistr
    # Python 3 returns NameError because unicode is not a type.
    except NameError:
        pass

    chars = []
    for c in unistr:
        replacement = table.get(c)
        chars.append(replacement if replacement else c)
    return u''.join(chars)
1022590
def convertforinput(self,filepath, metadata=None):
        """"""
        super(CharEncodingConverter,self).convertforinput(filepath, metadata)

        shutil.copy(filepath, filepath + '.convertsource')

        try:
            fsource = io.open(filepath + '.convertsource','r',encoding=self.charset)
            ftarget = io.open(filepath,'w',encoding=metadata['encoding'])
            for line in fsource:
                ftarget.write(line + "\n")
            success = True
        except:
            ftarget.close()
            fsource.fclose()
            success = False
        finally:
            os.unlink(filepath + '.convertsource')

        return success
1296107
private static String translate(String word, List<Replacer> replacers){
        // Scan uncountables and leave alone
        for(String uncountable: uncountables){
            if(uncountable.equals(word))
                return word;
        }

        // Scan our patterns for a match and return the correct replacement
        for(Replacer replacer: replacers){
            Matcher matcher = replacer.pattern.matcher(word);

            if(matcher.matches()){
                StringBuffer sb = new StringBuffer();
                boolean group = false;
                for(int i=0; i<replacer.rule.length(); i++){
                    char ch = replacer.rule.charAt(i);
                    if(group){
                        sb.append(matcher.group(Character.digit(ch, 10)));
                        group = false;
                    }else if(ch=='\\')
                        group=true;
                    else
                        sb.append(ch);
                }
                return sb.toString();
            }
        }

        // Return the original string unchanged
        return word;
    }
1122709
def ascii_text(text):
    """"""
    text = latinize_text(text, ascii=True)
    if isinstance(text, six.text_type):
        text = text.encode('ascii', 'ignore').decode('ascii')
    return text
1020651
def transform_source(text):
    '''
    '''
    toks = tokenize.generate_tokens(StringIO(text).readline)
    result = []
    replacing_keyword = False
    for toktype, tokvalue, _, _, _ in toks:
        if toktype == tokenize.NAME and tokvalue == 'switch':
            result.extend([
                (tokenize.NAME, 'for'),
                (tokenize.NAME, '__case'),
                (tokenize.NAME, 'in'),
                (tokenize.NAME, '_Switch'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif toktype == tokenize.NAME and (tokvalue == 'case' or tokvalue == 'default'):
            result.extend([
                (tokenize.NAME, 'if'),
                (tokenize.NAME, '__case'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif replacing_keyword and tokvalue == ':':
            result.extend([
                (tokenize.OP, ')'),
                (tokenize.OP, ':')
            ])
            replacing_keyword = False
        else:
            result.append((toktype, tokvalue))
    return tokenize.untokenize(result)
733903
def generate_greeklish_words(greek_words)
      @greeklish_list.clear

      greek_words.each do |greek_word|
        @per_word_greeklish.clear

        initial_token = greek_word

        digraphs.each_key do |key|
          greek_word = greek_word.gsub(key, digraphs[key])
        end

        # Convert it back to array of characters. The iterations of each
        # character will take place through this array.
        input_token = greek_word.split(//)

        # Iterate through the characters of the token and generate
        # greeklish words.
        input_token.each do |greek_char|
          add_character(conversions[greek_char])
        end

        @greeklish_list << per_word_greeklish.flatten
      end

      @greeklish_list.flatten
    end
1347022
def bothify(self, text='## ??', letters=string.ascii_letters):
        
        return self.lexify(self.numerify(text), letters=letters)
691489
def replace_greek_tex(self, name):
        """"""
        name = name.replace('gamma-delta', 'gammadelta')
        name = name.replace('interleukin-1 beta', 'interleukin-1beta')
        # greek_present = False
        for greek_txt, tex in self.greek2tex.items():
            if greek_txt in name:
                # greek_present = True
                name = name.replace(greek_txt, "{B}".format(B=tex))
        # if greek_present is True:
        #     name = texcode(name, 'utf-8') # For writing to xlsx
        return name
163313
def decode(s):
    
    if isinstance(s, binary_type):
        s = s.decode('latin-1')
    if not isinstance(s, text_type):
        return s

    r = []
    _in = []
    for c in s:
        if c == '&' and not _in:
            _in.append('&')
        elif c == '-' and _in:
            if len(_in) == 1:
                r.append('&')
            else:
                r.append(modified_deutf7(''.join(_in[1:])))
            _in = []
        elif _in:
            _in.append(c)
        else:
            r.append(c)
    if _in:
        r.append(modified_deutf7(''.join(_in[1:])))

    return ''.join(r)
159559
def toUnicode(s):
    
    if isinstance(s, six.binary_type):
        s = s.decode('utf-8')
    return s
259503
def translate_word(word, dictionary=['simplified']):
    '''
    
    '''
    if not dictionaries:
        init()
    for d in dictionary:
        if word in dictionaries[d]:
            return dictionaries[d][word]
    return None
378072
def slugify(text, delim='-'):
    """"""
    result = []
    for word in _punct_re.split((text or '').lower()):
        result.extend(codecs.encode(word, 'ascii', 'replace').split())
    return delim.join([str(r) for r in result])
896482
def translate(self, text):
        

        # Reset substitution counter
        self.count = 0

        # Process text
        return self._make_regex().sub(self, text)