当前位置: 首页>>代码示例>>Python>>正文


Python transliterate.translit函数代码示例

本文整理汇总了Python中transliterate.translit函数的典型用法代码示例。如果您正苦于以下问题:Python translit函数的具体用法?Python translit怎么用?Python translit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了translit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_russian_regions

    def generate_russian_regions(self, session):
        self.print_status('Generating regions...')
        subject_types = {
            'Респ': 'republic',
            'обл': 'oblast',
            'г': 'city',
            'край': 'krai',
            'АО': 'autonomous oblast/okrug'
        }
        russia = session.query(Country).filter_by(name='Russia').one()

        for r_info in regions_info:
            name = r_info['name']
            code = r_info['regioncode']
            name_tokens = name.split()
            try:
                region_type = subject_types[name_tokens[-1]]
                result_name = translit(' '.join(name_tokens[:-1]), 'ru', reversed=True)
            except:
                region_type = 'unknown'
                result_name = translit(name, 'ru', reversed=True)
            r = Region(name=result_name, type=region_type, code=code, country=russia)
            session.add(r)

        self.print_status('Done')
开发者ID:SukharevAndrey,项目名称:Diploma,代码行数:25,代码来源:generator.py

示例2: transliterate

 def transliterate(self, string, mode='2cyr'):
     """ """
     new_string = ""
     if   all(s in self.dgt for s in string):
         return string
     elif mode == '2cyr' and all(s in self.lat for s in string):
         return translit(string, 'ru')
     elif mode == '2lat' and all(s in self.cyr for s in string):
         return translit(string, 'en')
     else: return None
开发者ID:favorart,项目名称:InfoSearch4,代码行数:10,代码来源:utils.py

示例3: test_data

def test_data(input_list):

    city = translit(input_list[1], 'ru', reversed=True)
    street = translit(input_list[2], 'ru', reversed=True)
    house_number = str(int(input_list[3]))

    address = city+'/'+street+'/'+house_number
    q = address

    # get запрос к серверу для получения координат
    params = urllib.parse.urlencode({'format': 'json'})
    url = "http://nominatim.openstreetmap.org/search/{1}?{0}".format(params, q)
    print(url)
    req = urllib.request.Request(url, headers={'User-Agent': 'super'})
    _start_time = time.time()

    with urllib.request.urlopen(req) as res:
        time_1 = time.time() - _start_time
        print("Время выполнения GET запроса: {:.3f} с".format(time.time() - _start_time))
        j = json.loads(res.read().decode('utf-8'))
        try:
            lat = j[0]['lat']
            lon = j[0]['lon']
        except IndexError:
            print('Out of range')
        except Exception:
            print(Exception)
        if len(j) == 0:
            return [input_list[0], 'Null response on step 1']

    params = urllib.parse.urlencode({'lat': lat, 'lon': lon, 'format': 'json'})
    url = "http://nominatim.openstreetmap.org/reverse?%s" % params
    print(url)

    # get запрос к сервену для поллучения адреса
    req = urllib.request.Request(url, headers={'User-Agent': 'super'})
    _start_time = time.time()
    with urllib.request.urlopen(req) as f:
        time_2 = time.time() - _start_time
        print("Время выполнения GET запроса: {:.3f} с".format(time.time() - _start_time))
        j = json.loads(f.read().decode('utf-8'))
        address = j['address']
        new_house_number = address['house_number']
        new_street = address['road']
        new_city = address['city']
        if len(j) == 0:
            return [input_list[0], 'Null response on step 2']

    if new_city == input_list[4] and new_street == input_list[5] and int(new_house_number) == int(input_list[6]):
        result_status = 'done'
    else:
        result_status = 'Wrong response'

    result = [input_list[0], result_status, round(time_1, 3), round(time_2, 3)]
    return result
开发者ID:DespairAndPain,项目名称:protei,代码行数:55,代码来源:app.py

