| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use App\Models\SourceFile;
- use App\Models\SourcePaper;
- use App\Models\PaperPart;
- class PreQuestionCandidate extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'import_id',
- 'source_file_id',
- 'source_paper_id',
- 'part_id',
- 'sequence',
- 'index',
- 'order_index',
- 'question_number',
- 'order',
- 'raw_markdown',
- 'raw_hash',
- 'raw_text',
- 'clean_markdown',
- 'clean_hash',
- 'structured_json',
- 'stem',
- 'options',
- 'images',
- 'tables',
- 'is_question_candidate',
- 'ai_confidence',
- 'confidence',
- 'formula_detected',
- 'is_valid_question',
- 'status',
- 'meta',
- ];
- protected $casts = [
- 'is_question_candidate' => 'boolean',
- 'ai_confidence' => 'float',
- 'confidence' => 'decimal:2',
- 'sequence' => 'integer',
- 'order' => 'integer',
- 'options' => 'array',
- 'images' => 'array',
- 'tables' => 'array',
- 'formula_detected' => 'boolean',
- 'is_valid_question' => 'boolean',
- 'meta' => 'array',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- public const STATUS_PENDING = 'pending';
- public const STATUS_REVIEWED = 'reviewed';
- public const STATUS_ACCEPTED = 'accepted';
- public const STATUS_REJECTED = 'rejected';
- public const STATUS_SUPERSEDED = 'superseded';
- public function import(): BelongsTo
- {
- return $this->belongsTo(MarkdownImport::class, 'import_id');
- }
- public function sourceFile(): BelongsTo
- {
- return $this->belongsTo(SourceFile::class, 'source_file_id');
- }
- public function sourcePaper(): BelongsTo
- {
- return $this->belongsTo(SourcePaper::class, 'source_paper_id');
- }
- public function part(): BelongsTo
- {
- return $this->belongsTo(PaperPart::class, 'part_id');
- }
- public function getConfidenceBadgeAttribute(): string
- {
- if ($this->ai_confidence === null) {
- return 'gray';
- }
- if ($this->ai_confidence >= 0.8) {
- return 'success';
- } elseif ($this->ai_confidence >= 0.5) {
- return 'warning';
- }
- return 'danger';
- }
- public function getStatusBadgeAttribute(): string
- {
- $badges = [
- self::STATUS_PENDING => 'gray',
- self::STATUS_REVIEWED => 'info',
- self::STATUS_ACCEPTED => 'success',
- self::STATUS_REJECTED => 'danger',
- self::STATUS_SUPERSEDED => 'gray',
- ];
- return $badges[$this->status] ?? 'gray';
- }
- public function getFirstImageAttribute(): ?string
- {
- if (empty($this->images)) {
- return null;
- }
- $images = is_string($this->images) ? json_decode($this->images, true) : $this->images;
- return $images[0] ?? null;
- }
- public function getStemPreviewAttribute(): string
- {
- if (!$this->stem) {
- return 'No stem extracted';
- }
- return \Str::limit($this->stem, 100);
- }
- }
|