cookbase.graph

Module contents

The cookbase.graph package provides an API for the analysis and manipulation the different graph topologies involved in the Cookbase platform.

Submodules

cookbase.graph.cbrgraph

class cookbase.graph.cbrgraph.CBRGraph[source]

Bases: object

A class that provides the structures and methods needed to build, manipulate and analyze Cookbase Recipe Graphs (CBRGraphs).

Typically, a CBRGraph is generated by extracting the data from a complete traversal of a Cookbase Recipe (CBR). It makes use of the NetworkX graph manipulation package.

Variables:
  • g (networkx.classes.digraph.DiGraph) – An instance of a networkx directed graph
  • _appliances (dict[str]) – A dictionary of appliance references included in the recipe
  • _pending_processes_edges (list[tuple[str, str]]) – A list of 2-tuples denoting the edges pending to be added
add_appliance(appliance_ref: str, appliance: Dict[str, Any]) → None[source]

Adds an appliance to the graph.

Parameters:
add_ingredient(ingredient_ref: str, ingredient: Dict[str, Any]) → None[source]

Adds an ingredient to the graph.

Parameters:
add_process(process_ref: str, process: Dict[str, Any]) → None[source]

Adds a process and its in-edges to the graph.

Parameters:
  • process_ref (str) – A CBR Process reference
  • process (dict[str, Any]) – Dictionary representing a CBR Process
aggregated_appliances_graph() → networkx.classes.digraph.DiGraph[source]

Returns a graph where each node represents a concurrent preparation path of a CBRGraph, containing an inverted index on the appliances used in that path together with the list of processes that used it.

Returns:An aggregated appliances graph
Return type:networkx.classes.digraph.DiGraph
build_graph(data: Dict[str, Any]) → None[source]

Adds a process and its in-edges to the graph.

Parameters:data (dict[str, Any]) – A dictionary containing all the data from a CBR
clear() → None[source]

Clears the graph and internal structures.

get_ingredients() → List[Hashable][source]

Returns the list of nodes representing ingredients in the CBRGraph.

Returns:The list of ingredient nodes in the CBRGraph
Return type:list[Hashable]
get_leaf_processes() → List[Hashable][source]

Returns the list of leaf nodes from the processes’ subgraph.

Returns:The list of process leaf nodes from the processes’ subgraph.
Return type:list[Hashable]
get_processes() → List[Hashable][source]

Returns the list of nodes representing processes in the CBRGraph.

Returns:The list of process nodes in the CBRGraph
Return type:list[Hashable]
get_root_processes() → List[Hashable][source]

Returns the list of root nodes from the processes’ subgraph.

Returns:The list of process root nodes from the processes’ subgraph
Return type:list[Hashable]
get_serializable_graph() → Dict[str, Any][source]

Returns the CBRGraph data in a JSON-serializable format.

Returns:A dict with the CBRGraph data
Return type:dict[str, Any]
path_joining_processes() → List[Hashable][source]

Returns the list of process nodes that represent a junction point of two or more preparation paths.

Returns:The list of merging process nodes from the processes’ subgraph
Return type:list[Hashable]
processes_subgraph_view() → networkx.classes.digraph.DiGraph[source]

Returns the subgraph view of the CBRGraph including only its processes.

Returns:The processes’ subgraph view from the CBRGraph
Return type:networkx.classes.digraph.DiGraph
resolve_pending_processes_edges() → None[source]

Attempts to add edges that could not have been added to the graph before.