Bibliographic references from OpenAlex

This notebook downloads a small OpenAlex sample and loads it into NetworkXGraph, Neo4jGraph, MemgraphGraph and JenaGraph.

Dataset notes:

  • papers from an OpenAlex search query

  • author nodes created from authorships

  • citation links are added when both papers are present in the sample

  • if network access is restricted, the loader falls back to bundled demo data

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ó.")
[ ]:
import os

from cvcdocdb import JenaGraph, MemgraphGraph, Neo4jGraph, NetworkXGraph
from cvcdocdb.exemples import load_bibliografia_openalex


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

[ ]:
nx_graph = NetworkXGraph()
nx_stats = load_bibliografia_openalex(nx_graph, query="graph database", per_page=15)
print("NetworkX stats:", nx_stats)

# Show paper data (not just raw IDs)
node_ids = nx_graph.find_nodes_by_property("source", "openalex")[:5]
for nid in node_ids:
    attrs = nx_graph.get_node_attrs(nid)
    print(f"  {attrs.get('main_label', '?')}: {attrs.get('title', attrs.get('name', nid))}")

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_bibliografia_openalex(neo4j_graph, query="graph database", per_page=15)
    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_bibliografia_openalex(memgraph_graph, query="graph database", per_page=15)
    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_bibliografia_openalex(jena_graph, query="graph database", per_page=15)
    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()