示例4: __test_29_mappings

    def __test_29_mappings(self):
        """
        Testing mappings.
        """
        for language_pack in get_available_language_packs():
            print_('Testing language pack {0} {1}'.format(language_pack.language_code, language_pack.language_name))
            print_('Reversed test:')
            for letter in language_pack.mapping[1]:
                print_(letter, ' --> ', translit(letter, language_pack.language_code, reversed=True))

            print_('Normal test:')
            for letter in language_pack.mapping[0]:
                print_(letter, ' --> ', translit(letter, language_pack.language_code))
开发者ID:weezel,项目名称:ITIS13,代码行数:13,代码来源:test.py

示例5: create_categories

 def create_categories(self, parent, categories):
     print "Creating for:", parent
     for i, c in enumerate(categories):
         m = Menu()
         m.parent = parent
         m.page_type = c['page_type']
         m.title = c['title']
         m.title_ru = c['title']
         m.title_en = translit(c['title'], reversed=True)
         m.enabled = True
         m.url = slugify(translit(c['title'], reversed=True))
         m.save()
         print "created:", m
         if 'categories' in c:
             self.create_categories(m, c['categories'])
开发者ID:Brick85,项目名称:sitemenu,代码行数:15,代码来源:sitemenu_create_categories.py

示例6: test_03_translit_latin_to_georgian

 def test_03_translit_latin_to_georgian(self):
     """
     Test transliteration from Latin to Georgian.
     """
     res = translit(self.latin_text, 'ka')
     self.assertEqual(res, self.georgian_text)
     return res
开发者ID:weezel,项目名称:ITIS13,代码行数:7,代码来源:test.py

示例7: test_04_translit_latin_to_greek

 def test_04_translit_latin_to_greek(self):
     """
     Test transliteration from Latin to Greek.
     """
     res = translit(self.latin_text, 'el')
     self.assertEqual(res, self.greek_text)
     return res
开发者ID:weezel,项目名称:ITIS13,代码行数:7,代码来源:test.py

示例8: opener

def opener():
    dict_lines = {}

    # массив названий файлов для записи в zip файл
    files_name = []

    for root, dirs, files in os.walk(UPLOAD_FOLDER):
        for file in files:
            files_name.append(file)
            with open(root+"/"+file, 'rt', encoding='utf-8') as r:
                spam_reader = csv.reader(r)
                n = 0
                for row in spam_reader:
                    if len(row) > 0:
                        # транслитерируем и записывам в dict
                        dict_lines[n] = translit(row[0], 'ru', reversed=True)
                        n += 1
            with open(APP_STATIC+'/for_load/'+file, "w", encoding='utf-8') as wr:
                # из dict пишем в новый .csv файл
                write_file = csv.writer(wr, quoting=csv.QUOTE_MINIMAL, delimiter=';')
                for line in dict_lines.values():
                    iter_line = line.split(';')
                    write_file.writerow(iter_line)
                dict_lines = {}
    # создаём zip файл со всеми изменёнными файлами
    with zipfile.ZipFile(APP_STATIC+'/zip/files.zip', 'w') as zip_file:
        for file in files_name:
            path = APP_STATIC+'/for_load/'+file
            zip_file.write(path, basename(path))
开发者ID:DespairAndPain,项目名称:transliterate,代码行数:29,代码来源:transliter.py

示例9: test_02_translit_latin_to_armenian

 def test_02_translit_latin_to_armenian(self):
     """
     Test transliteration from Latin to Armenian.
     """
     res = translit(self.latin_text, 'hy')
     self.assertEqual(res, self.armenian_text)
     return res
开发者ID:weezel,项目名称:ITIS13,代码行数:7,代码来源:test.py

示例10: test_08_translit_georgian_to_latin

 def test_08_translit_georgian_to_latin(self):
     """
     Test transliteration from Georgian to Latin.
     """
     res = translit(self.georgian_text, 'ka', reversed=True)
     self.assertEqual(res, self.latin_text)
     return res
开发者ID:weezel,项目名称:ITIS13,代码行数:7,代码来源:test.py

