Commit 4deeb483 authored by Studer Brendan's avatar Studer Brendan
Browse files

corrected bug

parent 835b7852
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ def min_max_scores(content):
def find_scene_scores(scene, weight_name):
    graph, end_nodes = create_graph(scene)
    
    scene_min_score = 0
    scene_max_score = 0
    scene_min_score = 10000
    scene_max_score = -1000
    
    #scene_min_path = []
    #scene_max_path = []
@@ -53,6 +53,7 @@ def find_scene_scores(scene, weight_name):
        
        #Iterate over all paths
        for path in paths:
            
            path_weight = nx.path_weight(graph,path,weight=weight_name)
            
            # if the score of the current path is lower than the scene_min_score, we replace scene_min_score by the weight of the current path
@@ -88,12 +89,12 @@ def normalize_string(text):
    return text.lower().replace(" ", "_").replace("é", "e") \
        .replace("ê", "e").replace("è", "e").replace("à", "a")

def show_graph(graph):
def show_graph(graph, attribut):
    pos = nx.spring_layout(graph, seed=7)
    nx.draw_networkx_nodes(graph, pos, node_size=700)
    nx.draw_networkx_edges(graph, pos, edgelist=graph.edges(data=True), width=6)
    nx.draw_networkx_labels(graph, pos, font_size=20, font_family="sans-serif")
    edge_labels = nx.get_edge_attributes(graph, "score")
    edge_labels = nx.get_edge_attributes(graph, attribut)
    nx.draw_networkx_edge_labels(graph, pos, edge_labels)
    ax = plt.gca()
    ax.margins(0.08)
@@ -118,12 +119,19 @@ if __name__ == "__main__":
    with open("Chapters.json", 'r', encoding="utf-8") as j:
        contents = json.loads(j.read())
        
        scene = contents["Chapters"][0]["Scenes"][0]
        min_score, max_score = find_scene_scores(scene)
        scene = contents["Chapters"][0]["Scenes"][3]
        
        #min_authenticiy, max_authenticiy = find_scene_scores(scene,  'authenticiy')
        min_respect, max_respect = find_scene_scores(scene,  'respect')
        #min_compassion, max_compassion = find_scene_scores(scene,  'compassion')
        #min_hope, max_hope = find_scene_scores(scene,  'hope')
        #min_empathy, max_empathy = find_scene_scores(scene,  'empathy')
        
        print("Scores for "+scene["Title"])          
        print(f"Min: {min_score}")  
        print(f"Max: {max_score}")
        print("min:"+str(min_respect))
        print("max:"+ str(max_respect))
        
        graph, end_nodes = create_graph(scene)
        show_graph(graph,"respect")