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:
objectA 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
networkxdirected 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: - appliance_ref (str) – A CBR Appliance reference
- appliance (dict[str, Any]) – Dictionary representing a CBR Appliance
-
add_ingredient(ingredient_ref: str, ingredient: Dict[str, Any]) → None[source]¶ Adds an ingredient to the graph.
Parameters: - ingredient_ref (str) – A CBR Ingredient reference
- ingredient (dict[str, Any]) – Dictionary representing a CBR Ingredient
-
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
-
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]
- g (networkx.classes.digraph.DiGraph) – An instance of a