Add session context, increase logging.
This commit is contained in:
parent
359f858c39
commit
bb7d438e0d
7 changed files with 103 additions and 77 deletions
|
@ -97,45 +97,46 @@ def integrate_language(knowledge_base, example):
|
|||
break
|
||||
|
||||
for position, atom in lower_levels:
|
||||
session().annotate("\x1b[1mSelecting\x1b[0m: {}".format(atom))
|
||||
similar = get_similar_tree(knowledge_base, atom, tokens)
|
||||
remix, (start_bounds, end_bounds) = build_remix_matrix(knowledge_base, tokens, atom, similar)
|
||||
with session().log(atom):
|
||||
session().annotate("\x1b[1mSelecting\x1b[0m: {}".format(atom))
|
||||
similar = get_similar_tree(knowledge_base, atom, tokens)
|
||||
remix, (start_bounds, end_bounds) = build_remix_matrix(knowledge_base, tokens, atom, similar)
|
||||
|
||||
after_remix = apply_remix(tokens[len(start_bounds):-len(end_bounds)], remix)
|
||||
session().annotate("--FIND MIX--")
|
||||
session().annotate("-MIX- | {}".format(remix))
|
||||
session().annotate("-FRM- | {}".format(tokens))
|
||||
session().annotate("-AFT- | {}".format(after_remix))
|
||||
after_remix = apply_remix(tokens[len(start_bounds):-len(end_bounds)], remix)
|
||||
session().annotate("--FIND MIX--")
|
||||
session().annotate("-MIX- | {}".format(remix))
|
||||
session().annotate("-FRM- | {}".format(tokens))
|
||||
session().annotate("-AFT- | {}".format(after_remix))
|
||||
|
||||
session().annotate("--- TEMPLATE ---")
|
||||
session().annotate("--- TEMPLATE ---")
|
||||
|
||||
_, matcher, result = make_template(knowledge_base, after_remix, atom)
|
||||
session().annotate("Tx: {}".format(after_remix))
|
||||
session().annotate("Mx: {}".format(matcher))
|
||||
session().annotate("Rx: {}".format(result))
|
||||
session().annotate("Sx: {}".format(start_bounds))
|
||||
session().annotate("Ex: {}".format(end_bounds))
|
||||
_, matcher, result = make_template(knowledge_base, after_remix, atom)
|
||||
session().annotate("Tx: {}".format(after_remix))
|
||||
session().annotate("Mx: {}".format(matcher))
|
||||
session().annotate("Rx: {}".format(result))
|
||||
session().annotate("Sx: {}".format(start_bounds))
|
||||
session().annotate("Ex: {}".format(end_bounds))
|
||||
|
||||
|
||||
assert(len(after_remix) + len(start_bounds) + len(end_bounds) == len(tokens))
|
||||
session().annotate( " +-> {}".format(after_remix))
|
||||
subquery_type = knowledge_evaluation.get_subquery_type(knowledge_base.knowledge, atom)
|
||||
session().annotate(r" \-> <{}>".format(subquery_type))
|
||||
assert(len(after_remix) + len(start_bounds) + len(end_bounds) == len(tokens))
|
||||
session().annotate( " +-> {}".format(after_remix))
|
||||
subquery_type = knowledge_evaluation.get_subquery_type(knowledge_base.knowledge, atom)
|
||||
session().annotate(r" \-> <{}>".format(subquery_type))
|
||||
|
||||
# Clean remaining tokens
|
||||
new_tokens = list(tokens)
|
||||
offset = len(start_bounds)
|
||||
for _ in range(len(remix)):
|
||||
new_tokens.pop(offset)
|
||||
# Clean remaining tokens
|
||||
new_tokens = list(tokens)
|
||||
offset = len(start_bounds)
|
||||
for _ in range(len(remix)):
|
||||
new_tokens.pop(offset)
|
||||
|
||||
# TODO: Get a specific types for... types
|
||||
new_tokens.insert(offset, (subquery_type, remix))
|
||||
tokens = new_tokens
|
||||
# TODO: Get a specific types for... types
|
||||
new_tokens.insert(offset, (subquery_type, remix))
|
||||
tokens = new_tokens
|
||||
|
||||
resolved_parsed = replace_position(resolved_parsed, position, offset)
|
||||
session().annotate("RP: {}".format(resolved_parsed))
|
||||
session().annotate("AT: {}".format(atom))
|
||||
session().annotate("#########")
|
||||
resolved_parsed = replace_position(resolved_parsed, position, offset)
|
||||
session().annotate("RP: {}".format(resolved_parsed))
|
||||
session().annotate("AT: {}".format(atom))
|
||||
session().annotate("#########")
|
||||
|
||||
|
||||
tokens, matcher, result = make_template(knowledge_base, tokens, resolved_parsed)
|
||||
|
@ -298,12 +299,12 @@ def get_similar_tree(knowledge_base, atom, tokens):
|
|||
return None
|
||||
|
||||
for i, possibility in enumerate(sorted_possibilities):
|
||||
session().annotate('---- POSSIBILITY #{} ----'.format(i))
|
||||
similar_matcher, similar_result, similar_result_resolved, _, _ = possibility
|
||||
session().annotate('AST: {}'.format(similar_result))
|
||||
session().annotate('Based on: {}'.format(similar_matcher))
|
||||
session().annotate('Results on: {}'.format(similar_result_resolved))
|
||||
session().annotate('---------------------')
|
||||
with session().log(possibility):
|
||||
similar_matcher, similar_result, similar_result_resolved, _, _ = possibility
|
||||
session().annotate('AST: {}'.format(similar_result))
|
||||
session().annotate('Based on: {}'.format(similar_matcher))
|
||||
session().annotate('Results on: {}'.format(similar_result_resolved))
|
||||
session().annotate('---------------------')
|
||||
|
||||
return sorted_possibilities[0]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue