def modify_edges(graph, modify_type, edges, attr={}, weight=None): """Create modify edges operation for nx graph. Args: graph (:class:`nx.Graph`): A nx graph. modify_type (`type_pb2.(NX_ADD_EDGES | NX_DEL_EDGES | NX_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 == graph_def_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.PROPERTIES] = utils.s_to_attr(json.dumps(attr)) if weight: config[types_pb2.EDGE_KEY] = utils.s_to_attr(weight) op = Operation( graph.session_id, types_pb2.MODIFY_EDGES, config=config, large_attr=utils.bytes_to_large_attr(edges), output_types=types_pb2.GRAPH, ) return op
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
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
def modify_vertices(graph, modify_type, vertices, attr={}): """Create modify vertices operation for nx graph. Args: graph (:class:`nx.Graph`): A nx graph. modify_type (`type_pb2.(NX_ADD_NODES | NX_DEL_NODES | NX_UPDATE_NODES)`): The modify type vertices (list): node list. Returns: An op to modify vertices on the graph. """ check_argument(graph.graph_type == graph_def_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.PROPERTIES] = utils.s_to_attr(json.dumps(attr)) op = Operation( graph.session_id, types_pb2.MODIFY_VERTICES, config=config, large_attr=utils.bytes_to_large_attr(vertices), output_types=types_pb2.GRAPH, ) return op