fix data generation: hidden data is local

otherwise, the first data generation emties the data and the second get
none
This commit is contained in:
AntonObersteiner 2024-06-05 12:47:02 +02:00
parent e71e30ce86
commit c6d2415271

View file

@ -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"