causal_grammar.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Causality 作者: vcla 项目源码 文件源码
def complete_parse_tree(active_parse_tree, fluent_hash, event_hash, frame, completions, source, event_timeouts):
    # we have a winner! let's show them what they've won, bob!
    global debug_calculate_energy
    #debug_calculate_energy = True
    ### don't need this energy = calculate_energy(active_parse_tree, get_energies(fluent_hash, event_hash))
    debug_calculate_energy = False
    fluent = active_parse_tree["symbol"]
    agents_responsible = []
    # if there are agents in the parse, print out who they were
    keys = get_fluent_and_event_keys_we_care_about((active_parse_tree,))
    # WARNING: if we have two event types in the same parse, we can wind up adding the same parse multiple times.
    # BACKLOG: make sure the "if not found" solution below doesn't break anything else when it solves the above
    for event_key in keys["events"]:
        event = get_best_energy_event(event_hash[event_key]['energies'],newerthan=(frame - event_timeouts[event_key]))
        agent = event["agent"]
        if agent:
            agents_responsible.append(agent,)
        if "_" in fluent:
            prefix, postfix = fluent.rsplit("_",1)
            if postfix in ("on","off",):
                fluent = prefix
        if fluent not in completions:
            completions[fluent] = {}
        completion = completions[fluent]
        if frame not in completion:
            completion[frame] = []
        completion_frame = completion[frame]
        found = False
        for item in completion_frame:
            if item['parse']['id'] == active_parse_tree['id']:
                found = True
                break
        if not found:
            #completion_frame.append({"frame": frame, "fluent": fluent, "energy": energy, "parse": active_parse_tree, "agents": agents_responsible, "sum": fluent_hash[active_parse_tree['symbol']]['energy'], 'source': source})
            completion_frame.append({"frame": frame, "fluent": fluent, "parse": active_parse_tree, "agents": agents_responsible, "sum": fluent_hash[active_parse_tree['symbol']]['energy'], 'source': source})
    #print("{}".format("\t".join([str(fluent),str(frame),"{:g}".format(energy),str(make_tree_like_lisp(active_parse_tree)),str(agents_responsible)])))
    #print("{} PARSE TREE {} COMPLETED at {}: energy({}) BY {}\n{}\n***{}***".format(fluent,active_parse_tree['id'],frame,energy,source,make_tree_like_lisp(active_parse_tree),active_parse_tree))
    #print("Agents responsible: {}".format(agents_responsible))
    if kDebugEnergies:
        debug_energies(fluent_hash, event_hash)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号