Spaces:
Running
Running
File size: 1,663 Bytes
f2ec360 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
'''def qStr2Dict(question: str) -> dict:
print('qStr2Dict :', question)
split = question.strip(" '\"").split(".", 1)
question_dict = {'id': int(split[0]), 'question': split[-1].strip()}
return question_dict
def result2QuestionsList(question_response: str, type: str, status: str) -> list:
response_splits = question_response.split("\n")
qlist = []
for q in response_splits:
question = {**qStr2Dict(q), 'type': type, 'status': status, 'answer': None}
qlist = qlist + [question]
return qlist
'''
def qStr2Dict(question: str) -> dict:
try:
print('qStr2Dict:', question)
split = question.strip(" '\"").split(".", 1)
# Check if id_part is 'Here are the sub-questions:', set it to integer 1
id_part = split[0].replace("#", "").strip()
if isinstance(id_part, str):
id_part = 1 # Convert any string to integer 1
# Convert id_part to integer, if not empty
id_part = int(id_part) if id_part else None
question_dict = {'id': id_part, 'question': split[-1].strip()}
return question_dict
except ValueError as e:
print("Error:", e)
return {'id': None, 'question': question.strip()}
def result2QuestionsList(question_response: str, type: str, status: str) -> list:
response_splits = question_response.split("\n")
qlist = []
for q in response_splits:
# Skip empty lines
if q.strip() == '':
continue
question = qStr2Dict(q)
question.update({'type': type, 'status': status, 'answer': None})
qlist.append(question)
return qlist |