def __init__(self, utterance, context, possible_utterances): """Creates a new Utterance. Arguments: utterance (doc?): the word that's spoken context (doc?): the environmental/linguistic context in which the word is spoken possible_utterances (doc?): a set of other words we could have spoken, given the context """ self_update(self, locals())
def __init__(self, grammar, fn, recurse_up=False): """ This manages rules that we add and subtract in the context of grammar generation. This is a class that is somewhat in between Grammar and GrammarRule. It manages creating, adding, and subtracting the bound variable rule via "with" clause in Grammar. NOTE: The "rule" here is the added rule, not the "bound variable" one (that adds the rule) NOTE: If rule is None, then nothing happens This actually could go in FunctionNode, *except* that it needs to know the grammar, which FunctionNodes do not """ self_update(self, locals()) self.added_rules = [ ] # all of the rules we added -- may be more than one from recurse_up=True
def __init__(self, grammar=None, value=None, f=None, maxnodes=25, **kwargs): if 'args' in kwargs: assert False, "*** Use of 'args' is deprecated. Use display='...' instead." # Save all of our keywords self_update(self, locals()) if value is None and grammar is not None: value = grammar.generate() FunctionHypothesis.__init__(self, value=value, f=f, **kwargs) self.likelihood = 0.0 self.rules_vector = None
def __init__(self, nt, name, to, p=1.0, bv_prefix=None): p = float(p) assert p > 0.0, "*** p=0 in rule %s %s %s. What are you thinking?" % ( nt, name, to) self_update(self, locals()) assert to is None or isinstance(to, list) or isinstance( to, tuple), "*** 'to' in a GrammarRule must be a list!" for a in None2Empty(to): assert isinstance(a, str) if name == '': assert (to is None) or (len(to) == 1), \ "*** GrammarRules with empty names must have only 1 argument"
def __init__(self, nt, name, to, p=1.0, bv_prefix="y", bv_type=None, bv_args=None, bv_p=None): p = float(p) self_update(self, locals()) assert bv_type is not None, "Did you mean to use a GrammarRule instead of a BVGrammarRule?" assert isinstance( bv_type, str ), "bv_type must be a string! Make sure it's not a tuple or list."
def __init__(self, current_sample, data, steps=Infinity, proposer=None, skip=0, prior_temperature=1.0, likelihood_temperature=1.0, acceptance_temperature=1.0, trace=False, shortcut_likelihood=True): self_update(self, locals()) self.was_accepted = None if proposer is None: self.proposer = lambda x: x.propose() self.samples_yielded = 0 self.set_state(current_sample, compute_posterior=(current_sample is not None)) self.reset_counters()
def __init__(self, parent, returntype, name, args): self_update(self, locals()) self.added_rule = None assert self.name is None or isinstance(self.name, str)