Commit 18a89aa5 authored by Studer Brendan's avatar Studer Brendan
Browse files

pour henri la fourmie

parent 8344f0bc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -165,3 +165,4 @@ cython_debug/

# End of https://www.toptal.com/developers/gitignore/api/python
variables.txt
variables.nani
+8 −3
Original line number Diff line number Diff line
import json
import logging
import networkx as nx
import matplotlib.pyplot as plt

from loguru import logger

OUTPUT_FILE = "variables.txt"
OUTPUT_FILE = "variables.nani"

def min_max_scores(content):
    logger.info("Computing scores for all scenes. It may take a bit of time...")
@@ -84,6 +83,11 @@ def create_graph(scene):
                end_nodes.add(current_node)
    return graph, end_nodes

def normalize_string(text):
    """Normalize an input string"""
    return text.lower().replace(" ", "_").replace("é", "e") \
        .replace("ê", "e").replace("è", "e").replace("à", "a")

def show_graph(graph):
    pos = nx.spring_layout(graph, seed=7)
    nx.draw_networkx_nodes(graph, pos, node_size=700)
@@ -102,7 +106,8 @@ def write_vars_to_file(scores):
    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")      
                f.write("@set "+normalize_string(key.upper())+"_"+normalize_string(emotion.upper())+"="+str(scores[key][emotion])+"\n")     
        f.write("@stop") 

if __name__ == "__main__":