Getting Started with CVCDocDB

Minimal end-to-end graph workflow with NetworkXGraph and WeakNode.

[ ]:
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ó.")
[2]:
from cvcdocdb import NetworkXGraph, Node, WeakNode

graph = NetworkXGraph()
doc = Node(pk={"doc": "DOC-001"}, main_label="Document")
section = WeakNode(parent=doc, pk={"section": 1}, main_label="Section")
graph.insertNode(doc, replace=True)
graph.insertNode(section, insert_parent=True)
print(graph.get_nodes())
[1, 2]

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.

load_all=True draws every node and relation; the HAS relation links the section to its document.

[ ]:
from cvcdocdb.viewer import show

show(graph, load_all=True)

Cleanup

Closing the graph empties it, and the viewer with it: run this once you are done exploring.

[ ]:
# graph.close()