• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python transliterate.translit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: make_filename

def make_filename(collection_name, title, idx=None):
    if idx:
       idx = "-" + str(idx)
    else:
       idx = ""
    out_filename = filter_valid_path(translit(collection_name, 'uk', reversed=True)) + "/" + filter_valid_path(translit(title, 'uk', reversed=True).replace('/', '_')[:64]) + idx + ".txt"
    return out_filename
开发者ID:meshko,项目名称:scrapers,代码行数:7,代码来源:zakarpattya_gazeta.py


示例17: save

    def save(self, *args, **kwargs):
        if self.title:
            # TODO: 'uk' parameter should be changed in case of extra locale
            transliterated = translit(self.title, 'uk', reversed=True)
            self.slug = slugify(transliterated).replace('-', '_')

        super(Service, self).save(*args, **kwargs)
开发者ID:Kid-Binary,项目名称:HGBD,代码行数:7,代码来源:models.py


示例18: nameCompare

def nameCompare(persons, percentage = float(0.50)):
    global total, totalcorrect

    for person in persons:
        en = person.en_name.split(" ")
        ru = person.ru_name.split(" ")
        ru = [stripAccentMark(name) for name in ru]

        #translit_ru = [translit(name, "ru") for name in en]
        # Transliterate russian name to english name
        translit_en = [translit(name.encode("utf-8").decode("utf-8"), \
                reversed = True) for name in ru]

        total += len(en)

        # Print name in english and russian
        yield u"\n%s (EN) %s (RU) " % (" ".join(en), " ".join(ru))

        for en_litname in translit_en:
            for en_name in en:
                diff = jaccardIdx(en_name, en_litname)
                if diff <= percentage:
                    if diff == 0.0:
                        totalcorrect += 1
                    yield u":: (EN orig) %s <==> (EN lit) %s (%.2f)" % (en_name, \
                           en_litname, diff)
开发者ID:weezel,项目名称:ITIS13,代码行数:26,代码来源:russiannames.py


示例19: __test_05_translit_latin_to_hebrew

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


示例20: post

 def post(self):
     new_room_name = self.get_argument("new_room")
     room = yield tornado.gen.Task(
         self.db.rooms.find_one, {'name': new_room_name})
     if not isinstance(room[0][0], dict):
         room_to_add = {}
         if re.match(u"^[А-Яа-я _-]*$", new_room_name, re.UNICODE):
             new_room_to_use = translit(
                 new_room_name, 'ru', reversed=True).replace(' ', '_')
         else:
             new_room_to_use = new_room_name.replace(' ', '_')
         room_to_add["name"] = new_room_to_use
         room_to_add["name_to_show"] = new_room_name
         room_to_add["users"] = []
         room_to_add["messages"] = []
         yield tornado.gen.Task(self.db.rooms.insert, room_to_add)
         yield tornado.gen.Task(
             self.db.rooms_list.update,
             {'name': 'room'}, {'$push': {'rooms_list': [new_room_to_use, new_room_name]}}
         )
         new_url = "/room/" + new_room_to_use
         self.redirect(new_url)
     else:
         new_url = "/room/" + new_room_name.replace(' ', '_')
         self.redirect(new_url)
开发者ID:FuriousCoder,项目名称:tornadochat,代码行数:25,代码来源:main.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python transmeta.get_real_fieldname函数代码示例发布时间:2022-05-27
下一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap