Esempio n. 1
0
def modify_vertices(graph, modify_type, vertices):
    """Create modify vertices operation for nx graph.

    Args:
        graph (:class:`nx.Graph`): A nx graph.
        modify_type (`type_pb2.(ADD_NODES | DEL_NODES | UPDATE_NODES)`): The modify type
        vertices (list): node list.

    Returns:
        An op to modify vertices on the graph.
    """
    check_argument(graph.graph_type == types_pb2.DYNAMIC_PROPERTY)
    config = {}
    config[types_pb2.GRAPH_NAME] = utils.s_to_attr(graph.key)
    config[types_pb2.MODIFY_TYPE] = utils.modify_type_to_attr(modify_type)
    config[types_pb2.NODES] = utils.list_str_to_attr(vertices)
    op = Operation(
        graph._session_id,
        types_pb2.MODIFY_VERTICES,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op
Esempio n. 2
0
def modify_edges(graph, modify_type, edges):
    """Create modify edges operation for nx graph.

    Args:
        graph (:class:`nx.Graph`): A nx graph.
        modify_type (`type_pb2.(ADD_EDGES | DEL_EDGES | UPDATE_EDGES)`): The modify type
        edges (list): List of edges to be inserted into or delete from graph based on `modify_type`

    Returns:
        An op to modify edges on the graph.
    """
    check_argument(graph.graph_type == types_pb2.DYNAMIC_PROPERTY)
    config = {}
    config[types_pb2.GRAPH_NAME] = utils.s_to_attr(graph.key)
    config[types_pb2.MODIFY_TYPE] = utils.modify_type_to_attr(modify_type)
    config[types_pb2.EDGES] = utils.list_str_to_attr(edges)
    op = Operation(
        graph._session_id,
        types_pb2.MODIFY_EDGES,
        config=config,
        output_types=types_pb2.GRAPH,
    )
    return op