def keep_strip(keep=None, strip=None): if keep is None: keep = properties.trivial() if strip is None: strip = properties.trivial() return properties.both( fields.field_value(to_keep(), keep), fields.field_value(to_strip(), strip) )
def both_stripper(asker, update, object, a, b): keeps = properties.trivial() strips = properties.trivial() for x in [a, b]: keep_or_strip = asker.ask(modifiers_to_strip(update, x, object)).value new_keeps = fields.get(asker, fields.implication_about(to_keep()), keep_or_strip) keeps = properties.both(keeps, new_keeps) new_strips = fields.get(asker, fields.implication_about(to_strip()), keep_or_strip) strips = properties.both(strips, new_strips) return asker.reply(value=keep_strip(keep=keeps, strip=strips))
def process_response(self, response, *args, **kwargs): if response.head == queries.head: #TODO could easily do this inside the system self.cost += response['k'].to_int() return properties.trivial() else: return super(Counter, self).process_response(response, *args, **kwargs)
def __init__(self, value=None, answer=None, question=None): self.question = question if value is None: value = properties.trivial() if answer is not None: value = properties.both(answer_is(answer), value) self.value = value
def print_string(s): view_in = asker.refresh(view) asker.update(add_line(input), view_in) #FIXME more things going wrong with representation levels... s = convert.unquote(asker, s) line = asker.ask_firmly(render(s)) asker.update(add_line(line), view_in) return properties.trivial()
def dispatch(x): view_in = asker.refresh(view) asker.update(add_line(input), view_in) head = fields.get(asker, representations.head(), x) bindings = fields.get(asker, representations.bindings(), x) view_in = asker.refresh(view_in) asker.update(add_line(head), view_in) for p in dictionaries.item_iterator(asker, bindings): var, val = pairs.to_pair(asker, p) view_in = asker.refresh(view_in) asker.update(bind_variable(var, val), view_in) return properties.trivial()
def move(asker, question, direction): if direction.head == down.head: if below is None: asker.pass_through(moved(direction)) else: asker.update(now_is_pointer(), below) asker.update(remove_pointer(), child) if direction.head == up.head: if above is None: asker.update(now_is_pointer(), root) asker.update(remove_pointer(), child) else: asker.update(add_pointer_to_bottom(), above) asker.update(remove_pointer(), child) elif direction.head == left.head: asker.update(remove_pointer(), child) asker.update(now_is_pointer(), root) return properties.trivial()
def convert(asker, value, req): starting_cost = asker.cost def check(x): return properties.check_firmly(asker, req, representations.quote(x)) if check(value): return asker.reply(answer=value) #TODO in the long run we might want to leave properties in if they can simplify the conversion old_modifier = value.modifier stripped = value.simple_update(_modifier=properties.trivial()) id = stripped.id result = None if (id, req.id) in conversion_cache: result = conversion_cache[(id, req.id)] if result is None: for form in synonyms[id]: if check(form): result = form if result is None: response = asker.ask(raw_convert(value, req)) if response.has_answer(): result = response.answer else: return asker.reply() synonyms[id].add(result) conversion_cache[(id, req.id)] = result #FIXME what an ugly hack; this sort of thing will hopefully be done automatically if (asker.cost - starting_cost > 30 and booleans.ask_firmly(asker, nicer_representation( representations.quote(value), representations.quote(result), req ))): asker.set_repr(value, representations.quote(result)) return asker.reply(answer=properties.simple_add_modifier(result, old_modifier))
def process_update(source, update, repr): repr_change = updates.become(repr) self.incoming_update(source, Q, update, repr_change=repr_change) return properties.trivial()
def process_query(self, other): if other.head == use_state.head: self.state = other['state'] return properties.trivial() else: return super(StatefulAsker, self).process_query(other)
def __init__(self, question, other=None): if other is None: other = properties.trivial() self.other = other self.question = question
def relay(property): self.relay(property) return properties.trivial()
def __init__(self, *args, **kwargs): super(Relayer, self).__init__(*args, **kwargs) self.to_relay = properties.trivial()
def handle(x): context.result = x return properties.trivial()
def assign(s, x): view_in = asker.refresh(view) asker.update(add_line(input), view_in) view_in = asker.refresh(view_in) asker.update(bind_variable(s, x), view_in) return properties.trivial()