コード例 #1
0
ファイル: cmd.py プロジェクト: trevorsummerssmith/vinge
def semex_add(ctx, args):
    """
    Adds a semex to the context's list of semexes.

    Args:
        ctx (context.Context)
        args (kct.argparse.Namepsace)
        args.name (str) - used to refer to the semex
        args.semex-str (str) - the semex in string form. A valid argument to
            semex.parser.compile_regex

    Returns: None
    """
    from vinge.semex.parser import compile_regex, RegexParseException
    from vinge.semex.ast_to_semex import ast_to_semex
    name = args.name
    # argparse gives us an array of strings as the semex-str. We want a string
    semex_str = ' '.join(getattr(args, 'semex-str'))
    try:
        semex_ast = compile_regex(semex_str)
        semex = ast_to_semex(ctx.graph, ctx.transition, ctx.transition_op, semex_ast)
        # Add to the context
        ctx.add_semex(name, semex)
        pp('Successfully added path set')
    except RegexParseException, rpe:
        error("Error parsing path set (semex) '%s': %s"%(semex_str, rpe.message))
コード例 #2
0
ファイル: cmd.py プロジェクト: trevorsummerssmith/vinge
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
コード例 #3
0
ファイル: cmd.py プロジェクト: trevorsummerssmith/vinge
def semex_toggle(ctx, args):
    """
    Swaps the active status of the provided semex. Active semexes are used in
    various display commands (see e.g. cmd.node_info).

    Args:
        ctx (context.Context)
        args (kct.argparse.Namepsace)
        args.name (str) - used to refer to the semex

    Returns: None
    """
    name = args.name
    try:
        is_active = not ctx.semex_toggle_active(name)
        info("%s is now %s" % (name, _bool_to_active[is_active]))
    except KeyError, ke:
        # TODO(trevor) catching keyerror here is bad. Probs masking something
        error("Unknown path set '%s'" % name)
コード例 #4
0
ファイル: cmd.py プロジェクト: trevorsummerssmith/vinge
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))