<jupyter_start><jupyter_text>Community detection<jupyter_code>graph = nx.Graph()
graph.add_edges_from([(l[2], l[3], {'cnt': l[1]}) for l in leg_links.itertuples()])
# Also make a graph withouth the most common nodes
nodes_to_remove = ["Wet op de rechterlijke organisatie, Artikel 81", 
                   "Wet op de rechterlijke organisatie, Artikel 80a",
                   "Wetboek van Strafvordering",
                   "Wetboek van Strafrecht",
                   "Burgerlijk Wetboek Boek 1",
                   "Burgerlijk Wetboek Boek 2",
                   "Burgerlijk Wetboek Boek 3",
                  "Burgerlijk Wetboek Boek 6",
                   "Burgerlijk Wetboek Boek 7",
                  "Algemene wet bestuursrecht",
                  "Opiumwet",
                  "Wetboek van Burgerlijke Rechtsvordering", 
                   "Faillissementswet"]
graph2 = graph.copy()
for n in nodes_to_remove:
    graph2.remove_node(n)
commmunities_weighted = community.best_partition(graph, weight='cnt')
commmunities_unweighted = community.best_partition(graph)
commmunities_weighted_small = community.best_partition(graph, weight='cnt', resolution=0.5)
commmunities_unweighted_small = community.best_partition(graph, resolution=0.5)
communities_weighted2 = community.best_partition(graph2, weight='cnt')
leg_nodes_df = pd.DataFrame()
leg_nodes_df['louvain_weighted'] = pd.Series(commmunities_weighted)
leg_nodes_df['louvain_unweighted'] = pd.Series(commmunities_unweighted)
leg_nodes_df['louvain_weighted_small'] = pd.Series(commmunities_weighted_small)
leg_nodes_df['louvain_unweighted_small'] = pd.Series(commmunities_unweighted_small)
leg_nodes_df['louvain_weighted_sub'] = pd.Series(communities_weighted2)
leg_nodes_df = leg_nodes_df.reset_index().rename(columns={"index": "name"})
leg_nodes_df[leg_nodes_df['name']=="<NAME>"]<jupyter_output><empty_output><jupyter_text>meta info legislation<jupyter_code>leg_nodes_df = leg_nodes_df.set_index(['name'])
leg_nodes_df['nr_references'] = nr_references
leg_nodes_df = leg_nodes_df.reset_index()
leg_nodes_df.head()
leg_nodes_df.to_csv(os.path.join(inputpath, 'leg_to_leg_nodes_min10.tsv'), index=False, sep='\t')
leg_nodes_df.to_csv(os.path.join(inputpath, 'leg_to_leg_nodes_min10.csv'), index=False)
leg_nodes_df['book'] = leg_nodes_df['name'].str.split(',').map(lambda l: l[0])
leg_nodes_df['book'].value_counts()<jupyter_output><empty_output><jupyter_text>look into clusters<jupyter_code>case_to_leg_merged = case_leg.merge(leg_nodes_df, left_on='title', right_on='name')
case_to_leg_merged.head()
com_name = 'louvain_weighted_sub'

grouped_by_com = leg_nodes_df.groupby(com_name)
community_summary = pd.DataFrame()
community_summary['nodes'] = grouped_by_com['name'].apply(lambda l: "|".join(list(sorted(l))))
community_summary['nr_leg_nodes'] = grouped_by_com['name'].nunique()
community_summary['nr_cases'] = case_to_leg_merged.groupby(com_name)['source'].nunique()
community_summary = community_summary.sort_values('nr_cases', ascending=False)
community_summary.head(50)
community_summary.to_csv(os.path.join(inputpath, 'leg_to_leg_communities.csv'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12456307594534477, 'fraction_numerical': 0.008897362567524627, 'mean_word_length': 5.7844827586206895, 'pattern_counts': {'":': 1, '<': 14, '<?xml version=': 0, '>': 14, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '156931', 'license': 'Apache-2.0', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1102, 'n_words': 154, 'path': 'notebooks/archived/Leg-to-leg network.ipynb', 'repo_name': 'caselawanalytics/case-law-research', 'size': '3163'}