def copy(self): # Networkx graph copy is very slow, so we implement nodes = self._g.nodes(data=True) vertices = [Vertex(vertex_id=n, properties=data) for n, data in nodes] edges_iter = self._g.edges(data=True, keys=True) edges = [Edge(source_id=u, target_id=v, label=l, properties=data) for u, v, l, data in edges_iter] return NXGraph(self.name, vertices, edges)
def create_vertex(vitrage_id, entity_id=None, entity_category=None, entity_type=None, entity_state=None, is_deleted=False, sample_timestamp=None, update_timestamp=None, is_placeholder=False, project_id=None, metadata=None): """A builder to create a vertex :param vitrage_id: :type vitrage_id: str :param entity_id: :type entity_id: str :param entity_category: :type entity_category: str :param entity_type: :type entity_type: str :param entity_state: :type entity_state: str :param is_deleted: :type is_deleted: boolean :param update_timestamp: :type update_timestamp: str :param sample_timestamp: :type sample_timestamp: str :param metadata: :type metadata: dict :param is_placeholder: :type is_placeholder: boolean :param project_id: :type project_id: str :return: :rtype: Vertex """ properties = { VConst.ID: entity_id, VConst.STATE: entity_state, VConst.TYPE: entity_type, VConst.CATEGORY: entity_category, VConst.IS_DELETED: is_deleted, VConst.UPDATE_TIMESTAMP: update_timestamp, VConst.SAMPLE_TIMESTAMP: sample_timestamp, VConst.IS_PLACEHOLDER: is_placeholder, VConst.VITRAGE_ID: vitrage_id, VConst.PROJECT_ID: project_id } if metadata: properties.update(metadata) properties = dict((k, v) for k, v in properties.items() if v is not None) vertex = Vertex(vertex_id=vitrage_id, properties=properties) return vertex
def vertex_copy(v_id, data): return Vertex(vertex_id=v_id, properties=copy.copy(data))
def _convert_dist_to_vertex(self, neighbor): ver_id = neighbor[VProps.CATEGORY] + \ TransformerBase.KEY_SEPARATOR + neighbor[VProps.TYPE] + \ TransformerBase.KEY_SEPARATOR + neighbor[VProps.ID] return Vertex(vertex_id=ver_id, properties=neighbor)
def create_vertex(vitrage_id, vitrage_category=None, vitrage_type=None, vitrage_sample_timestamp=None, vitrage_is_deleted=False, vitrage_is_placeholder=False, entity_id=None, entity_state=None, update_timestamp=None, project_id=None, vitrage_resource_project_id=None, metadata=None, datasource_name=None): """A builder to create a vertex :param vitrage_id: :type vitrage_id: str :param entity_id: :type entity_id: str :param vitrage_category: :type vitrage_category: str :param vitrage_type: :type vitrage_type: str :param entity_state: :type entity_state: str :param vitrage_is_deleted: :type vitrage_is_deleted: boolean :param update_timestamp: :type update_timestamp: str :param vitrage_sample_timestamp: :type vitrage_sample_timestamp: str :param metadata: :type metadata: dict :param vitrage_is_placeholder: :type vitrage_is_placeholder: boolean :param project_id: :type project_id: str :param datasource_name: :type datasource_name: str :return: :rtype: Vertex """ properties = { VConst.ID: entity_id, VConst.STATE: entity_state, VConst.VITRAGE_TYPE: vitrage_type, VConst.VITRAGE_CATEGORY: vitrage_category, VConst.VITRAGE_IS_DELETED: vitrage_is_deleted, VConst.UPDATE_TIMESTAMP: update_timestamp, VConst.VITRAGE_SAMPLE_TIMESTAMP: vitrage_sample_timestamp, VConst.VITRAGE_IS_PLACEHOLDER: vitrage_is_placeholder, VConst.VITRAGE_ID: vitrage_id, VConst.PROJECT_ID: project_id, VConst.VITRAGE_RESOURCE_PROJECT_ID: vitrage_resource_project_id, VConst.VITRAGE_DATASOURCE_NAME: datasource_name, } if metadata: properties.update(metadata) properties = {k: v for k, v in properties.items() if v is not None} vertex = Vertex(vertex_id=vitrage_id, properties=properties) return vertex