def insert_elementmap()

in src/graph_notebook/network/gremlin/GremlinNetwork.py [0:0]


    def insert_elementmap(self, e_map, check_emap=False, path_element=None, index=None):
        """
        Add a vertex or edge that has been returned by an elementMap query step.

        Any elementMap representations of edges must be directed, and contain both of the Direction.IN and Direction.OUT
        properties. If the elementMap contains neither of these, then we assume it is a vertex.

        :param e_map: A dictionary containing the elementMap representation of a vertex or an edge
        """
        # Handle directed edge elementMap
        if (Direction.IN in e_map.keys() and Direction.OUT in e_map.keys()) \
                or ('IN' in e_map.keys() and 'OUT' in e_map.keys()):
            out_prop = Direction.OUT if Direction.OUT in e_map.keys() else 'OUT'
            in_prop = Direction.IN if Direction.IN in e_map.keys() else 'IN'
            from_id = get_id(e_map[out_prop])
            to_id = get_id(e_map[in_prop])
            # Ensure that the default nodes includes with edge elementMaps do not overwrite nodes
            # with the same ID that have been explicitly inserted.
            if not self.graph.has_node(from_id):
                self.add_vertex(e_map[out_prop], path_index=index-1)
            if not self.graph.has_node(to_id):
                self.add_vertex(e_map[in_prop], path_index=index+1)
            self.add_path_edge(e_map, from_id, to_id)
        # Handle vertex elementMap
        else:
            # If a default node was created at the same index by an edge elementMap, overwrite it.
            if check_emap:
                self.insert_path_element(path_element, index)
            else:
                self.add_vertex(e_map, path_index=index)