Skip to content

Commit 82ec09d

Browse files
authored
fix: note comparison ambiguous outcome nodes whitespace insensitive (#389)
1 parent 901844e commit 82ec09d

File tree

8 files changed

+38
-282
lines changed

8 files changed

+38
-282
lines changed

src/rebdhuhn/graph_conversion.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module contains logic to convert EbdTable data to EbdGraph data.
33
"""
44

5+
import re
56
from typing import Dict, List, Literal, Optional, overload
67

78
from networkx import DiGraph, isolates # type:ignore[import-untyped]
@@ -143,6 +144,15 @@ def _get_key_and_node_with_lowest_step_number(ebd_table: EbdTable) -> tuple[str,
143144
return str(lowest_numeric_key), nodes[str(lowest_numeric_key)]
144145

145146

147+
def _notes_same_except_for_whitespace(note1: str | None, note2: str | None) -> bool:
148+
"""
149+
Checks if two notes are the same except for whitespace characters.
150+
"""
151+
if note1 is not None and note2 is not None:
152+
return re.sub(r"\s+", "", note1) == re.sub(r"\s+", "", note2)
153+
return note1 is None and note2 is None
154+
155+
146156
def get_all_edges(table: EbdTable) -> List[EbdGraphEdge]:
147157
"""
148158
Returns a list with all edges from the given table.
@@ -188,7 +198,9 @@ def get_all_edges(table: EbdTable) -> List[EbdGraphEdge]:
188198
# check for ambiguous outcome nodes, i.e. A** with different notes
189199
is_ambiguous_outcome_node = (
190200
outcome_node.result_code in outcome_nodes_duplicates
191-
and outcome_nodes_duplicates[outcome_node.result_code].note != outcome_node.note
201+
and not _notes_same_except_for_whitespace(
202+
outcome_nodes_duplicates[outcome_node.result_code].note, outcome_node.note
203+
)
192204
)
193205

194206
if not is_ambiguous_outcome_node:

unittests/output/E_0003.dot.svg

Lines changed: 1 addition & 27 deletions
Loading

unittests/output/E_0003_with_watermark_background_is_False.dot.svg

Lines changed: 1 addition & 27 deletions
Loading

unittests/output/E_0003_with_watermark_background_is_True.dot.svg

Lines changed: 1 addition & 27 deletions
Loading

0 commit comments

Comments
 (0)