def predict_input(asker, view): lines = fields.get(asker, lines_field(), view) h = asker.ask(state.get_history()).firm_answer response = asker.ask(fields.get_field(dictionaries.image(lines), h)) if response.has_answer(): return asker.reply(answer=response.answer) else: input = asker.ask_firmly(elicit(view)) asker.ask(state.update_state(updates.apply_to_field( state.history(), updates.set_field( dictionaries.image(lines), input ) ))) return asker.reply(answer=input)
def set_referent(asker, rep, new_value, s): import updates, dictionaries return asker.ask_tail(updates.apply_update( updates.set_field( fields.compose(bindings(), dictionaries.image(s)), new_value ), rep ))
def bind_variable(asker, view, name, value): return asker.reply(answer=updates.update( updates.apply_to_field( bindings_field(), updates.set_field( dictionaries.image(name), value ) ), view ))
def interpret_raw(asker, view, text, bindings): #FIXME I think that most field lookups should be done implicitly variable_bindings = fields.get(asker, bindings_field(), view) lookup_value = asker.ask(fields.get_field( dictionaries.image(text), variable_bindings )) if lookup_value.has_answer(): return asker.reply(answer=lookup_value.answer) update_bindings = dictionaries.map( computations.apply_to_single( computations.askQ_literal(interpret_expression( computations.quote(view), computations.getvar(computations.quote(computations.x_var)) )), computations.x_var ) ) return asker.reply(answer=representations.quoted_term( text, functions.apply(update_bindings, bindings) )) #FIXME should have other answers soon, not everything should be held... return elicit_meaning(text, view, functions.apply(update_bindings, bindings))
def getvar(asker, bindings, variable): return asker.ask_tail(fields.get_field(dictionaries.image(variable), bindings))
def get_referent(asker, rep, s): import dictionaries return asker.ask_tail(fields.get_field( fields.compose(bindings(), dictionaries.image(s)), rep ))
def referent_of(s): import dictionaries return fields.compose(bindings(), dictionaries.image(s))
def reduce_referent_of(asker, s): import dictionaries return asker.reply(answer=fields.compose(representations.bindings(), dictionaries.image(s)))