Loading eol_json_parser.py +6 −10 Original line number Diff line number Diff line """Parser for command line option""" import getopt import json import logging import os import shutil import sys from config.app_config import AppConfig from features.min_max_stats_finder import min_max_scores logging.basicConfig( format='[%(name)s::%(levelname)s]\t\t%(message)s', level=logging.DEBUG) _logger = logging.getLogger(__name__) from loguru import logger from config.app_config import AppConfig from features.min_max_stats_finder import min_max_scores, write_vars_to_file def show_chapters(chapters): """Print a summary of the content of the json file""" Loading Loading @@ -71,14 +67,14 @@ def main(argv): #if --scores argument exists if scores: scores = min_max_scores(contents) _logger.info(scores) write_vars_to_file(scores) sys.exit(0) # if output folder already exist, we delete it if os.path.exists(output_folder): shutil.rmtree(output_folder) _logger.debug("Creating %s folder...", output_folder) logger.debug("Creating %s folder...", output_folder) os.mkdir(output_folder) # Iterate over chapters Loading Loading @@ -150,7 +146,7 @@ def main(argv): f"@choice \"{choice['Text']}\" {stat_update} goto:.{choice['NextInteractionID']}\n") f.write("@stop\n\n") _logger.debug("DONE !") logger.debug("DONE !") if __name__ == "__main__": Loading features/min_max_stats_finder.py +35 −12 Original line number Diff line number Diff line Loading @@ -3,27 +3,43 @@ import logging import networkx as nx import matplotlib.pyplot as plt logging.basicConfig( format='[%(name)s::%(levelname)s]\t\t%(message)s', level=logging.DEBUG) from loguru import logger _logger = logging.getLogger(__name__) OUTPUT_FILE = "variables.txt" def min_max_scores(content): _logger.info("Computing scores for all scenes. It may take a bit of time...") logger.info("Computing scores for all scenes. It may take a bit of time...") scores = dict() #Ierate over chapters for idx_chapter, chapter in enumerate(content["Chapters"]): #Iterate over scenes for idx_scene, scene in enumerate(chapter["Scenes"]): scene_name = scene["Title"] min_score, max_score = find_scene_scores(scene) min_score, max_score = find_scene_scores(scene, 'score') 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') scores[scene_name] = { "max": max_score, "min": min_score "max_score": max_score, "min_Score": min_score, "max_authenticiy": max_authenticiy, "min_authenticiy": min_authenticiy, "max_respect": max_respect, "min_respect": min_respect, "max_compassion": max_compassion, "min_compassion": min_compassion, "max_hope": max_hope, "min_hope": min_hope, "max_empathy": max_empathy, "min_empathy": min_empathy } return scores def find_scene_scores(scene): def find_scene_scores(scene, weight_name): graph, end_nodes = create_graph(scene) scene_min_score = 0 Loading @@ -38,7 +54,7 @@ def find_scene_scores(scene): #Iterate over all paths for path in paths: path_weight = nx.path_weight(graph,path,weight='weight') 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 if path_weight < scene_min_score: Loading @@ -63,7 +79,7 @@ def create_graph(scene): child_node = choice["NextInteractionID"] score = choice["Authenticity"] + choice["Respect"] + choice["Compassion"] + choice["Hope"] + choice["Empathy"] if child_node != -1: graph.add_edge(current_node,child_node, weight=score) graph.add_edge(current_node,child_node, score=score, authenticiy=choice["Authenticity"], respect=choice["Respect"], compassion=choice["Compassion"], hope=choice["Hope"], empathy=choice["Empathy"]) else: end_nodes.add(current_node) return graph, end_nodes Loading @@ -73,7 +89,7 @@ def show_graph(graph): 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, "weight") edge_labels = nx.get_edge_attributes(graph, "score") nx.draw_networkx_edge_labels(graph, pos, edge_labels) ax = plt.gca() ax.margins(0.08) Loading @@ -81,9 +97,16 @@ def show_graph(graph): plt.tight_layout() plt.show() def write_vars_to_file(scores): logger.info("Writing scores int ouput file "+OUTPUT_FILE) with open(OUTPUT_FILE, 'w', encoding='utf-8') as f: for key in scores: for emotion in scores[key]: f.write(key.upper()+"_"+emotion.upper()+"="+str(scores[key][emotion])+"\n") if __name__ == "__main__": _logger.info("Testing find_scene_scores for first scene...") logger.info("Testing find_scene_scores for first scene...") with open("Chapters.json", 'r', encoding="utf-8") as j: contents = json.loads(j.read()) Loading Loading
eol_json_parser.py +6 −10 Original line number Diff line number Diff line """Parser for command line option""" import getopt import json import logging import os import shutil import sys from config.app_config import AppConfig from features.min_max_stats_finder import min_max_scores logging.basicConfig( format='[%(name)s::%(levelname)s]\t\t%(message)s', level=logging.DEBUG) _logger = logging.getLogger(__name__) from loguru import logger from config.app_config import AppConfig from features.min_max_stats_finder import min_max_scores, write_vars_to_file def show_chapters(chapters): """Print a summary of the content of the json file""" Loading Loading @@ -71,14 +67,14 @@ def main(argv): #if --scores argument exists if scores: scores = min_max_scores(contents) _logger.info(scores) write_vars_to_file(scores) sys.exit(0) # if output folder already exist, we delete it if os.path.exists(output_folder): shutil.rmtree(output_folder) _logger.debug("Creating %s folder...", output_folder) logger.debug("Creating %s folder...", output_folder) os.mkdir(output_folder) # Iterate over chapters Loading Loading @@ -150,7 +146,7 @@ def main(argv): f"@choice \"{choice['Text']}\" {stat_update} goto:.{choice['NextInteractionID']}\n") f.write("@stop\n\n") _logger.debug("DONE !") logger.debug("DONE !") if __name__ == "__main__": Loading
features/min_max_stats_finder.py +35 −12 Original line number Diff line number Diff line Loading @@ -3,27 +3,43 @@ import logging import networkx as nx import matplotlib.pyplot as plt logging.basicConfig( format='[%(name)s::%(levelname)s]\t\t%(message)s', level=logging.DEBUG) from loguru import logger _logger = logging.getLogger(__name__) OUTPUT_FILE = "variables.txt" def min_max_scores(content): _logger.info("Computing scores for all scenes. It may take a bit of time...") logger.info("Computing scores for all scenes. It may take a bit of time...") scores = dict() #Ierate over chapters for idx_chapter, chapter in enumerate(content["Chapters"]): #Iterate over scenes for idx_scene, scene in enumerate(chapter["Scenes"]): scene_name = scene["Title"] min_score, max_score = find_scene_scores(scene) min_score, max_score = find_scene_scores(scene, 'score') 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') scores[scene_name] = { "max": max_score, "min": min_score "max_score": max_score, "min_Score": min_score, "max_authenticiy": max_authenticiy, "min_authenticiy": min_authenticiy, "max_respect": max_respect, "min_respect": min_respect, "max_compassion": max_compassion, "min_compassion": min_compassion, "max_hope": max_hope, "min_hope": min_hope, "max_empathy": max_empathy, "min_empathy": min_empathy } return scores def find_scene_scores(scene): def find_scene_scores(scene, weight_name): graph, end_nodes = create_graph(scene) scene_min_score = 0 Loading @@ -38,7 +54,7 @@ def find_scene_scores(scene): #Iterate over all paths for path in paths: path_weight = nx.path_weight(graph,path,weight='weight') 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 if path_weight < scene_min_score: Loading @@ -63,7 +79,7 @@ def create_graph(scene): child_node = choice["NextInteractionID"] score = choice["Authenticity"] + choice["Respect"] + choice["Compassion"] + choice["Hope"] + choice["Empathy"] if child_node != -1: graph.add_edge(current_node,child_node, weight=score) graph.add_edge(current_node,child_node, score=score, authenticiy=choice["Authenticity"], respect=choice["Respect"], compassion=choice["Compassion"], hope=choice["Hope"], empathy=choice["Empathy"]) else: end_nodes.add(current_node) return graph, end_nodes Loading @@ -73,7 +89,7 @@ def show_graph(graph): 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, "weight") edge_labels = nx.get_edge_attributes(graph, "score") nx.draw_networkx_edge_labels(graph, pos, edge_labels) ax = plt.gca() ax.margins(0.08) Loading @@ -81,9 +97,16 @@ def show_graph(graph): plt.tight_layout() plt.show() def write_vars_to_file(scores): logger.info("Writing scores int ouput file "+OUTPUT_FILE) with open(OUTPUT_FILE, 'w', encoding='utf-8') as f: for key in scores: for emotion in scores[key]: f.write(key.upper()+"_"+emotion.upper()+"="+str(scores[key][emotion])+"\n") if __name__ == "__main__": _logger.info("Testing find_scene_scores for first scene...") logger.info("Testing find_scene_scores for first scene...") with open("Chapters.json", 'r', encoding="utf-8") as j: contents = json.loads(j.read()) Loading