<jupyter_start><jupyter_text>How to generate wordclouds for different brands using different modules<jupyter_code>%load_ext autoreload
%autoreload 2
import sys
sys.path.append('../')
from common import connectMongo
from common import getData
from viz import createWordcloud

conn = connectMongo.connect_mongo('forums','ooakForum')
import re 

patterns = {'Tenergy 05':"[tT]energy[-\s]?05\s?[^Ff]?[^Xx]?",
            'Baracuda':"Baracuda",
           }
regex_or = re.compile(patterns['Tenergy 05'], re.IGNORECASE)
regex_or_result = conn.find({"title":regex_or},{"title":1,"replies.clean_text":1})<jupyter_output><empty_output><jupyter_text>Tenergy 05<jupyter_code>regex_or = re.compile(patterns['Tenergy 05'], re.IGNORECASE)
regex_or_result = conn.find({"title":regex_or},{"title":1,"replies.clean_text":1})
tmp = getData.generate_df_from_result(regex_or_result)
df_s = tmp.copy()
df_s['reply_split'] = df_s.reply.apply(getData.tokenize_sent)  # df_s.reply.apply(tokenize_sent)
df_s = df_s.explode('reply_split')
df_s = df_s.drop('reply', axis=1)
df_s = df_s.loc[df_s['reply_split'].notnull(),:]
df_s.reset_index(inplace=True)
searchfor = ['[tT]energy]', '[tT]05']
df1 = df_s[df_s.reply_split.str.contains('|'.join(searchfor))]<jupyter_output><empty_output><jupyter_text>Baracuda<jupyter_code>regex_or = re.compile(patterns['Baracuda'], re.IGNORECASE)
regex_or_result = conn.find({"title":regex_or},{"title":1,"replies.clean_text":1})
tmp = getData.generate_df_from_result(regex_or_result)
df_s = tmp.copy()
df_s['reply_split'] = df_s.reply.apply(getData.tokenize_sent)
df_s = df_s.explode('reply_split')
df_s = df_s.drop('reply', axis=1)
df_s_tmp = df_s.loc[df_s['reply_split'].notnull(),:]
df_s_tmp.reset_index(inplace=True)
searchfor = ['[bB]aracuda']
df2 = df_s_tmp[df_s_tmp.reply_split.str.contains('|'.join(searchfor))]<jupyter_output><empty_output><jupyter_text>Preprocess<jupyter_code>from common import cleanData
data_col = 'reply_split'
clean_df1 = cleanData.preprocess_news(df1,data_col,lowercase=True)
clean_df2 = cleanData.preprocess_news(df2,data_col,lowercase=True)

clean_df1 = cleanData.remove_dash(clean_df1)
clean_df2 = cleanData.remove_dash(clean_df2)

string_df1 = ' '.join(clean_df1)    
string_df2 = ' '.join(clean_df2)    

stop_words = cleanData.get_stopwords_list()
t05_stopwords = stop_words
t05_stopwords.extend(['T05FX','T05','rubber','t05fx','t05',"t05fx'","t05 '",                     
't05','nt','would','much','t05fx','play','get','feel','...','one',
                      'use','tenergy','used','the','tried','using','think','t64','ball','spin','speed','playing','played','player','good','better','new'])
print(len(t05_stopwords))


baracuda_stopwords = stop_words
baracuda_stopwords.extend(['T05FX','T05','rubber','t05fx','t05',"t05fx'","t05 '",                     
't05','nt','would','much','t05fx','play','get','feel','...','one','quite','also',
                      'use','tenergy','used','the','tried','using','think','baracuda','spin','speed','playing','played','player','good','better'])
print(len(baracuda_stopwords))
import matplotlib.pyplot as plt
## Tenergy 05 Red Wordcloud
createWordcloud.produce_wordcloud_graphics(string_df1,t05_stopwords,'../../output/wordcloud/Butterfly-Tenergy-05.png',color='red')
## Baracuda Black Wordcloud
createWordcloud.produce_wordcloud_graphics(string_df2,baracuda_stopwords,'../../output/wordcloud/Baracuda.png',color='black')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18830034924330616, 'fraction_numerical': 0.024155995343422585, 'mean_word_length': 7.790281329923274, 'pattern_counts': {'":': 9, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '309153', 'license': 'MIT', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1293, 'n_words': 134, 'path': 'viz/.ipynb_checkpoints/Generate Wordclouds for different rubbers-checkpoint.ipynb', 'repo_name': 'vionwinnie/tableTennis-product-review', 'size': '3436'}