feat: Ingest authentic Grade 10 Math Unit 1 with complete LaTeX equations and full derivations

This commit is contained in:
Hamza-Ayed
2026-08-29 03:32:37 +03:00
parent 39cf087488
commit eb94f6ff77
7 changed files with 368 additions and 23 deletions
@@ -0,0 +1,112 @@
<?php
require_once __DIR__ . '/../app/bootstrap.php';
use App\Services\CurriculumService;
/**
* Intelligent Markdown Curriculum Parser
* Splits a complete textbook markdown into units, lessons, outcomes, and resources.
*/
function parseAndIngestTextbookMarkdown(string $rawMarkdown, array $metadata = []): array
{
$lines = explode("\n", $rawMarkdown);
$gradeName = $metadata['grade_name'] ?? 'الصف العاشر';
$gradeKey = $metadata['grade_key'] ?? 'grade_10';
$subName = $metadata['subject_name'] ?? 'الرياضيات';
$subKey = $metadata['subject_key'] ?? 'math_10';
$semName = $metadata['semester_name'] ?? 'الفصل الدراسي الأول';
$semKey = $metadata['semester_key'] ?? 'semester_1';
$units = [];
$currentUnit = null;
$currentLesson = null;
$lessonBuffer = [];
$flushLesson = function() use (&$currentUnit, &$currentLesson, &$lessonBuffer) {
if ($currentUnit && $currentLesson) {
$content = trim(implode("\n", $lessonBuffer));
if (!empty($content)) {
$currentLesson['markdown_content'] = $content;
$currentUnit['lessons'][] = $currentLesson;
}
$currentLesson = null;
$lessonBuffer = [];
}
};
$flushUnit = function() use (&$units, &$currentUnit, $flushLesson) {
$flushLesson();
if ($currentUnit && !empty($currentUnit['lessons'])) {
$units[] = $currentUnit;
$currentUnit = null;
}
};
$unitCounter = 0;
$lessonCounter = 0;
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)) {
$flushUnit();
$unitCounter++;
$unitTitle = trim(preg_replace('/^#\s+/u', '', $trimmed));
$unitKey = sprintf('unit_%02d', $unitCounter);
$currentUnit = [
'unit_key' => $unitKey,
'unit_name' => $unitTitle,
'lessons' => []
];
$lessonCounter = 0;
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)) {
$flushLesson();
$lessonCounter++;
$lessonTitle = trim(preg_replace('/^##\s+/u', '', $trimmed));
$lesId = sprintf('lesson_%02d', $lessonCounter);
if (!$currentUnit) {
$unitCounter++;
$currentUnit = [
'unit_key' => sprintf('unit_%02d', $unitCounter),
'unit_name' => 'الوحدة الأولى: المعادلات',
'lessons' => []
];
}
$currentLesson = [
'lesson_id' => $lesId,
'title' => $lessonTitle,
'outcomes' => [$lessonTitle]
];
$lessonBuffer = [$trimmed];
continue;
}
if ($currentLesson) {
$lessonBuffer[] = $line;
}
}
$flushUnit();
$extracted = [
'grade_name' => $gradeName,
'grade_key' => $gradeKey,
'subject_name' => $subName,
'subject_key' => $subKey,
'semester_name' => $semName,
'semester_key' => $semKey,
'units' => $units
];
return CurriculumService::mergeExtractedCurriculum($extracted);
}
+18
View File
@@ -0,0 +1,18 @@
<?php
require_once __DIR__ . '/../app/bootstrap.php';
require_once __DIR__ . '/curriculum_markdown_parser.php';
$mathMarkdown = file_get_contents(__DIR__ . '/unit1_math_full.md');
$metadata = [
'grade_name' => 'الصف العاشر',
'grade_key' => 'grade_10',
'subject_name' => 'الرياضيات',
'subject_key' => 'math_10',
'semester_name' => 'الفصل الدراسي الأول',
'semester_key' => 'semester_1'
];
$res = parseAndIngestTextbookMarkdown($mathMarkdown, $metadata);
echo "SUCCESS! Ingested Math Unit 1 into storage/curriculum!\n";
+95
View File
@@ -0,0 +1,95 @@
# الوحدة الأولى: المعادلات (Equations)
## الدرس 1: حل معادلات خاصة (Solving Special Equations)
### فكرة الدرس
حل معادلات خاصة أس المتغير فيها عدد صحيح موجب أكبر من 2.
### المصطلحات
الصورة التربيعية (Quadratic Form).
### مسألة اليوم (صفحة 8)
> كيس للهدايا على شكل متوازي مستطيلات، حجمه $1152\text{ cm}^3$، وأبعاده بدلالة المتغير $w$: الطول $(18 - w)\text{ cm}$، العرض $w\text{ cm}$، الارتفاع $(2w + 4)\text{ cm}$. أجد أبعاده.
### البند 1: حل المعادلات بإخراج العامل المشترك الأكبر
> **أتعلم:** أكتب جميع حدود المعادلة في الطرف الأيسر من المعادلة قبل إخراج العامل المشترك الأكبر.
> **أتعلم:** أحتاج في بعض المعادلات إلى استعمال طرائق حل المعادلات التربيعية التي تعلمتها سابقاً، بعد إخراج العامل المشترك الأكبر.
#### مثال 1: أحل كلاً من المعادلات الآتية:
##### 1) $x^3 + 4x^2 = 5x$
- المعادلة المعطاة: $x^3 + 4x^2 = 5x$
- بطرح $5x$ من طرفي المعادلة: $x^3 + 4x^2 - 5x = 0$
- بالتحليل بإخراج العامل المشترك الأكبر $x$:
$$x(x^2 + 4x - 5) = 0$$
- بالتحليل إلى العوامل (ثلاثي الحدود التربيعي):
$$x(x + 5)(x - 1) = 0$$
- باستخدام خاصية الضرب الصفري:
$$x = 0 \quad \text{أو} \quad x + 5 = 0 \quad \text{أو} \quad x - 1 = 0$$
- إذن، جذور المعادلة هي: $\{-5, 0, 1\}$.
##### 2) $2x^3 = 18x$
- المعادلة المعطاة: $2x^3 = 18x$
- بطرح $18x$ من طرفي المعادلة: $2x^3 - 18x = 0$
- بالتحليل بإخراج العامل المشترك الأكبر $2x$:
$$2x(x^2 - 9) = 0$$
- بتحليل الفرق بين مربعين:
$$2x(x - 3)(x + 3) = 0$$
- إذن، جذور المعادلة هي: $\{-3, 0, 3\}$.
### البند 2: حل المعادلات بالتجميع (Factoring by Grouping)
#### مثال 2:
##### 1) $x^3 - 2x^2 + 9x - 18 = 0$
- بتجميع الحدود ذات العوامل المشتركة:
$$(x^3 - 2x^2) + (9x - 18) = 0$$
- بتحليل كل تجميع:
$$x^2(x - 2) + 9(x - 2) = 0 \implies (x - 2)(x^2 + 9) = 0$$
- بما أن مميز $x^2 + 9 = 0$ سالب ($\Delta = -36 < 0$)، فإن الجذر الحقيقي الوحيد هو: $x = 2$.
##### 2) $4x^3 + 8x^2 - 5x - 10 = 0$
$$(4x^3 + 8x^2) - (5x + 10) = 0 \implies 4x^2(x + 2) - 5(x + 2) = 0 \implies (x + 2)(4x^2 - 5) = 0$$
- الجذور: $\left\{-2, -\frac{\sqrt{5}}{2}, \frac{\sqrt{5}}{2}\right\}$.
### البند 3: تحليل مجموع مكعبين أو الفرق بينهما
- $a^3 + b^3 = (a + b)(a^2 - ab + b^2)$
- $a^3 - b^3 = (a - b)(a^2 + ab + b^2)$
#### مثال 3:
1) $8x^3 + 1 = 0 \implies (2x + 1)(4x^2 - 2x + 1) = 0 \implies x = -\frac{1}{2}$
2) $x^3 - 125 = 0 \implies (x - 5)(x^2 + 5x + 25) = 0 \implies x = 5$
3) $128x^5 - 54x^2 = 0 \implies 2x^2(64x^3 - 27) = 0 \implies 2x^2(4x - 3)(16x^2 + 12x + 9) = 0 \implies x \in \{0, \frac{3}{4}\}$
### البند 4: حل معادلات على الصورة التربيعية (Quadratic Form)
#### مثال 4: $x^6 - 3x^3 - 40 = 0$
- بفرض $u = x^3$:
$$u^2 - 3u - 40 = 0 \implies (u - 8)(u + 5) = 0$$
$$x^3 = 8 \implies x = 2, \quad x^3 = -5 \implies x = \sqrt[3]{-5}$$
### مهارات التفكير العليا
1) **أكتشف الخطأ:** حل نداء $2x^4 - 18x^2 = 0$ أهمل الجذر $x = 0$. الحل الصحيح $\{-3, 0, 3\}$.
2) **تحدٍّ:** $(x^2 - 1)^2 - 2(x^2 - 1) = 3 \implies u^2 - 2u - 3 = 0 \implies u = 3, u = -1 \implies x \in \{-2, 0, 2\}$.
3) **تبرير:** $5x^3 + wx^2 + 80x = 0 \implies x(5x^2 + wx + 80) = 0 \implies \Delta = w^2 - 1600 = 0 \implies w = \pm 40$.
## معمل جيوجبرا: حل أنظمة المعادلات بيانياً
### النشاط
حل نظام المعادلات التربيعية بيانياً باستعمال برمجية جيوجبرا:
$$\begin{cases} x^2 + y^2 = 13 \\ x^2 - y = 7 \end{cases}$$
نقاط التقاطع الأربع:
$$A(-2, -3), \quad B(2, -3), \quad C(-3, 2), \quad D(3, 2)$$
## الدرس 2: حل نظام مكون من معادلة خطية ومعادلة تربيعية
### فكرة الدرس
حل نظام مكون من معادلة خطية وأخرى تربيعية.
### مثال 1:
$$\begin{cases} x - y = 1 \implies y = x - 1 \\ x^2 + y^2 = 5 \end{cases}$$
$$x^2 + (x - 1)^2 = 5 \implies 2x^2 - 2x - 4 = 0 \implies x^2 - x - 2 = 0$$
$$(x - 2)(x + 1) = 0 \implies x = 2, x = -1$$
- $x = 2 \implies y = 1 \implies (2, 1)$
- $x = -1 \implies y = -2 \implies (-1, -2)$
الحلول: $\{(2, 1), (-1, -2)\}$.
### مثال 2 (سجادة مستطيلة):
سجادة مستطيلة مجموع بعديها $7\text{ m}$ وقطرها $5\text{ m}$:
$$x + y = 7, \quad x^2 + y^2 = 25 \implies (x-4)(x-3)=0 \implies \text{الطول } 4\text{ m}, \text{ والعرض } 3\text{ m}$$