Exemple #1
0
def _print_most_likely_paths(ctx, node):
    """
    Calculates and prints the most likely endpoints for all semexes
    in the context provided.
    """
    indent()
    graph = ctx.graph
    num_nodes = ctx.graph_number_of_nodes()
    for name, val in ctx.semexes().iteritems():
        if not val.active:
            continue
        # Calculate semex starting at this neighbor node
        semex = val.semex
        this_semex = make_semex_starting_here(ctx.transition,
                                              ctx.transition_op,
                                              graph,
                                              num_nodes,
                                              semex,
                                              node)
        most_likely = most_likely_endpoints(this_semex, num_nodes)
        nodes = graph.nodes() # cache this lookup
        pp("%s"%name)
        indent()
        for (idx, val) in most_likely:
            endpoint = nodes[idx]
            # Skip current
            if endpoint == ctx.posn or endpoint == node:
                continue
            pp("%s [%e]" % (str(endpoint)[:80], val))
        deindent()
    deindent()
Exemple #2
0
def semex_peek(ctx, args):
    name = args.name
    node_ref_str = getattr(args, 'node-ref')
    node_ref = parse_node_ref(node_ref_str)
    if node_ref is None:
        error("Error %s is not a valid node-ref" % node_ref_str)
        return
    node = ctx.node_by_node_ref(node_ref)

    active_semex = ctx.semexes().get(name)
    if active_semex is None:
        error("Error unknown path set '%s'" % name)
    semex = active_semex.semex

    new_semex = make_semex_starting_here(ctx.transition, ctx.transition_op,
                                         ctx.graph, ctx.graph_number_of_nodes(),
                                         semex, node)
    most_likely = most_likely_endpoints(new_semex, ctx.graph_number_of_nodes())
    for (idx, val) in most_likely:
        endpoint = ctx.graph.nodes()[idx]
        pp("%s [%e]" % (str(endpoint)[:80], val))