Skip to content

Commit d533995

Browse files
authored
fix: don't break because of note not being None (support E_0594) (#384)
1 parent 5f924d8 commit d533995

File tree

5 files changed

+3068
-4
lines changed

5 files changed

+3068
-4
lines changed

src/rebdhuhn/graph_conversion.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import Dict, List, Literal, Optional, overload
66

7-
from networkx import DiGraph # type:ignore[import-untyped]
7+
from networkx import DiGraph, isolates # type:ignore[import-untyped]
88

99
from rebdhuhn.models import (
1010
DecisionNode,
@@ -60,9 +60,7 @@ def _convert_sub_row_to_outcome_node(sub_row: EbdTableSubRow) -> Optional[Outcom
6060
if is_hinweis and sub_row.result_code is None and following_step:
6161
# We ignore Hinweise, if they are in during a decision process.
6262
return None
63-
if sub_row.check_result.subsequent_step_number is not None and (
64-
sub_row.result_code is not None or sub_row.note is not None
65-
):
63+
if sub_row.check_result.subsequent_step_number is not None and sub_row.result_code is not None:
6664
raise OutcomeCodeAndFurtherStepError(sub_row=sub_row)
6765
if sub_row.result_code is not None or sub_row.note is not None and not is_cross_reference:
6866
return OutcomeNode(result_code=sub_row.result_code, note=sub_row.note)
@@ -221,6 +219,7 @@ def convert_table_to_graph(table: EbdTable) -> EbdGraph:
221219
if not any(table.rows):
222220
return convert_empty_table_to_graph(table.metadata)
223221
graph = convert_table_to_digraph(table)
222+
_apply_workaround_to_issue_383(graph)
224223
graph_metadata = EbdGraphMetaData(
225224
ebd_code=table.metadata.ebd_code,
226225
chapter=table.metadata.chapter,
@@ -231,6 +230,16 @@ def convert_table_to_graph(table: EbdTable) -> EbdGraph:
231230
return EbdGraph(metadata=graph_metadata, graph=graph, multi_step_instructions=table.multi_step_instructions)
232231

233232

233+
def _apply_workaround_to_issue_383(graph: DiGraph) -> None:
234+
"""
235+
removes isolated hinweis nodes which are not connected to the graph, e.g. 'Es gibt 1..n Treffer'...
236+
Ideally we'd not create them at all, then we wouldn't have to remove them in a post processing step.
237+
https://github.com/Hochfrequenz/rebdhuhn/issues/383
238+
"""
239+
isolated = list(isolates(graph))
240+
graph.remove_nodes_from(isolated)
241+
242+
234243
def convert_empty_table_to_graph(metadata: EbdTableMetaData) -> EbdGraph:
235244
"""
236245
Converts an ebd section with no table to a graph to capture hints.

0 commit comments

Comments
 (0)