示例11: song_rebase

    def song_rebase(self):
        playlists = self.library.getPlaylistNames()

        for playlist in playlists:
            playlist_match = self.playlist_re.search(playlist)

            if playlist_match:
                disk_number = playlist_match.group('disk')
                disk_folder = "{0}CD{1}/".format(self.structure_path, disk_number)

                print "Заполняем структуру по плейлисту \'{0}\' как диск {1} с {2} композицией(ями)".format(playlist,
                                                        disk_number, len(self.library.getPlaylist(playlist).tracks))

                if not os.path.isdir(disk_folder):
                    os.makedirs(disk_folder, 0755)
                else:
                    filelist = [f for f in os.listdir(disk_folder) if f.endswith(".mp3")]
                    for f in filelist:
                        os.remove("{0}/{1}".format(disk_folder, f))

                for song in self.library.getPlaylist(playlist).tracks:
                    print "    Перемещаем #{2} [{0} - {1}]".format(song.artist, song.name, song.playlist_order)

                    file_cache = "{0}{1}.mp3".format(self.cache_path, song.track_id)
                    file_name = self.make_safe_filename(
                                             translit("{0}_{1} - {2}.mp3".format(song.playlist_order, song.artist,
                                                                                 song.name),
                                                      language_code="ru", reversed=True))
                    file_structure = "{0}{1}".format(disk_folder, file_name)

                    shutil.copyfile(file_cache, file_structure)
开发者ID:MaxOnNet,项目名称:Yator,代码行数:31,代码来源:Yator.py

示例12: test_11_translit_mongolian_cyrillic_to_latin

 def test_11_translit_mongolian_cyrillic_to_latin(self):
     """
     Test transliteration from Mongolian Cyrillic to Latin.
     """
     res = translit(self.mongolian_cyrillic_text, 'mn', reversed=True)
     self.assertEqual(res, self.latin_text)
     return res
开发者ID:akosiaris,项目名称:transliterate,代码行数:7,代码来源:test_transliterate.py

示例13: test_06_translit_latin_to_ukrainian_cyrillic

 def test_06_translit_latin_to_ukrainian_cyrillic(self):
     """
     Test transliteration from Latin to Ukrainian Cyrillic.
     """
     res = translit(self.latin_text, 'uk')
     self.assertEqual(res, self.ukrainian_cyrillic_text)
     return res
开发者ID:weezel,项目名称:ITIS13,代码行数:7,代码来源:test.py

示例14: replacer

def replacer(word):
    search_word = translit(word, 'mn')
    if u"ө" in search_word:
        search_word_regex = search_word.replace(u"ө", u"[өүу]")
        search_word_regex_reform = "^" + search_word_regex + '$'
        found_or_not = [item for i, item in enumerate(data) if re.search(search_word_regex_reform, item)]

        if found_or_not:
            return found_or_not[0]
        else:
            return search_word
    elif u"у" in search_word:
        search_word_regex = search_word.replace(u"у", u"[өүу]")
        search_word_regex_reform = "^" + search_word_regex + '$'
        found_or_not = [item for i, item in enumerate(data) if re.search(search_word_regex_reform, item)]

        if found_or_not:
            return found_or_not[0]
        else:
            return search_word
    elif u'үү' == search_word:
        return u'уу'
    elif u"ү" in search_word:
        search_word_regex = search_word.replace(u"ү", u"[өүу]")
        search_word_regex_reform = "^"+search_word_regex+'$'
        found_or_not = [item for i, item in enumerate(data) if re.search(search_word_regex_reform, item)]

        if found_or_not:
            return found_or_not[0]
        else:
            return search_word
    else:
        return search_word
开发者ID:enod,项目名称:rest-api-transliterate-mn,代码行数:33,代码来源:app.py

示例15: test_06_translit_latin_to_mongolian_cyrillic

 def test_06_translit_latin_to_mongolian_cyrillic(self):
     """
     Test transliteration from Latin to Mongolian Cyrillic.
     """
     res = translit(self.latin_text, 'mn')
     self.assertEqual(res, self.mongolian_cyrillic_text)
     return res
开发者ID:akosiaris,项目名称:transliterate,代码行数:7,代码来源:test_transliterate.py


注:本文中的transliterate.translit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。