Exemple #1
0
def node_info(ctx, args):
    """
    Args:
        ctx (context.Context)
        args (kct.argparse.Namespace)
        args.node-ref
    """
    node_ref_str = getattr(args, 'node-ref')
    # info command without anything is 'current'
    if node_ref_str is None:
        node_ref_str = 'cur'

    node_ref = parse_node_ref(node_ref_str)
    if node_ref is None:
        # TODO(trevor) print node-ref types in help msg
        error("Error %s is not a valid node-ref" % node_ref_str)
        return

    try:
        node = ctx.node_by_node_ref(node_ref)
        _print_location(ctx, node)
        _print_semexes_header(ctx)
        _print_neighbors(ctx, node)
    except ValueError, ve: # Catch invalid node-ref
        error(ve)
        return
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))
 def test_cur(self):
     node_ref = parse_node_ref("cur")
     assert node_ref == NodeRef(NodeRefType.CURRENT)
 def test_fail_dog(self):
     # dog is not a node ref
     node_ref = parse_node_ref("dog")
     assert node_ref == None
 def test_fail_neighbors_with_no_integer(self):
     node_ref = parse_node_ref("cur.neighbors[a]")
     assert node_ref == None
 def test_fail_cur_neighbors_no_period(self):
     node_ref = parse_node_ref("curneighbors[0]")
     assert node_ref == None
 def test_nbrs(self):
     node_ref = parse_node_ref("cur.nbrs[9]")
     assert node_ref == NodeRef(NodeRefType.NEIGHBOR, neighbor_index=9)
 def test_cur_eq_current(self):
     node_ref1 = parse_node_ref("cur")
     node_ref2 = parse_node_ref("current")
     assert node_ref1 == node_ref2