This commit is contained in:
wyn
2026-05-21 14:37:04 +08:00
parent 6f76c483ec
commit 3663dd4ea6
2 changed files with 38 additions and 10 deletions

View File

@@ -193,7 +193,7 @@ class ReferenceCheckService
'created_at' => $now,
'updated_at' => $now,
]);
// continue;
$this->pushJob(intval($checkId), $delay);
$checkIds[] = $checkId;
$queued++;
@@ -697,20 +697,32 @@ class ReferenceCheckService
}
$hasPriorCiteInParagraph = ($prevTagEnd > $paragraphStart);
// 同段后续引用:从上一 <blue> 后开始;段内首个引用:从段落开头到本标签前(非仅最后一句)
// 同段后续引用:从上一 <blue> 后开始;段内首个引用:从段落开头到本标签前
if ($hasPriorCiteInParagraph) {
$localStart = $prevTagEnd;
} else {
$localStart = $this->capContextStartBeforeTag($content, $tagStart, $paragraphStart);
$sentenceStart = $this->findSentenceStart($content, $tagStart);
$localStart = $this->capContextStartBeforeTag(
$content,
$tagStart,
max($paragraphStart, $sentenceStart)
);
}
// 默认:引用标签前的论述(如 Yin et al. [13] → 含 “higher than … Yin et al.”)
// 默认:引用标签前的论述
$localEnd = $tagStart;
$originalText = $this->buildCitationContextText($content, $localStart, $localEnd);
// 标签前几乎无正文(如句末 … ICU nurses [14]→ 改用标签后至下一引用或句末
// 同句多引(如 …[23] and external environment [24]:上一标签后仅几个词,回退到本句开头
if ($hasPriorCiteInParagraph && mb_strlen($originalText) < 50) {
$sentenceStart = $this->findSentenceStart($content, $tagStart);
$localStart = max($paragraphStart, $sentenceStart);
$originalText = $this->buildCitationContextText($content, $localStart, $localEnd);
}
// 仅段内首个引用且标签前极短时才用标签后文(避免 [24] 误截到 [25] 所在句)
if (!$this->isMeaningfulCitationContext($originalText)
|| $this->shouldUseTrailingCitationContext($content, $localStart, $tagStart, $tagEnd)
|| (!$hasPriorCiteInParagraph && $this->shouldUseTrailingCitationContext($content, $localStart, $tagStart, $tagEnd))
) {
$trailEnd = ($nextTagStart < $sentenceEnd) ? $nextTagStart : $sentenceEnd;
$trailText = $this->buildCitationContextText($content, $tagEnd, $trailEnd);
@@ -811,6 +823,7 @@ class ReferenceCheckService
$text = trim(strip_tags($text));
$text = preg_replace('/\s+/u', ' ', $text);
$text = ltrim($text, "\xEF\xBB\xBF");
$text = preg_replace('/^[\s.,。;、:!?]+/u', '', $text);
return $text;
}

View File

@@ -709,13 +709,27 @@ PROMPT;
}
/**
* 将模型输出的 confidence 吸附到固定档位,并与 is_match 规则对齐
* 与 buildReferenceCheckSystemPrompt3 一致的 confidence 档位
*/
private function getReferenceCheckConfidenceBands($isMatch)
{
return $isMatch
? [0.65, 0.78, 0.85, 0.92, 0.98]
: [0.15, 0.25, 0.35, 0.45];
}
/**
* 将模型输出的 confidence 吸附到合法档位(如 0.95 → 0.920.75 → 0.78
*/
private function snapReferenceCheckConfidence($confidence, $isMatch)
{
$matchBands = [0.75, 0.85, 0.95];
$mismatchBands = [0.15, 0.25, 0.35];
$bands = $isMatch ? $matchBands : $mismatchBands;
$bands = $this->getReferenceCheckConfidenceBands($isMatch);
foreach ($bands as $band) {
if (abs($confidence - $band) < 0.001) {
return $band;
}
}
$nearest = $bands[0];
$minDiff = abs($confidence - $nearest);
@@ -726,6 +740,7 @@ PROMPT;
$nearest = $band;
}
}
return $nearest;
}