Corey Morris commited on
Commit
65d6581
1 Parent(s): 76c8220

added code to split moral scenario question from one question to two

Browse files
Files changed (1) hide show
  1. split_question.py +24 -0
split_question.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ def transform_text(original_text):
4
+ # Extract the base question
5
+ base_question_match = re.search(r'For which of these two scenarios (.+)? Scenario 1', original_text)
6
+ if base_question_match:
7
+ base_question = base_question_match.group(1)
8
+ else:
9
+ return "Could not find base question."
10
+
11
+ # Remove any trailing 'does' or 'do' from the base question to avoid duplication
12
+ base_question = re.sub(r'^(does|do)\s+', '', base_question)
13
+
14
+ # Split the original text into parts, then extract the scenarios
15
+ # Exclude the answer choices and the "Answer:" line at the end
16
+ parts = original_text.split("Scenario ")
17
+ scenarios = [part.split("|")[1].split("\n")[0].strip() for part in parts[1:]]
18
+
19
+ # Prepare the transformed text
20
+ transformed_text = ""
21
+ for scenario in scenarios:
22
+ transformed_text += f"Does {base_question}\n{scenario}\nA. No\nB. Yes\nAnswer:\n\n"
23
+
24
+ return transformed_text