Created
September 12, 2018 14:12
-
-
Save gotraveltoworld/50c4feb6bda619b9274ab38052185a1d to your computer and use it in GitHub Desktop.
Emojis and Punctuations filter base on python.
This file contains 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
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 |
This file contains 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
from filter_text import Filter_Text | |
if __name__ == '__main__': | |
result = Filter_Text().filtet_text('!!!Python is fun 👍. 測試中文標點符號,;') | |
print(result) | |
pass |
This file contains 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
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