debug_improved_matching.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use App\Services\OCRDataParser;
  3. use App\Models\PaperQuestion;
  4. use App\Models\OCRRecord;
  5. require __DIR__ . '/vendor/autoload.php';
  6. $app = require_once __DIR__ . '/bootstrap/app.php';
  7. $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
  8. $kernel->bootstrap();
  9. $recordId = 4;
  10. $ocrRecord = OCRRecord::find($recordId);
  11. $rawOcrData = \Illuminate\Support\Facades\DB::table('ocr_raw_data')
  12. ->where('ocr_record_id', $recordId)
  13. ->value('raw_response');
  14. if (!$rawOcrData) {
  15. echo "No raw data found for record {$recordId}\n";
  16. exit;
  17. }
  18. $rawOcrData = json_decode($rawOcrData, true);
  19. $paperQuestions = PaperQuestion::where('paper_id', $ocrRecord->analysis_id)
  20. ->orderBy('question_number')
  21. ->get();
  22. $parser = new OCRDataParser();
  23. echo "Testing matchWithSystemPaper with improved logic...\n";
  24. $results = $parser->matchWithSystemPaper($rawOcrData, $paperQuestions);
  25. foreach ($results as $qNum => $result) {
  26. echo "Question {$qNum}:\n";
  27. echo " Y-Range: {$result['coordinates']['y_min']} - {$result['coordinates']['y_max']}\n";
  28. echo " Answer: " . mb_substr($result['student_answer'], 0, 50) . "...\n";
  29. }