本文整理汇总了Python中term.Term.from_str方法的典型用法代码示例。如果您正苦于以下问题:Python Term.from_str方法的具体用法?Python Term.from_str怎么用?Python Term.from_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类term.Term
的用法示例。
在下文中一共展示了Term.from_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_term
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def render_term(asker, term):
return asker.reply(answer=strings.concat(
strings.concat(
T.from_str("T("),
field.get(asker, representations.head(), term)),
T.from_str(")")
))
示例2: render_list
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def render_list(asker, x):
result = T.from_str("[")
first = True
for item in lists.iterator(asker, x):
item_printed = asker.ask_firmly(render(item))
if not first:
item_printed = strings.concat(T.from_str(", "), item_printed)
first = False
result = strings.concat(result, item_printed)
result = strings.concat(result, T.from_str("]"))
return asker.reply(answer=result)
示例3: render_pair
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def render_pair(asker, x):
return asker.reply(answer=strings.concat(
strings.concat(
T.from_str("("),
asker.ask_firmly(render(fields.get(pairs.first(), x))),
),
strings.concat(
T.from_str(", "),
strings.concat(
asker.ask_firmly(render(fields.get(pairs.first(), x))),
T.from_str(")")
)
)
))
示例4: update_view
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def update_view(asker, view, input):
relayer = asker.pass_through(should_return.head)
#FIXME using the name view_in is a hack to keep view from being locally scoped...
@relayer(should_print.head)
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()
@relayer(should_dispatch.head)
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()
@relayer(should_assign.head)
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()
interpret_response = asker.ask(interpret_input(view, input), handler=relayer)
if interpret_response.has_answer():
bindings = dictionaries.to_dict(asker, fields.get(asker, bindings_field(), view))
bindings_str = {strings.to_str(asker, k):v for k, v in bindings.items()}
for char in "xyzw" + string.letters:
if char not in bindings_str:
break
asker.update(bind_variable(T.from_str(char), interpret_response.answer), view)
new_line = strings.concat(
T.from_str("{} = ".format(char)),
input
)
asker.update(add_line(new_line), view)
return asker.reply()
示例5: make_raw_expr
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def make_raw_expr(xs):
text = ""
args = {}
for x in xs:
if type(x) is str:
text += x
else:
arg_name = ("xyzw"+alphas)[len(args)]
text += "[{}]".format(arg_name)
args[arg_name] = x
return T(make_raw_expr.head, text=T.from_str(text), bindings=T.from_dict_of_str(args))
示例6: __init__
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def __init__(self, *args, **kwargs):
super(ContextUpdater, self).__init__(*args, **kwargs)
self.internal = {}
self.changed = {}
self.original = {}
self.current = {}
self.updates = {}
self.source = {}
if self.Q is not None:
self.question_bindings = self.Q.question.bindings
for k, v in self.question_bindings.iteritems():
self.tag(in_question(T.from_str(k)), v)
示例7: add_children_on_expanded
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def add_children_on_expanded(asker, old, new, bindings):
children = []
for p in lists.iterator(asker, lists.from_dict(bindings)):
k = asker.ask(fields.get_field(first(), p)).firm_answer
v = asker.ask(fields.get_field(second(), p)).firm_answer
prefix = strings.string_concat(k, T.from_str(": "))
new_node = node_from_term(asker, v)
new_node = updates.update(
updates.apply_to(headline(), strings.prepend_str(prefix)),
new_node
)
children.append(new_node)
return asker.reply(answer=updates.update(
fields.set_field(all_children(), T.from_list(children)),
new
))
示例8: outline_to_lines
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def outline_to_lines(asker, root):
debug()
result = asker.ask(fields.get_field(cached_lines(), root)).answer
if result is not None:
return asker.reply(answer=result)
base_headline = asker.ask(fields.get_field(headline(), root)).firm_answer
root = asker.refresh(root)
prefix = "* " if convert.check_hard(asker, is_pointer(), root) else " "
full_headline = strings.string_concat(T.from_str(prefix), base_headline)
root = asker.refresh(root)
children = asker.ask(fields.get_field(visible_children(), root)).firm_answer
body = empty_lines()
for child in lists.iterator(asker, children):
section = asker.ask(outline_to_lines(child)).firm_answer
body = concat_lines(body, section)
result = concat_lines(one_line(full_headline), indent_lines(body))
asker.update(updates.set_field(cached_lines(), result), root)
return asker.reply(answer=result)
示例9: propagate_back
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def propagate_back(s):
if s.head == term.because.head:
return propagate_back(s['operation'])
elif s.head == term.explain.head:
return propagate_back(s['operation']) or propagate_back(s['prior'])
elif s.head == term.accessing.head:
if change.head == updates.trivial.head:
parent = s['term']
binding = s['binding']
return self.update(
updates.trivial(),
parent,
repr_change=updates.apply_to_field(
representations.referent_of(T.from_str(binding)),
repr_change
).explain("tracing backwards from [v]", v=v)
)
else:
return False
elif s.head == askers.answering.head:
Q = s['Q']
if Q.head == fields.get_field.head:
parent = Q['object']
field = Q['field']
return self.update(
updates.apply_to_field(field, change),
parent,
repr_change=updates.apply_to_field(updates.lift_field(field), repr_change)
)
elif Q.head == convert.convert.head:
previous = Q['value']
return self.update(
change,
previous,
repr_change=None
)
return False
示例10: print_lines_simple
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def print_lines_simple(asker, lines):
return asker.ask_tail(print_lines(lines, T.from_int(0), T.from_str(" ")))
示例11: render_dict
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def render_dict(asker, x):
return asker.reply(answer=strings.concat(
T.from_str("D"),
lists.from_dict(x)
))
示例12: make_str_expr
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def make_str_expr(s):
return T(make_str_expr.head, s=T.from_str(s[0]))
示例13: render_int
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def render_int(asker, x):
return asker.reply(answer=T.from_str(str(ints.to_int(asker, x))))
示例14: get_starting_view
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def get_starting_view(asker, query):
head = fields.get(asker, representations.head(), query)
bindings = fields.get(asker, representations.bindings(), query)
initial_lines = T.from_list([head, T.from_str("---")])
return asker.reply(answer=view(initial_lines, bindings))
示例15: prompt
# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import from_str [as 别名]
def prompt(asker):
return asker.reply(answer=T.from_str(raw_input("")))