def add_results()

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


    def add_results(self, results, is_http=False):
        """
        receives path results and traverses them to add nodes and edges to the network graph.
        We will look at sets of three in a path to form a vertex -> edge -> vertex pattern. All other
        patters will be considered invalid at this time.

        :param results: the data to be processed. Must be of type :type Path
        :param is_http: A flag indicating the type of token keys returned
        :return:
        """
        if not isinstance(results, list):
            raise ValueError("results must be a list of paths")

        if is_http:
            gremlin_ids = ['id', '~id']
            gremlin_label = 'label'
        else:
            gremlin_ids = [T.id]
            gremlin_label = T.label

        for path_index, path in enumerate(results):
            if isinstance(path, Path):
                if type(path[0]) is Edge or type(path[-1]) is Edge:
                    raise INVALID_PATH_ERROR

                for i in range(len(path)):
                    if isinstance(path[i], dict):
                        is_elementmap = False
                        gremlin_id_in_path = False
                        for possible_id in gremlin_ids:
                            if possible_id in path[i]:
                                gremlin_id_in_path = True
                                break
                        if gremlin_id_in_path and gremlin_label in path[i]:
                            for prop, value in path[i].items():
                                # ID and/or Label property keys could be renamed by a project() step
                                if isinstance(value, str) and prop not in gremlin_ids + [gremlin_label]:
                                    is_elementmap = True
                                    break
                                elif isinstance(value, dict):
                                    if prop in [Direction.IN, Direction.OUT]:
                                        is_elementmap = True
                                        break
                                elif isinstance(value, list):
                                    break
                                elif not isinstance(value, (str, list, dict)):
                                    is_elementmap = True
                                    break
                        if is_elementmap:
                            self.insert_elementmap(path[i], check_emap=True, path_element=path, index=i)
                        else:
                            self.insert_path_element(path, i)
                    else:
                        self.insert_path_element(path, i)
            elif isinstance(path, dict):
                gremlin_id_in_path_keys = False
                for possible_id in gremlin_ids:
                    if possible_id in path.keys():
                        gremlin_id_in_path_keys = True
                        break
                if gremlin_id_in_path_keys and gremlin_label in path.keys():
                    self.insert_elementmap(path, index=path_index)
                else:
                    raise ValueError("all entries in results must be paths or elementMaps")
            else:
                raise ValueError("all entries in results must be paths or elementMaps")