From 3663dd4ea69be8f4010bdcc2838d563f6d23a092 Mon Sep 17 00:00:00 2001 From: wyn <1074145239@qq.com> Date: Thu, 21 May 2026 14:37:04 +0800 Subject: [PATCH] Changes --- application/common/ReferenceCheckService.php | 25 +++++++++++++++----- application/common/service/LLMService.php | 23 ++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/application/common/ReferenceCheckService.php b/application/common/ReferenceCheckService.php index be13d089..65ee9abc 100644 --- a/application/common/ReferenceCheckService.php +++ b/application/common/ReferenceCheckService.php @@ -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); - // 同段后续引用:从上一 后开始;段内首个引用:从段落开头到本标签前(非仅最后一句) + // 同段后续引用:从上一 后开始;段内首个引用:从段落开头到本标签前 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; } diff --git a/application/common/service/LLMService.php b/application/common/service/LLMService.php index ce66056c..4ffe0cda 100644 --- a/application/common/service/LLMService.php +++ b/application/common/service/LLMService.php @@ -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.92,0.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; }