Karate Club dataset
This notebook shows the classic Zachary Karate Club network loaded into NetworkXGraph, Neo4jGraph, MemgraphGraph and JenaGraph using the shared loader in cvcdocdb.exemples.
Dataset notes:
34 members
classic community-detection benchmark
clubattribute is used to build club nodes
The server sections need a running server each: skip the ones you don’t have. They read NEO4J_*, MEMGRAPH_URL/MEMGRAPH_USER/MEMGRAPH_PASSWORD and FUSEKI_URL/FUSEKI_USER/FUSEKI_PASSWORD (defaults: bolt://localhost:7687 and http://localhost:3030/ds).
[ ]:
import importlib.util
# Comprovació de presència del paquet, amb l'extra [notebook] del visualitzador de grafs (anywidget)
if (importlib.util.find_spec("cvcdocdb") is None
or importlib.util.find_spec("cvcdocdb.viewer") is None
or importlib.util.find_spec("anywidget") is None):
print("⚠️ cvcdocdb[notebook] no està instal·lat. Iniciant instal·lació...")
%pip install -q --upgrade "cvcdocdb[notebook]"
print("✅ Instal·lació completada. L'estat del kernel PODRIA requerir un reinici.")
else:
print("✅ cvcdocdb i anywidget ja són presents al sistema. Saltant instal·lació.")
[7]:
import os
from cvcdocdb import JenaGraph, MemgraphGraph, Neo4jGraph, NetworkXGraph
from cvcdocdb.exemples import load_karate_club
def neo4j_config(default_target="DEV"):
target = os.environ.get("NEO4J_TARGET", default_target).upper()
prefix = f"NEO4J_{target}_"
return {
"target": target,
"url": os.environ.get(f"{prefix}URL", os.environ.get("NEO4J_URL", "bolt://localhost:7687")),
"user": os.environ.get(f"{prefix}USER", os.environ.get("NEO4J_USER", "neo4j")),
"password": os.environ.get(f"{prefix}PASSWORD", os.environ.get("NEO4J_PASSWORD", "secret")),
"database": os.environ.get(f"{prefix}DATABASE", os.environ.get("NEO4J_DATABASE", "neo4j")),
}
NetworkXGraph
[8]:
nx_graph = NetworkXGraph()
nx_stats = load_karate_club(nx_graph)
print("NetworkX stats:", nx_stats)
print("NetworkX nodes:", len(nx_graph.get_nodes()))
print("NetworkX edges:", len(nx_graph.get_edges()))
NetworkX stats: {'members': 34, 'clubs': 2, 'interacts': 78, 'member_of': 34}
NetworkX nodes: 36
NetworkX edges: 112
Explore the graph
show() opens the cvcdocdb graph viewer on this graph. Click a node to see its properties, double-click it to expand its neighbours, and search or filter from the sidebar. The viewer reads the graph live from the kernel, so the graph is only closed in the last cell, once you are done.
[ ]:
from cvcdocdb.viewer import show
show(nx_graph, load_all=True)
Neo4jGraph
[ ]:
cfg = neo4j_config()
print("Using Neo4j target:", cfg["target"])
neo4j_graph = Neo4jGraph(
url=cfg["url"],
user=cfg["user"],
password=cfg["password"],
database=cfg["database"],
)
try:
neo4j_stats = load_karate_club(neo4j_graph)
print("Neo4j stats:", neo4j_stats)
finally:
neo4j_graph.close()
MemgraphGraph
Same API and behaviour as Neo4jGraph.
[ ]:
memgraph_url = os.environ.get("MEMGRAPH_URL", "bolt://localhost:7687")
print("Using Memgraph:", memgraph_url)
memgraph_graph = MemgraphGraph(
memgraph_url,
os.environ.get("MEMGRAPH_USER", ""),
os.environ.get("MEMGRAPH_PASSWORD", ""),
)
try:
memgraph_stats = load_karate_club(memgraph_graph)
print("Memgraph stats:", memgraph_stats)
finally:
memgraph_graph.close()
JenaGraph
The graph is stored as RDF 1.2 in an Apache Jena Fuseki dataset (Fuseki >= 6.2.0).
[ ]:
fuseki_url = os.environ.get("FUSEKI_URL", "http://localhost:3030/ds")
print("Using Fuseki:", fuseki_url)
jena_graph = JenaGraph(fuseki_url, os.environ.get("FUSEKI_USER"), os.environ.get("FUSEKI_PASSWORD"))
try:
jena_stats = load_karate_club(jena_graph)
print("Jena stats:", jena_stats)
finally:
jena_graph.close()
Cleanup
Closing the graph empties it, and the viewer with it: run this once you are done exploring.
[ ]:
# nx_graph.close()