alutiiq.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:wiinaq 作者: futurulus 项目源码 文件源码
def normalize(word):
    '''
    Perform fuzzy search normalization (collapse commonly confused sounds
    so search is resilient to misspellings of Alutiiq words).

    >>> normalize('tuumiaqlluku')
    'tumiaklluku'
    >>> normalize("Wiiwaq")
    'uiuak'
    >>> normalize("estui'isuun")
    'stuisun'
    '''
    word = re.subn(r'(?<!n)g', 'r', word)[0]
    word = re.subn(r'[A-QS-Z]', lambda m: m.group().lower(), word)[0]
    word = (word.replace('q', 'k')
                .replace('y', 'i')
                .replace('w', 'u')
                .replace('e', '')
                .replace("'", ''))
    for vowel in 'aiu':
        word = re.sub(vowel + '+', vowel, word)
    return word
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号