def __init__(self, domain, assignment=None): dict.__init__(self) self.domain = domain if assignment: for var in assignment.keys(): val = assignment[var] assert val in self.domain,\ "'%s' is not in the domain: %s" % (val, self.domain) assert is_indvar(var),\ "Wrong format for an Individual Variable: '%s'" % var self.update(assignment) self._addvariant()
def add(self, val, var): """ Add a new variable-value pair to the assignment, and update C{self.variant}. We write the arguments in the order 'val, var' by analogy with the notation 'g[u/x]'. """ assert val in self.domain,\ "%s is not in the domain %s" % (val, self.domain) assert is_indvar(var),\ "Wrong format for an Individual Variable: '%s'" % var self[var] = val self._addvariant() return self
def __init__(self, valuation=None): dict.__init__(self) if valuation: for k in valuation.keys(): if is_indvar(k): raise Error, "This looks like an individual variable: '%s'" % k # Check if the valuation is of the form {'p': True} if isinstance(valuation[k], bool): self[k] = valuation[k] else: try: cf = CharFun(valuation[k]) self[k] = cf except (TypeError, ValueError): self[k] = valuation[k]
def read(self, seq): """ Parse a list such as C{[('j', 'b1'), ('girl', set(['g1', 'g2']))]} into a L{Valuation}. @rtype: L{Valuation} @param seq: A list of tuples of the form (I{constant}, I{relation}), where I{relation} is a set of tuples. """ d = dict(seq) for k in d.keys(): if is_indvar(k): raise Error, "This looks like an individual variable: '%s'" % k val = d[k] if isinstance(val, str): pass else: cf = CharFun() cf.read(d[k]) d[k] = cf self.update(d)