| import json
|
| import networkx as nx
|
| import community as community_louvain
|
|
|
| def main():
|
|
|
| with open('arxiv2023_1624-10.json', 'r', encoding='utf-8') as f:
|
| data = json.load(f)
|
|
|
|
|
| nodes_count = len(data)
|
| classes = set()
|
| train_nodes_count = 0
|
| validation_nodes_count = 0
|
| test_nodes_count = 0
|
|
|
|
|
| G = nx.Graph()
|
|
|
|
|
| for entry in data:
|
| node_id = entry['node_id']
|
| label = entry['label']
|
| mask = entry['mask']
|
|
|
|
|
| classes.add(label)
|
|
|
|
|
| G.add_node(node_id, label=label, mask=mask)
|
|
|
|
|
| if mask == 'Train':
|
| train_nodes_count += 1
|
| elif mask == 'Validation':
|
| validation_nodes_count += 1
|
| elif mask == 'Test':
|
| test_nodes_count += 1
|
|
|
|
|
| neighbors = set(entry['neighbors'])
|
| for neighbor in neighbors:
|
|
|
| if neighbor != node_id:
|
| G.add_edge(node_id, neighbor)
|
|
|
|
|
|
|
| edge_count = G.number_of_edges()
|
| classes_count = len(classes)
|
|
|
|
|
| partition = community_louvain.best_partition(G)
|
| communities = set(partition.values())
|
| community_count = len(communities)
|
|
|
|
|
| print("Nodes count:", nodes_count)
|
| print("Edges count:", edge_count)
|
| print("Classes count:", classes_count)
|
| print("Train nodes count:", train_nodes_count)
|
| print("Validation nodes count:", validation_nodes_count)
|
| print("Test nodes count:", test_nodes_count)
|
| print("Louvain community count:", community_count)
|
|
|
| if __name__ == '__main__':
|
| main()
|
|
|