diff options
Diffstat (limited to 'ricky/param')
| -rw-r--r-- | ricky/param/probabilities.py | 21 | ||||
| -rw-r--r-- | ricky/param/probability.py | 9 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ricky/param/probabilities.py b/ricky/param/probabilities.py new file mode 100644 index 0000000..d109b18 --- /dev/null +++ b/ricky/param/probabilities.py @@ -0,0 +1,21 @@ +from ricky.param.probability import Probability +import sys +class Probabilities: + def __init__(self, *args): + self._values = args + def __iter__(self): + return iter(self._values) + def __len__(self): + return len(self._values) + def __str__(self): + return str(self._values) + def __getitem__(self, i): + return self._values[i] + def search(self, s): + for i in self: + if str(s) in i.value: + return i + @classmethod + def from_dict(cls, *args): + probabilities = map(lambda x: Probability(**x), args); + return cls(*probabilities); diff --git a/ricky/param/probability.py b/ricky/param/probability.py new file mode 100644 index 0000000..0d27b70 --- /dev/null +++ b/ricky/param/probability.py @@ -0,0 +1,9 @@ +class Probability(dict): + def __init__(self, **kwargs): + super(Probability, self).__init__(**kwargs) + self.value = kwargs["value"] + self.weight = kwargs["weight"] + def __getattr__(self, attr): + return self.get(attr) + __setattr__= dict.__setitem__ + __delattr__= dict.__delitem__ |
