Skip to content

Instantly share code, notes, and snippets.

@gotraveltoworld
Created September 12, 2018 14:12
Show Gist options
  • Save gotraveltoworld/50c4feb6bda619b9274ab38052185a1d to your computer and use it in GitHub Desktop.
Save gotraveltoworld/50c4feb6bda619b9274ab38052185a1d to your computer and use it in GitHub Desktop.
Emojis and Punctuations filter base on python.
import re
import string
import emoji
from zhon import hanzi
class Filter_Text:
def filter_emoji(fun):
def wrapper(self, text=''):
result_text = fun(self, text)
return re.sub('(@@.*@@)', '', emoji.demojize(
'{0}'.format(result_text),
delimiters=('@@', '@@')
))
return wrapper
def filter_punctuation(fun):
def wrapper(self, text=''):
result_text = fun(self, text)
return ''.join([
w for w in result_text
if (
w not in string.punctuation and
w not in hanzi.punctuation
)
])
return wrapper
@filter_emoji
@filter_punctuation
def filtet_text(self, text=''):
return text
from filter_text import Filter_Text
if __name__ == '__main__':
result = Filter_Text().filtet_text('!!!Python is fun 👍. 測試中文標點符號,;')
print(result)
pass
emoji==0.5.0
zhon==1.1.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment