feat: Ingest authentic Grade 10 Math Unit 2 (Circle) with full theorems, LaTeX proofs, exercises, and exam

This commit is contained in:
Hamza-Ayed
2026-08-29 04:43:18 +03:00
parent 8230b42ac1
commit 8cbb87cb51
10 changed files with 571 additions and 5 deletions
+32 -5
View File
@@ -47,14 +47,41 @@ function parseAndIngestTextbookMarkdown(string $rawMarkdown, array $metadata = [
$unitCounter = 0;
$lessonCounter = 0;
$arabicOrdinalMap = [
'الأولى' => 1, 'الاولى' => 1, '1' => 1, 'one' => 1,
'الثانية' => 2, 'الثانيه' => 2, '2' => 2, 'two' => 2,
'الثالثة' => 3, 'الثالثه' => 3, '3' => 3, 'three' => 3,
'الرابعة' => 4, 'الرابعه' => 4, '4' => 4, 'four' => 4,
'الخامسة' => 5, 'الخامسه' => 5, '5' => 5, 'five' => 5,
'السادسة' => 6, 'السادسه' => 6, '6' => 6, 'six' => 6,
'السابعة' => 7, 'السابعه' => 7, '7' => 7, 'seven' => 7,
'الثامنة' => 8, 'الثامنه' => 8, '8' => 8, 'eight' => 8,
'التاسعة' => 9, 'التاسعه' => 9, '9' => 9, 'nine' => 9,
'العاشرة' => 10, 'العاشره' => 10, '10' => 10, 'ten' => 10,
];
foreach ($lines as $line) {
$trimmed = trim($line);
// Detect Unit (# UNIT or # الوحدة)
if (preg_match('/^#\s+(UNIT|الوحدة)\s*([0-9\-\:A-Za-z\s]+)(.*)$/ui', $trimmed, $m) || preg_match('/^#\s+([A-Za-z0-9\s]+(?:SPOT|SKILLS|REFERENCE|LIST))/ui', $trimmed, $m2)) {
if (preg_match('/^#\s+(UNIT|الوحدة)\s*([0-9\-\:A-Za-z\s\p{Arabic}]+)(.*)$/ui', $trimmed, $m) || preg_match('/^#\s+([A-Za-z0-9\s]+(?:SPOT|SKILLS|REFERENCE|LIST))/ui', $trimmed, $m2)) {
$flushUnit();
$unitCounter++;
$unitTitle = trim(preg_replace('/^#\s+/u', '', $trimmed));
// Try to extract unit number from title
$detectedNum = null;
foreach ($arabicOrdinalMap as $word => $num) {
if (mb_stripos($unitTitle, $word) !== false) {
$detectedNum = $num;
break;
}
}
if ($detectedNum !== null) {
$unitCounter = $detectedNum;
} else {
$unitCounter++;
}
$unitKey = sprintf('unit_%02d', $unitCounter);
$currentUnit = [
@@ -66,8 +93,8 @@ function parseAndIngestTextbookMarkdown(string $rawMarkdown, array $metadata = [
continue;
}
// Detect Lesson (## Lesson or ## الدرس or ## معمل or ## )
if (preg_match('/^##\s+(Lesson|الدرس|قسم|المحطة|قواعد|تمارين|معمل)\s*([0-9\-\:A-Za-z\s]+)(.*)$/ui', $trimmed, $m) || (preg_match('/^##\s+(.+)$/u', $trimmed, $mAlt) && $currentUnit)) {
// Detect Lesson (## Lesson or ## الدرس or ## معمل or ## مقدمة or ## اختبار or ## )
if (preg_match('/^##\s+(Lesson|الدرس|قسم|المحطة|قواعد|تمارين|معمل|مقدمة|مشروع|اختبار)\s*([0-9\-\:A-Za-z\s\p{Arabic}]+)(.*)$/ui', $trimmed, $m) || (preg_match('/^##\s+(.+)$/u', $trimmed, $mAlt) && $currentUnit)) {
$flushLesson();
$lessonCounter++;
$lessonTitle = trim(preg_replace('/^##\s+/u', '', $trimmed));
@@ -77,7 +104,7 @@ function parseAndIngestTextbookMarkdown(string $rawMarkdown, array $metadata = [
$unitCounter++;
$currentUnit = [
'unit_key' => sprintf('unit_%02d', $unitCounter),
'unit_name' => 'الوحدة الأولى: المعادلات',
'unit_name' => 'الوحدة ' . $unitCounter,
'lessons' => []
];
}