# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import topicvisexplorer
from ipywidgets import Play
from ipywidgets import interact, interactive, fixed, interact_manual
import matplotlib.pyplot as plt
import seaborn as sns
import textwrap
from ipywidgets import FloatSlider
import json

# +
vis = topicvisexplorer.TopicVisExplorer("name")



# -

vis.load_single_corpus_data("models_output/single_corpus_europe_cambridge_analytica_lda_mallet_gensim_new_prepared_data_enero_11.pkl")

vis.run()

# +

type(topicvisexplorer.single_corpus_data['topic_similarity_matrix'])
# -

# ### Get confussion matrix

# +

names_excel_europe = [
"Issues after deleting facebook account (e.g, new account makes old facebook accounts suggestion, facebook account was deleted by irrational reasons)",
"Cambridge analytica interfered on UK referendum (brexit)",
"Facebook has move users out of reach of european privacy law to dodge GDPR",
"Bigdata (Big data companies and big data solutions)",
"Promote social networks accounts",
"<NAME> hearing (EU and US parliament)",
"Inteligence Artificial on the industry",
"News about data privacy breaches on Facebook",
"Relationship between  Scottish National party (snp) and Cambridge Analytica",
"Discussion about Facebook company's practices",
"People share and discuss different articles thay they read (some of them related to privacy)"
]
# -

names_excel_northamerica = [
    'Delete of content on Facebook (account, messages, photos,…)',
    "Comments about <NAME>",
    "Intelligence Artificial as a bussiness or service",
    "Facebook is censonring speech",
    "Facebook share information with other companies",
    "Privacy, as a problem that must be resolved // People problems ?",
    "Facebook and privacy regulations (such as GDPR)",
    "Discussion about Fake news",
    "US election was intervened (by Russia and Cambridge Analytica)",
    "Trump and inmigration policies (separating child from families)",
    "PC gaming streaming and Zuckerberg's hearing"    
]

matrices_dict_test = topicvisexplorer.single_corpus_data['topic_similarity_matrix']


def show_confussion_matrix(omega):
    omega = omega/100.0
    max_width = 45
    fig, ax = plt.subplots(figsize=(10,10))     
    sns.heatmap(matrices_dict_test[omega], annot=True, cmap='vlag_r', vmin=-1, vmax=1, linewidths=.5, ax=ax, xticklabels=names_excel_europe, yticklabels=names_excel_europe)
    ax.set_xticklabels(textwrap.fill(x.get_text(), max_width) for x in ax.get_xticklabels())
    ax.set_yticklabels(textwrap.fill(x.get_text(), max_width) for x in ax.get_yticklabels())
    plt.title("Topic similarity metric proposed - Omega: "+str(omega), fontsize = 20, y = 1.02)
    plt.xlabel('North America', fontsize=16)
    plt.ylabel('Europe', fontsize=16)


from ipywidgets import Play
interact(show_confussion_matrix, omega=Play(value=0, min=0, max=100, step=1, interval=200));


# ### Check bubbles positions - Scenario 1

# +

data = json.loads(topicvisexplorer.single_corpus_data['new_circle_positions']) 
#single_corpus_data['new_circle_positions']
# -

def plot_circles_with_procrustes(lambda_):
    new_circle_positions_selected = data[str(lambda_)]
    #print(lambda_, new_circle_positions_selected)
    x = [i[0] for i in new_circle_positions_selected]
    y = [i[1] for i in new_circle_positions_selected]
    plt.figure()
    plt.plot(x, y, 'o'); # markersize = 15

    n = range(len(x))
    for i, txt in enumerate(n):
        plt.annotate(txt, (x[i], y[i]), fontsize =15)

    plt.show()



interact(plot_circles_with_procrustes, lambda_=FloatSlider(min=0, max=1, step=0.01))



topicvisexplorer.single_corpus_data['lda_model'][0].print_topics()

vis.run()

 len(topicvisexplorer.single_corpus_data['relevantDocumentsDict'])



StarcoderdataJupyterScriptsDedupFiltered