Initial Persp generation

This commit is contained in:
2026-07-11 20:30:27 +02:00
parent fd35675e4c
commit 09befe1d55
4 changed files with 175 additions and 14 deletions
+37
View File
@@ -34,6 +34,43 @@ def pdf_image_of_solution(root_dir, label):
if os.path.exists(pdf_path):
return pdf_path
def pdf_images_of_contexts(root_dir, label, all_labels):
text2_dir = os.path.join(root_dir, "Text2")
if not os.path.isdir(text2_dir):
return []
# Map safe labels (with '/' replaced by '_') to their chronological index
safe_to_idx = {l.replace("/", "_"): i for i, l in enumerate(all_labels)}
safe_target = label.replace("/", "_")
target_idx = safe_to_idx.get(safe_target, -1)
if target_idx == -1:
return []
pertinent_contexts = []
for filename in os.listdir(text2_dir):
if filename.startswith("CTXT ") and filename.endswith(".pdf"):
# Extract "first_label -> last_label" from "CTXT first_label -> last_label.pdf"
core = filename[5:-4]
parts = core.split(" -> ")
if len(parts) == 2:
first_safe, last_safe = parts
first_idx = safe_to_idx.get(first_safe, -1)
last_idx = safe_to_idx.get(last_safe, -1)
# Check if the current label falls within the context's validity range
if first_idx != -1 and last_idx != -1:
if first_idx <= target_idx <= last_idx:
pdf_path = os.path.join(text2_dir, filename)
pertinent_contexts.append((first_idx, pdf_path))
# Sort by first_idx to ensure contexts are returned in logical reading order
pertinent_contexts.sort(key=lambda x: x[0])
return [path for _, path in pertinent_contexts]
def get_exam_file_content(folder_path, mode, label):
"""