# ---
# 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
# ---

# Install latest version from GitHub
# !pip install -q -U git+https://github.com/jdvelasq/techminer

# # Ocurrence

# +
import matplotlib.pyplot as plt
import pandas as pd

from techminer import DataFrame, Plot, heatmap, Map

#
# Data loading
#
df = DataFrame(
    pd.read_json(
        "https://raw.githubusercontent.com/jdvelasq/techminer/master/data/tutorial/"
        + "cleaned-data.json",
        orient="records",
        lines=True,
    )
)

#
# Columns of the dataframe
#
df.columns
# -

# ## Authors

top_authors = df.documents_by_term("Authors").head(10).Authors
top_authors

matrix = df.occurrence(column="Authors", as_matrix=True)
matrix = matrix.loc[top_authors, top_authors]
heatmap(matrix)

plt.figure(figsize=(10, 8))
Plot(matrix).heatmap(cmap='Blues')

plt.figure(figsize=(10, 10))
dic1 = df.occurrence_map(column="Authors", include_only=top_authors)
dic2 = dict(
    term_props={"node_color": "red"},
    label_docs_props={"color": "k"},
    label_term_props=dict(ma="left", rotation=0, fontsize=10, disp=3, bbox=None),
)
kwargs = {**dic1, **dic2}
Map().ocurrence_map(**kwargs)

# ## Keywords

#
# Analysis for top 10 most frequent keywords
#
top_keywords = df.documents_by_term("keywords_cleaned", sep=';').head(10).keywords_cleaned
top_keywords

matrix = df.occurrence(column="keywords_cleaned", sep=';', as_matrix=True)
matrix = matrix.loc[top_keywords, top_keywords]
heatmap(matrix)

plt.figure(figsize=(9, 8))
Plot(matrix).heatmap(cmap='Blues')

StarcoderdataJupyterScriptsDedupFiltered