<jupyter_start><jupyter_text>Word Treepara mais detalhes: https://developers.google.com/chart/interactive/docs/gallery/wordtree<jupyter_code>from IPython.display import HTML
from string import Template
import requests
#dados(frases)

json_tree = [['Frases'],
        ['cats are better than dogs'], ['dog eat kibble'], ['cats are better than hamsters'],
        ['dog are awesome'], ['cats are people too'], ['cats eat mice'],
        ['cats meowing'], ['cats in the cradle'], ['cats eat mice'],
        ['cats in the cradle lyrics'], ['cats eat kibble'], ['cats for adoption'],
        ['dog are family'], ['dog eat mice'], ['dog are better than kittens'],
        ['cats are evil'], ['cats are weird'], ['cats eat mice']]
#ler um aqrquivo ou a URL onde comtem o HTML do google
url = requests.get("https://raw.githubusercontent.com/EduardoMoraesRitter/word-tree-analysis/main/wordtree_template.html")

#Ler HTML do aquirvo
htmltext = Template(url.text)

#subistituir os valores ${}
htmlfinal =  htmltext.substitute(root_word="are", tree_type="double", json_formatted=json_tree)

#executar o HML
HTML(htmlfinal)<jupyter_output><empty_output><jupyter_text>Exemplo com função<jupyter_code>def get_word_tree_html(json_formatted, root_word, lowercase=True, tree_type='double'):
    
    with open('https://raw.githubusercontent.com/EduardoMoraesRitter/word-tree-analysis/main/wordtree_template.html', 'r') as my_file:
        html_template = Template(my_file.read())
    return html_template.substitute(root_word=root_word,
                                    tree_type=tree_type,
                                    json_formatted=json_formatted.lower() if lowercase else json_formatted)
json = [['Frases'],
        ['cats are better than dogs'],
        ['dog eat kibble'],
        ['cats are better than hamsters'],
        ['dog are awesome'],
        ['cats are people too'],
        ['cats eat mice'],
        ['cats meowing'],
        ['cats in the cradle'],
        ['cats eat mice'],
        ['cats in the cradle lyrics'],
        ['cats eat kibble'],
        ['cats for adoption'],
        ['dog are family'],
        ['dog eat mice'],
        ['dog are better than kittens'],
        ['cats are evil'],
        ['cats are weird'],
        ['cats eat mice']]

HTML(get_word_tree_html(json, 'are', lowercase=False, tree_type='double'))
"""
<html>

<head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

        google.charts.load('current', { packages: ['wordtree'] });

        var chart;
        var data;
        var options = {
            wordtree: {
                format: 'implicit',
                word: '${root_word}',
                type: '${tree_type}'
            }
        };

        function initChart() {
            data = google.visualization.arrayToDataTable(${json_formatted});
            chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
        }

        function drawChart() {
            chart.draw(data, options);
        }

        function setRootWordFromForm() {
            options.wordtree.word = document.getElementById('root_word').value;
            drawChart();
        }

        google.charts.setOnLoadCallback(function () {
            initChart();
            drawChart();
        });

    </script>
</head>

<body>
    Root Word:
    <input type="text" id="root_word" value="${root_word}">
    <button type="button" onclick="setRootWordFromForm()">Update Tree</button>
    <br>
    <div id="wordtree_basic" style="width: 900px; height: 600px;"></div>
</body>

</html>
"""
#forma de ler o aquivo
with open('wordtree_template.html', 'r') as my_file:
  print(my_file)
  html_template = Template(my_file.read())
teste = html_template.substitute(root_word="are", tree_type="double", json_formatted=[["aa"],["are"]])
HTML(teste)
#outra forma de ler um aquivo
import codecs
f=codecs.open("wordtree_template.html", 'r')
print(f.read())<jupyter_output><empty_output><jupyter_text>Wordcloud  Define the helper method<jupyter_code>def generate_cloud(texts, max_words=30):
    # Add more words here if you want to ignore them:
    my_stopwords = STOPWORDS.copy()
    my_stopwords.update(['go', 'ya', 'come', 'back', 'good', 'sound'])
    words = ' '.join(texts).lower()
    wordcloud = WordCloud(font_path='CabinSketch-Bold.ttf',
                          stopwords=my_stopwords,
                          background_color='black',
                          width=800,
                          height=600,
                          relative_scaling=1,
                          max_words=max_words
                         ).generate_from_text(words)
    print('Based on {0:,} texts'.format(len(texts)))
    
    fig, ax = plt.subplots(figsize=(15,10))
    ax.imshow(wordcloud)
    ax.axis('off')
    plt.show()<jupyter_output><empty_output><jupyter_text>Texts you've sent<jupyter_code># Word cloud of the top 25 words I use based on the most recent 30,000 messages.

texts_from_me = fully_merged_messages_df[fully_merged_messages_df.is_from_me == 1].text[-30000:]
widgets.interact(
    generate_cloud,
    texts=widgets.fixed(texts_from_me),
    max_words=widgets.IntSlider(min=5,max=50,step=1,value=10, continuous_update=False,
                                description='Max words to show:'))<jupyter_output><empty_output><jupyter_text>Texts to/from a specific contact<jupyter_code>def _word_cloud_specific_contact(max_words, from_me, contact):
    contact = convert_unicode_to_str_if_needed(contact)
    if contact not in full_names:
        print('{} not found'.format(contact))
        return
    sliced_df = fully_merged_messages_df[(fully_merged_messages_df.full_name == contact) &
                                         (fully_merged_messages_df.is_from_me == from_me)].text
    generate_cloud(sliced_df, max_words)

widgets.interact(
    _word_cloud_specific_contact,
    max_words=widgets.IntSlider(min=5, max=50, step=1, value=10,
                                continuous_update=False, description='Max words to show:'),
    from_me=widgets.RadioButtons(
        options={'Show messages FROM me': True, 'Show messages TO me': False}, description=' '),
    contact=widgets.Text(value='Mom', description='Contact name:')
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1343141907925961, 'fraction_numerical': 0.007119126720455624, 'mean_word_length': 3.037037037037037, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '245044', 'license': 'MIT', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1928, 'n_words': 421, 'path': 'word_tree_analysis.ipynb', 'repo_name': 'EduardoMoraesRitter/word-tree-analysis', 'size': '6321'}