Parses the reasoning steps from a given text. Parameters: - text (str): The text containing reasoning steps. Returns: - dict: A dictionary mapping step numbers to their content.
(text)
| 344 | """ |
| 345 | |
| 346 | def parse_steps(text): |
| 347 | """ |
| 348 | Parses the reasoning steps from a given text. |
| 349 | |
| 350 | Parameters: |
| 351 | - text (str): The text containing reasoning steps. |
| 352 | |
| 353 | Returns: |
| 354 | - dict: A dictionary mapping step numbers to their content. |
| 355 | """ |
| 356 | step_pattern = re.compile(r"Step\s+(\d+):\s*") |
| 357 | steps = {} |
| 358 | current_step_num = None |
| 359 | current_content = [] |
| 360 | |
| 361 | for line in text.splitlines(): |
| 362 | step_match = step_pattern.match(line) |
| 363 | if step_match: |
| 364 | # If there's an ongoing step, save its content |
| 365 | if current_step_num is not None: |
| 366 | steps[current_step_num] = "\n".join(current_content).strip() |
| 367 | current_step_num = int(step_match.group(1)) |
| 368 | content = line[step_match.end():].strip() |
| 369 | current_content = [content] if content else [] |
| 370 | else: |
| 371 | if current_step_num is not None: |
| 372 | current_content.append(line) |
| 373 | |
| 374 | # Save the last step if any |
| 375 | if current_step_num is not None: |
| 376 | steps[current_step_num] = "\n".join(current_content).strip() |
| 377 | |
| 378 | return steps |
| 379 | |
| 380 | # Parse the original and replacement steps |
| 381 | origin_steps = parse_steps(origin_str) |
no outgoing calls
no test coverage detected