From c6d2415271a48fa43ca7c06996424e55920f2a0d Mon Sep 17 00:00:00 2001 From: AntonObersteiner Date: Wed, 5 Jun 2024 12:47:02 +0200 Subject: [PATCH] fix data generation: hidden data is local otherwise, the first data generation emties the data and the second get none --- generate.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/generate.py b/generate.py index b1a5001..d7ed699 100755 --- a/generate.py +++ b/generate.py @@ -200,14 +200,10 @@ network = Network( ), ) -def pop_hidden_data(): - global hidden_data - index = randint(0, len(hidden_data) - 1) - return hidden_data.pop(index) - def generate_text(number_of_lines = 200, language = None): """ language can be None (both), "en" or "de". """ + local_hidden_data = hidden_data[:] do_german = not language or language == "de" do_english = not language or language == "en" result = "" @@ -225,8 +221,9 @@ def generate_text(number_of_lines = 200, language = None): english += both if do_german: result += german + "\n" if do_english: result += english + "\n" - if random() < len(hidden_data) / (number_of_lines - i): - hidden_line = pop_hidden_data() + if random() < len(local_hidden_data) / (number_of_lines - i): + index = randint(0, len(local_hidden_data) - 1) + hidden_line = local_hidden_data.pop(index) german, english = hidden_line.split("\n") if do_german: result += german + "\n" if do_english: result += english + "\n"