From a3e9906b706ad197dcb7ac1b81e5c491f711b0d0 Mon Sep 17 00:00:00 2001 From: everythingfades Date: Tue, 27 Jan 2026 23:11:31 +0000 Subject: [PATCH 1/2] fix: fix the transform from FSAFrontend to FSA --- evaluation_function/schemas/fsaFrontend.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/evaluation_function/schemas/fsaFrontend.py b/evaluation_function/schemas/fsaFrontend.py index 5292b10..0550ee6 100644 --- a/evaluation_function/schemas/fsaFrontend.py +++ b/evaluation_function/schemas/fsaFrontend.py @@ -69,17 +69,17 @@ class Config: } @classmethod - def toFSA(cls, data: dict) -> FSA: + def toFSA(cls) -> FSA: """ Convert frontend FSA payload (with transitions as "from|symbol|to") into the FSABackend model with proper Transition objects. """ - states = data.get("states", []) - alphabet = data.get("alphabet", []) - initial_state = data.get("initial_state", "q0") - accept_states = data.get("accept_states", []) + states = cls.states + alphabet = cls.alphabet + initial_state = cls.initial_state + accept_states = cls.accept_states - flat_transitions = data.get("transitions", []) + flat_transitions = cls.transitions transitions: List[Transition] = [] for t in flat_transitions: try: From be5f8186235a5b110ab6278080f4cdfdf284fa3f Mon Sep 17 00:00:00 2001 From: everythingfades Date: Tue, 27 Jan 2026 23:31:44 +0000 Subject: [PATCH 2/2] fix: fix the transform from FSAFrontend to FSA --- evaluation_function/schemas/fsaFrontend.py | 68 ++++++++++++++-------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/evaluation_function/schemas/fsaFrontend.py b/evaluation_function/schemas/fsaFrontend.py index 0550ee6..1073aad 100644 --- a/evaluation_function/schemas/fsaFrontend.py +++ b/evaluation_function/schemas/fsaFrontend.py @@ -68,32 +68,52 @@ class Config: } } - @classmethod - def toFSA(cls) -> FSA: - """ - Convert frontend FSA payload (with transitions as "from|symbol|to") - into the FSABackend model with proper Transition objects. - """ - states = cls.states - alphabet = cls.alphabet - initial_state = cls.initial_state - accept_states = cls.accept_states - - flat_transitions = cls.transitions + def toFSA(self) -> FSA: transitions: List[Transition] = [] - for t in flat_transitions: - try: - from_state, symbol, to_state = t.split("|") - transitions.append( - Transition(from_state=from_state, symbol=symbol, to_state=to_state) + + for t in self.transitions: + parts = t.split("|") + + # allow trailing delimiter but enforce structure + if len(parts) == 4 and parts[-1] == "": + parts = parts[:-1] + + if len(parts) != 3: + raise ValueError( + f"Invalid transition format '{t}'. " + "Expected 'from|symbol|to'" ) - except ValueError: - raise ValueError(f"Invalid transition format: '{t}'") + + from_state, symbol, to_state = parts + + if from_state not in self.states: + raise ValueError(f"Unknown from_state '{from_state}'") + + if to_state not in self.states: + raise ValueError(f"Unknown to_state '{to_state}'") + + if symbol not in self.alphabet: + raise ValueError(f"Symbol '{symbol}' not in alphabet") + + transitions.append( + Transition( + from_state=from_state, + symbol=symbol, + to_state=to_state, + ) + ) + + if self.initial_state not in self.states: + raise ValueError("initial_state must be in states") + + for s in self.accept_states: + if s not in self.states: + raise ValueError(f"Accept state '{s}' not in states") return FSA( - states=states, - alphabet=alphabet, + states=self.states, + alphabet=self.alphabet, transitions=transitions, - initial_state=initial_state, - accept_states=accept_states, - ) + initial_state=self.initial_state, + accept_states=self.accept_states, + ) \ No newline at end of file