-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update stats.py #10
base: main
Are you sure you want to change the base?
Update stats.py #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,14 @@ def __init__(self, chat_json: Union[str, Path]): | |
""" | ||
# load chat data | ||
logger.info(f"Loading chat data from {chat_json}") | ||
with open(chat_json) as f: | ||
with open(chat_json, encoding='UTF8') as f: | ||
self.chat_data = json.load(f) | ||
|
||
self.normalizer = Normalizer() | ||
|
||
# load stopwords | ||
logger.info(f"Loading stopwords from {DATA_DIR / 'stopwords.txt'}") | ||
stop_words = open(DATA_DIR / 'stopwords.txt').readlines() | ||
stop_words = open(DATA_DIR / 'stopwords.txt', encoding='UTF8').readlines() | ||
stop_words = map(str.strip, stop_words) | ||
self.stop_words = set(map(self.normalizer.normalize, stop_words)) | ||
|
||
|
@@ -128,7 +128,29 @@ def de_emojify(self, text): | |
|
||
:param text: Text that contains emoji | ||
""" | ||
regrex_pattern = re.compile(pattern="[\u2069\u2066]+", flags=re.UNICODE) | ||
regrex_pattern = re.compile(pattern="[" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since in the next line the You can find the emojis that method |
||
u"\U0001F600-\U0001F64F" # emoticons | ||
u"\U0001F300-\U0001F5FF" # symbols & pictographs | ||
u"\U0001F680-\U0001F6FF" # transport & map symbols | ||
u"\U0001F1E0-\U0001F1FF" # flags (iOS) | ||
u"\U00002702-\U000027B0" | ||
u"\U000024C2-\U0001F251" | ||
u"\U0001f926-\U0001f937" | ||
u'\U00010000-\U0010ffff' | ||
u"\u200d" | ||
u"\u2640-\u2642" | ||
u"\u2600-\u2B55" | ||
u"\u23cf" | ||
u"\u23e9" | ||
u"\u231a" | ||
u"\u3030" | ||
u"\ufe0f" | ||
u"\u2069" | ||
u"\u2066" | ||
u"\u200c" | ||
u"\u2068" | ||
u"\u2067" | ||
"]+", flags=re.UNICODE) | ||
text = regrex_pattern.sub('', text) | ||
return demoji.replace(text, " ") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Ali and thanks for the PR.
Encoding of JSON files extracted from Telegram is UTF-8 and It is a good idea to identify the encoding of files when reading them. Thanks for this suggestion.