예제 #1
0
파일: convert.py 프로젝트: 2vitalik/words
def transliterate(text):
    transliterator = transliteration.transliterator('ascii')
    try:
        codecedText = text.encode('ascii', 'replace').decode('ascii')
    except UnicodeDecodeError:
        codecedText = text
    transliteratedText = ''
    # Note: A transliteration replacement might be longer than the
    # original character, e.g. ч is transliterated to ch.
    prev = "-"
    for i in xrange(len(codecedText)):
        # work on characters that couldn't be encoded, but not on
        # original question marks.
        if codecedText[i] == '?' and text[i] != u'?':
            try:
                transliterated = transliterator.transliterate(
                    text[i], default='?', prev=prev, next=text[i+1])
            except IndexError:
                transliterated = transliterator.transliterate(
                    text[i], default = '?', prev=prev, next=' ')
            # transliteration was successful. The replacement
            # could consist of multiple letters.
            # mark the transliterated letters in yellow.
            # transliteratedText += '\03{lightyellow}%s\03{default}' \
            #                       % transliterated
            transliteratedText += transliterated
            transLength = len(transliterated)
            # memorize if we replaced a single letter by multiple
            # letters.
            if len(transliterated) > 0:
                prev = transliterated[-1]
        else:
            # no need to try to transliterate.
            transliteratedText += codecedText[i]
            prev = codecedText[i]
    return transliteratedText
예제 #2
0
import re
import sys
import threading

from typing import Any, Optional, Union

import pywikibot
from pywikibot import config2 as config

from pywikibot.backports import Sequence
from pywikibot.bot import VERBOSE, INFO, STDOUT, INPUT, WARNING
from pywikibot.bot_choice import (ChoiceException, Option, OutputOption,
                                  QuitKeyboardInterrupt, StandardOption)
from pywikibot.userinterfaces import transliteration

transliterator = transliteration.transliterator(config.console_encoding)

colors = [
    'default',
    'black',
    'blue',
    'green',
    'aqua',
    'red',
    'purple',
    'yellow',
    'lightgray',
    'gray',
    'lightblue',
    'lightgreen',
    'lightaqua',
예제 #3
0
import math
import re
import sys
import threading

import pywikibot
from pywikibot import config2 as config
from pywikibot.bot import VERBOSE, INFO, STDOUT, INPUT, WARNING
from pywikibot.bot_choice import (
    Option, OutputOption, StandardOption, ChoiceException,
    QuitKeyboardInterrupt,
)
from pywikibot.tools import deprecated, PY2
from pywikibot.userinterfaces import transliteration

transliterator = transliteration.transliterator(config.console_encoding)

colors = [
    'default',
    'black',
    'blue',
    'green',
    'aqua',
    'red',
    'purple',
    'yellow',
    'lightgray',
    'gray',
    'lightblue',
    'lightgreen',
    'lightaqua',