Skip to content

Commit 1ac2cf2

Browse files
committed
refactoring correctnes code
1 parent 9067e38 commit 1ac2cf2

3 files changed

Lines changed: 11 additions & 39 deletions

File tree

src/hyperbase/correctness.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,14 @@ def _check_edge(edge: Hyperedge) -> dict[Hyperedge, list[tuple[str, str]]]:
108108
)
109109

110110
ars_counts = Counter(ars)
111-
if ars_counts["s"] > 1:
112-
errors.append(
113-
("argrole-s-1-max", "argrole s can only be used once")
114-
)
115-
if ars_counts["o"] > 1:
116-
errors.append(
117-
("argrole-o-1-max", "argrole o can only be used once")
118-
)
119-
if ars_counts["c"] > 1:
120-
errors.append(
121-
("argrole-c-1-max", "argrole c can only be used once")
122-
)
123-
if ars_counts["i"] > 1:
124-
errors.append(
125-
("argrole-i-1-max", "argrole i can only be used once")
126-
)
127-
if ars_counts["p"] > 1:
128-
errors.append(
129-
("argrole-p-1-max", "argrole p can only be used once")
130-
)
131-
if ars_counts["a"] > 1:
132-
errors.append(
133-
("argrole-a-1-max", "argrole a can only be used once")
134-
)
111+
for role in "socipam":
112+
if ars_counts[role] > 1:
113+
errors.append(
114+
(
115+
f"argrole-{role}-1-max",
116+
f"argrole {role} can only be used once",
117+
)
118+
)
135119
else:
136120
errors.append(
137121
(

src/hyperbase/parsers/correctness.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections import Counter
43
from typing import Any
54

65
from hyperbase.hyperedge import Hyperedge
@@ -21,7 +20,6 @@ def _visit(current_edge: Hyperedge) -> None:
2120
# Argrole checks
2221
try:
2322
ars = current_edge.argroles()
24-
ar_counts: Counter[str] = Counter()
2523
for ar in ars:
2624
if ar not in "mspaoixtjrc":
2725
current_errors.append(
@@ -32,17 +30,7 @@ def _visit(current_edge: Hyperedge) -> None:
3230
2,
3331
)
3432
)
35-
ar_counts[ar] += 1
3633

37-
for role in "spoiamc":
38-
if ar_counts[role] > 1:
39-
current_errors.append(
40-
(
41-
f"duplicate-argrole-{role}",
42-
f"Argument role '{role}' should only be used once.",
43-
2,
44-
)
45-
)
4634
except Exception:
4735
pass
4836

tests/test_correctness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ def test_duplicate_argrole(self):
282282
for _k, v in errors.items():
283283
if isinstance(v, list):
284284
for err in v:
285-
if isinstance(err, tuple) and err[0] == "duplicate-argrole-s":
285+
if isinstance(err, tuple) and err[0] == "argrole-s-1-max":
286286
assert len(err) == 3
287-
assert err[2] == 2
287+
assert err[2] == 0
288288
found = True
289289
break
290-
assert found, "Should detect duplicate argrole 's' with severity 2"
290+
assert found, "Should detect duplicate argrole 's'"
291291

292292
def test_invalid_junction_mixed(self):
293293
# Mixed types C and R

0 commit comments

Comments
 (0)