causal_grammar.py 文件源码

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

项目:Causality 作者: vcla 项目源码 文件源码
def add_missing_parses(fluent, fluent_hash, event_hash, frame, completions):
    ## here we're just getting the completions for one specific frame
    ## we want to go through all the possible parses for that fluent
    ## and make sure they're spoken for in completions
    #print "ADDING MISSING PARSES"
    for symbol in (completions[0]['parse']['symbol'],):
        parse_ids_completed = []
        for completion in completions:
            parse_ids_completed.append(completion['parse']['id'])
        #print("IDS: {}".format(parse_ids_completed))
        anti_symbol = invert_name(symbol)
        possible_trees = fluent_hash[symbol]['trees']
        unpossible_trees = fluent_hash[anti_symbol]['trees']
        for possible_tree in possible_trees + unpossible_trees:
            # if this tree is a "primary" for this symbol
            if possible_tree['symbol'] in (symbol,anti_symbol):
                other_parses = possible_tree['parses']
                for other_parse in other_parses:
                    if other_parse['id'] not in parse_ids_completed:
                        parse_ids_completed.append(other_parse['id'])
                        #print("ADDING ID: {}".format(other_parse['id']))
                        #complete_parse_tree(other_parse, fluent_hash, event_hash, effective_frames[symbol], completions, 'missing') ### what is this 'effective frames' thing?
                        #complete_parse_tree(other_parse, fluent_hash, event_hash, frame, completions, 'missing')
                        # we have a winner! let's show them what they've won, bob!
                        #### don't need this energy = calculate_energy(other_parse, get_energies(fluent_hash, event_hash))
                        agents_responsible = []
                        source = 'missing'
                        #completions.append({"frame": frame, "fluent": fluent, "energy": energy, "parse": other_parse, "agents": agents_responsible, "sum": fluent_hash[other_parse['symbol']]['energy'], 'source': source})
                        completions.append({"frame": frame, "fluent": fluent, "parse": other_parse, "agents": agents_responsible, "sum": fluent_hash[other_parse['symbol']]['energy'], 'source': source})
                        #print("{}".format("\t".join([str(fluent),str(frame),"{:g}".format(energy),str(make_tree_like_lisp(other_parse)),str(agents_responsible)])))
                        #print("{} PARSE TREE {} COMPLETED at {}: energy({}) BY {}\n{}\n***{}***".format(fluent,other_parse['id'],frame,energy,source,make_tree_like_lisp(other_parse),other_parse))
                        #print("Agents responsible: {}".format(agents_responsible))
                        if kDebugEnergies:
                            debug_energies(fluent_hash, event_hash)
    #print "---"
    return completions

# clears out any parses that have not been touched within N frames, printing out any over reporting_threshold_energy
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号