Commit f409167b authored by Paul Fiterau Brostean's avatar Paul Fiterau Brostean
Browse files

Added provisional fix to problem

parent bc84e65e
from abc import ABCMeta, abstractmethod
from typing import List, Generator, Iterable, Tuple
from typing import List, Generator, Iterable, Tuple, Set
import itertools
from model import Automaton, Acceptor, Transducer
......@@ -17,6 +17,10 @@ class Test(metaclass=ABCMeta):
def check(self, model:Automaton):
"""checks if the hyp passes the test. On failure, it returns a minimal trace to be added by the learner.
On success it return None"""
# TODO this is a quick fix to the problem of not having a predefined alphabet from the very start.
# if the trace contains new labels, then we return whole trace
if len(self.input_labels().difference(model.input_labels())) != 0:
return self._check_trace(model,
......@@ -36,6 +40,27 @@ class Test(metaclass=ABCMeta):
def covers(self, test) -> bool:
def inputs(self) -> List[object]:
def input_labels(self) -> Set[object]:
"""generates all the input labels in the test trace. Used to verify that model contains all test input labels"""
inputs = self.inputs()
input_labels = set()
for inp in inputs:
# if it's RA stuff
if isinstance(inp, Action):
(label, _) = inp
elif isinstance(inp, str):
label = inp
raise Exception("Unrecognized type")
return input_labels
class EqualTestsMixin(metaclass=ABCMeta):
"""doesn't work unfortunately"""
def __eq__(self, other):
......@@ -131,6 +156,9 @@ class TransducerTest(Test):
def size(self):
return len(
def inputs(self):
return [inp for (inp, _) in]
def covers(self, test):
if type(test) is type(self) and len(test.trace()) <= len(self.trace()):
for ((inp, _),(inp2, _)) in zip(self.trace(), test.trace()):
......@@ -186,6 +214,10 @@ class AcceptorTest(Test):
(seq, acc) =
return len(seq)
def inputs(self):
(seq, acc) =
return seq
def __hash__(self):
(seq, acc) =
return hash((type(self), frozenset(seq), acc))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment