SeverinJB / the_lads

Project "Scholarly Network Engine" - Examination for "Computational Thinking and Programming" - Second-cycle degree "Digital Humanities and Digital Knowledge" at the University of Bologna
0 stars 0 forks source link

do_aut_distance(data, sse, aut) #5

Open SeverinJB opened 5 years ago

SeverinJB commented 5 years ago

Functionality:

SeverinJB commented 5 years ago

The following solution has not yet been refactored but works and was tested thoroughly. I'll rewrite the code as soon as I have had a look at all the functions assigned to me. If you'd like to run the code, you have to use all files (sne.py, execution_example.py, and the_lads.py).

+++ do_aut_distance +++

def do_aut_distance(data, sse, aut):
    aut_distance = nx.MultiGraph()

    def assistant(sse, aut, tmp, visited=list()):
        visited.append(aut)
        tmp = nx.compose(tmp, nx.MultiGraph(sse.coauthor_network(aut)))

        for node in tmp:
            if node not in visited:
                tmp = assistant(sse, node, tmp)

        return tmp

    aut_distance = assistant(sse, aut, aut_distance)

    distance = nx.single_source_shortest_path_length(aut_distance, aut)
    nx.set_node_attributes(aut_distance, distance, "Distance")

    return aut_distance  

+++ execution_example.py +++

from sne import ScholarlyNetworkEngine
my_sne = ScholarlyNetworkEngine("metadata_sample.csv", "citations_sample.csv")
my_sne.aut_distance('Michel, Dumontier')

+++ the_lads.py +++

import pandas as pd
import networkx as nx

def process_citation_data(file_path):
    df = pd.read_csv(file_path, index_col='DOI', header=0, names=['DOI', 'citation_number', 'known_reference'])
    return df

def do_aut_distance(data, sse, aut):
    aut_distance = nx.MultiGraph()

    def assistant(sse, aut, tmp, visited=list()):
        visited.append(aut)
        tmp = nx.compose(tmp, nx.MultiGraph(sse.coauthor_network(aut)))

        for node in tmp:
            if node not in visited:
                tmp = assistant(sse, node, tmp)

        return tmp

    aut_distance = assistant(sse, aut, aut_distance)

    distance = nx.single_source_shortest_path_length(aut_distance, aut)
    nx.set_node_attributes(aut_distance, distance, "Distance")

    return aut_distance
dersuchendee commented 5 years ago
def process_citation_data(file_path):
    df = pd.read_csv(file_path, index_col='DOI', header=0, names=['DOI', 'citation_number', 'known_reference'])
    return df

def do_aut_distance(data, sse, aut):
    aut_distance = nx.MultiGraph() #create a graph

    def assistant(sse, aut, tmp, visited=list()): #ancillary function
        visited.append(aut) #append in the visited list the authors
        tmp = nx.compose(tmp, nx.MultiGraph(sse.coauthor_network(aut))) #create a new graph that is called 'tmp' and is composed of the authors in the coauthor network in sse

        for node in tmp:
            if node not in visited: #for author in tmp, if author doesn't appear in visited aut list
                tmp = assistant(sse, node, tmp) #?

        return tmp

    aut_distance = assistant(sse, aut, aut_distance)

    distance = nx.single_source_shortest_path_length(aut_distance, aut) #distance is shortest path from aut (source) to aut_distance 
    nx.set_node_attributes(aut_distance, distance, "Distance") #attrubutes of aut_distance are the number that came out from distance, and they are called 'Distance'

    return aut_distance #return the aut_distance graph