Created
March 10, 2019 23:11
-
-
Save krmgns/0b5e2068b0ba5c2b495de3196eb6f742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fn_slug(words): | |
import re | |
#global words | |
chrs = {'ı':'i', 'ö':'o', 'ü':'u', 'ç':'c', 'ğ':'g', 'ş':'s', | |
'İ':'I', 'Ö':'O', 'Ü':'U', 'Ç':'C', 'Ğ':'G', 'Ş':'S'} | |
def lower(word): | |
return word.replace('İ', 'i').replace('I', 'ı').lower() | |
def replace(word, chrs, ret=None): | |
for cs, cr in chrs.items(): | |
if cs in word: | |
ret = word = word.replace(cs, cr) | |
return ret | |
ret = [] | |
for word in re.split('([\d]\+[\d])|[^\w]+', words): | |
if not word: continue | |
word = re.sub('^[^\w]+|[^\w]+$', '', word) | |
if len(word) >= 2: | |
word = lower(word) | |
ret.append(word) | |
rep = replace(word, chrs) | |
if rep: | |
ret.append(lower(rep)) | |
return ' '.join(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment