|
1 | 1 | # FSA Correction Module |
2 | 2 |
|
3 | | -Compares student FSAs against expected FSAs, leveraging the validation module for detailed feedback. |
| 3 | +Compares student FSAs against expected FSAs, returns `Result` with `FSAFeedback`. |
4 | 4 |
|
5 | 5 | ## Exports |
6 | 6 |
|
7 | 7 | ```python |
8 | 8 | from evaluation_function.correction import ( |
9 | | - analyze_fsa_correction, # Main pipeline |
| 9 | + analyze_fsa_correction, # Main pipeline -> Result |
10 | 10 | check_minimality, # Check if FSA is minimal |
11 | | - CorrectionResult, # Result model |
12 | 11 | ) |
13 | 12 | ``` |
14 | 13 |
|
15 | 14 | ## Pipeline |
16 | 15 |
|
17 | 16 | ``` |
18 | | -┌─────────────────────────────────────────────────────────────────┐ |
19 | | -│ analyze_fsa_correction() │ |
20 | | -│ (student_fsa, expected_fsa) │ |
21 | | -├─────────────────────────────────────────────────────────────────┤ |
22 | | -│ Step 1: Structural Validation │ |
23 | | -│ └── is_valid_fsa() → List[ValidationError] │ |
24 | | -├─────────────────────────────────────────────────────────────────┤ |
25 | | -│ Step 2: Minimality Check (optional) │ |
26 | | -│ └── check_minimality() → bool │ |
27 | | -├─────────────────────────────────────────────────────────────────┤ |
28 | | -│ Step 3: Structural Analysis │ |
29 | | -│ └── get_structured_info_of_fsa() → StructuralInfo │ |
30 | | -├─────────────────────────────────────────────────────────────────┤ |
31 | | -│ Step 4: Language Equivalence │ |
32 | | -│ └── fsas_accept_same_language() → are_isomorphic() │ |
33 | | -│ Provides detailed feedback with ElementHighlight │ |
34 | | -├─────────────────────────────────────────────────────────────────┤ |
35 | | -│ OUTPUT: CorrectionResult │ |
36 | | -│ ├── is_equivalent: bool │ |
37 | | -│ ├── is_isomorphic: bool │ |
38 | | -│ ├── is_minimal: Optional[bool] │ |
39 | | -│ ├── validation_errors: List[ValidationError] │ |
40 | | -│ ├── equivalence_errors: List[ValidationError] │ |
41 | | -│ └── structural_info: StructuralInfo │ |
42 | | -│ │ |
43 | | -│ Methods: │ |
44 | | -│ ├── .model_dump() → dict │ |
45 | | -│ ├── .to_fsa_feedback() → FSAFeedback │ |
46 | | -│ └── .get_language_comparison() → LanguageComparison │ |
47 | | -└─────────────────────────────────────────────────────────────────┘ |
| 17 | +analyze_fsa_correction(student_fsa, expected_fsa, require_minimal=False) -> Result |
| 18 | +├── 1. Validate student FSA (is_valid_fsa) |
| 19 | +├── 2. Check minimality (if required) |
| 20 | +├── 3. Structural analysis (get_structured_info_of_fsa) |
| 21 | +└── 4. Language equivalence (fsas_accept_same_language -> are_isomorphic) |
| 22 | + └── All "why" feedback comes from here |
48 | 23 | ``` |
49 | 24 |
|
50 | | -## Usage |
| 25 | +## Result |
51 | 26 |
|
52 | 27 | ```python |
53 | | -from evaluation_function.correction import analyze_fsa_correction, check_minimality |
54 | | - |
55 | | -# Compare two FSAs |
56 | | -result = analyze_fsa_correction(student_fsa, expected_fsa, check_minimality=True) |
57 | | - |
58 | | -# Check result |
59 | | -result.is_equivalent # bool |
60 | | -result.equivalence_errors # List[ValidationError] with ElementHighlight |
| 28 | +Result( |
| 29 | + is_correct: bool, # True if FSAs accept same language |
| 30 | + feedback: str, # Human-readable summary |
| 31 | + fsa_feedback: FSAFeedback # Structured feedback for UI |
| 32 | +) |
| 33 | +``` |
61 | 34 |
|
62 | | -# For UI |
63 | | -result.to_fsa_feedback() # FSAFeedback schema |
| 35 | +## Usage |
64 | 36 |
|
65 | | -# As dict |
66 | | -result.model_dump() # dict |
| 37 | +```python |
| 38 | +from evaluation_function.correction import analyze_fsa_correction |
67 | 39 |
|
68 | | -# Check minimality only |
69 | | -check_minimality(fsa) # bool |
| 40 | +result = analyze_fsa_correction(student_fsa, expected_fsa) |
| 41 | +result.is_correct # bool |
| 42 | +result.feedback # "Correct!" or "Languages differ: ..." |
| 43 | +result.fsa_feedback.errors # List[ValidationError] with ElementHighlight |
70 | 44 | ``` |
0 commit comments