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 abc import ABCMeta, abstractmethod
from typing import List, Generator, Iterable, Tuple from typing import List, Generator, Iterable, Tuple, Set
import itertools import itertools
from model import Automaton, Acceptor, Transducer from model import Automaton, Acceptor, Transducer
...@@ -17,6 +17,10 @@ class Test(metaclass=ABCMeta): ...@@ -17,6 +17,10 @@ class Test(metaclass=ABCMeta):
def check(self, model:Automaton): 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. """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""" 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.tr
return self._check_trace(model, self.tr) return self._check_trace(model, self.tr)
@abstractmethod @abstractmethod
...@@ -36,6 +40,27 @@ class Test(metaclass=ABCMeta): ...@@ -36,6 +40,27 @@ class Test(metaclass=ABCMeta):
def covers(self, test) -> bool: def covers(self, test) -> bool:
pass pass
@abstractmethod
def inputs(self) -> List[object]:
pass
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
else:
raise Exception("Unrecognized type")
input_labels.add(label)
return input_labels
class EqualTestsMixin(metaclass=ABCMeta): class EqualTestsMixin(metaclass=ABCMeta):
"""doesn't work unfortunately""" """doesn't work unfortunately"""
def __eq__(self, other): def __eq__(self, other):
...@@ -131,6 +156,9 @@ class TransducerTest(Test): ...@@ -131,6 +156,9 @@ class TransducerTest(Test):
def size(self): def size(self):
return len(self.tr) return len(self.tr)
def inputs(self):
return [inp for (inp, _) in self.tr]
def covers(self, test): def covers(self, test):
if type(test) is type(self) and len(test.trace()) <= len(self.trace()): if type(test) is type(self) and len(test.trace()) <= len(self.trace()):
for ((inp, _),(inp2, _)) in zip(self.trace(), test.trace()): for ((inp, _),(inp2, _)) in zip(self.trace(), test.trace()):
...@@ -186,6 +214,10 @@ class AcceptorTest(Test): ...@@ -186,6 +214,10 @@ class AcceptorTest(Test):
(seq, acc) = self.tr (seq, acc) = self.tr
return len(seq) return len(seq)
def inputs(self):
(seq, acc) = self.tr
return seq
def __hash__(self): def __hash__(self):
(seq, acc) = self.tr (seq, acc) = self.tr
return hash((type(self), frozenset(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