ExposoGraph.engine

NetworkX-backed graph engine for building and querying the knowledge graph.

GraphEngine.load(...) and GraphEngine.merge(...) both accept a mode argument:

  • exploratory keeps provisional content after grounding

  • strict merges only canonically grounded content and returns warnings for dropped items

The engine is backed by a NetworkX MultiDiGraph and preserves parallel edges. Distinct evidence edges with the same source, predicate, and target are kept as separate graph edges instead of replacing earlier records.

class ExposoGraph.engine.GraphEngine[source]

Bases: object

Thin wrapper around a NetworkX MultiDiGraph that speaks our domain model.

add_node(node)[source]
Parameters:

node (Node)

Return type:

None

add_edge(edge)[source]
Parameters:

edge (Edge)

Return type:

None

remove_node(node_id)[source]
Parameters:

node_id (str)

Return type:

None

remove_edge(source, target, key=None)[source]
Parameters:
Return type:

None

load(kg, *, mode=GraphMode.EXPLORATORY)[source]

Replace the current graph with kg.

Clears all existing nodes and edges before loading. Returns a list of warning messages for any skipped edges.

Parameters:
Return type:

list[str]

merge(kg, *, mode=GraphMode.EXPLORATORY)[source]

Additive merge — new nodes/edges are added, existing ones updated.

Returns a list of warning messages for any skipped edges.

Parameters:
Return type:

list[str]

clear()[source]
Return type:

None

property node_count: int
property edge_count: int
get_node(node_id)[source]
Parameters:

node_id (str)

Return type:

dict[str, Any] | None

neighbors(node_id)[source]
Parameters:

node_id (str)

Return type:

list[str]

nodes_by_type(node_type)[source]
Parameters:

node_type (str)

Return type:

list[dict[str, Any]]

to_dict()[source]
Return type:

dict[str, list[Any]]

to_knowledge_graph()[source]
Return type:

KnowledgeGraph

to_json(indent=2)[source]
Parameters:

indent (int)

Return type:

str

validate()[source]
Return type:

list[str]