src/graph.py
def __create_graph(self, data_path: str):
        '''
        Function to create the graph using NetworkX.
        Args:
            data_path: The path to the json file with the graph data
        Returns:
            A NetworkX graph object
        '''
        with open(data_path) as data_file:
            data = json.load(data_file)

        graph = nx.Graph()

        for entry in tqdm.tqdm(data, desc="Creating graph..."):
            conference = {
                "id_str":entry["id_conference"],
                "id_int":entry["id_conference_int"]
            }
            publication = {
                "id_str": entry["id_publication"],
                "id_int": entry["id_publication_int"],
                "title": entry["title"]
            }
            nodes_id = []

            for author in entry["authors"]:
                try:
                    node = graph.node[author["author_id"]]["data"]
                except KeyError:
                    new_author = {
                        "name": author["author"],
                        "id": author["author_id"]
                    }
                    node = {
                        "author": new_author,
                        "publications": {},
                        "conferences": {}
                    }

                    graph.add_node(new_author['id'], data=node)

                node['publications'][publication['id_int']] = publication
                node['conferences'][conference['id_int']] = conference

                if nodes_id:
                    for node_id in nodes_id:
                        graph.add_edge(node_id, author["author_id"], weight=None)
                nodes_id.append(author["author_id"])

        graph = self.__add_weights(graph)
        return graph

        Function to create the graph using NetworkX.
        Args:
            data_path: The path to the json file with the graph data
        Returns:
            A NetworkX graph object
        
Function to create the graph using NetworkX.
Function to create the graph using NetworkX .
def __create_graph(self, data_path: str):
        with open(data_path) as data_file:
            data = json.load(data_file)
        graph = nx.Graph()
        for entry in tqdm.tqdm(data, desc="Creating graph..."):
            conference = {
                "id_str":entry["id_conference"],
                "id_int":entry["id_conference_int"]
            }
            publication = {
                "id_str": entry["id_publication"],
                "id_int": entry["id_publication_int"],
                "title": entry["title"]
            }
            nodes_id = []
            for author in entry["authors"]:
                try:
                    node = graph.node[author["author_id"]]["data"]
                except KeyError:
                    new_author = {
                        "name": author["author"],
                        "id": author["author_id"]
                    }
                    node = {
                        "author": new_author,
                        "publications": {},
                        "conferences": {}
                    }
                    graph.add_node(new_author['id'], data=node)
                node['publications'][publication['id_int']] = publication
                node['conferences'][conference['id_int']] = conference
                if nodes_id:
                    for node_id in nodes_id:
                        graph.add_edge(node_id, author["author_id"], weight=None)
                nodes_id.append(author["author_id"])
        graph = self.__add_weights(graph)
        return graph
def __create_graph ( self , data_path : str ) : with open ( data_path ) as data_file : data = json . load ( data_file ) graph = nx . Graph ( ) for entry in tqdm . tqdm ( data , desc = "Creating graph..." ) : conference = { "id_str" : entry [ "id_conference" ] , "id_int" : entry [ "id_conference_int" ] } publication = { "id_str" : entry [ "id_publication" ] , "id_int" : entry [ "id_publication_int" ] , "title" : entry [ "title" ] } nodes_id = [ ] for author in entry [ "authors" ] : try : node = graph . node [ author [ "author_id" ] ] [ "data" ] except KeyError : new_author = { "name" : author [ "author" ] , "id" : author [ "author_id" ] } node = { "author" : new_author , "publications" : { } , "conferences" : { } } graph . add_node ( new_author [ 'id' ] , data = node ) node [ 'publications' ] [ publication [ 'id_int' ] ] = publication node [ 'conferences' ] [ conference [ 'id_int' ] ] = conference if nodes_id : for node_id in nodes_id : graph . add_edge ( node_id , author [ "author_id" ] , weight = None ) nodes_id . append ( author [ "author_id" ] ) graph = self . __add_weights ( graph ) return graph
Function to create the graph using NetworkX.
Function to create the graph using NetworkX .
'''
        Function to create the graph using NetworkX.
        Args:
            data_path: The path to the json file with the graph data
        Returns:
            A NetworkX graph object
        '''
A NetworkX graph object
A NetworkX graph object
self
data_path
str
The path to the json file with the graph data
The path to the json file with the graph data