参考文献校对升级
This commit is contained in:
@@ -1178,6 +1178,107 @@ class Base extends Controller
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析方括号引用内层(如 1,2 / 3-5),展开为文献序号列表。
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
protected function expandCitationBracketNumbers(string $referencePart): array
|
||||
{
|
||||
$referencePart = trim($referencePart);
|
||||
if ($referencePart === '') {
|
||||
return [];
|
||||
}
|
||||
$referencePart = str_replace(
|
||||
[',', '–', '—', '−', '‐', '‑'],
|
||||
[',', '-', '-', '-', '-', '-'],
|
||||
$referencePart
|
||||
);
|
||||
$out = [];
|
||||
$segments = preg_split('/\s*,\s*/', $referencePart);
|
||||
foreach ($segments as $seg) {
|
||||
$seg = trim((string)$seg);
|
||||
if ($seg === '') {
|
||||
continue;
|
||||
}
|
||||
$seg = str_replace(['–', '—', '−', '‐', '‑'], '-', $seg);
|
||||
if (preg_match('/^(\d+)\s*-\s*(\d+)$/', $seg, $m)) {
|
||||
$a = intval($m[1]);
|
||||
$b = intval($m[2]);
|
||||
if ($a > $b) {
|
||||
$t = $a;
|
||||
$a = $b;
|
||||
$b = $t;
|
||||
}
|
||||
for ($i = $a; $i <= $b; $i++) {
|
||||
$out[] = $i;
|
||||
}
|
||||
} else {
|
||||
$n = intval($seg);
|
||||
if ($n > 0) {
|
||||
$out[] = $n;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从正文片段提取被引用的文献序号(reference_no = index+1)。
|
||||
* 兼容 <mycite data-id="p_refer_id"> 与 <blue>[n]</blue> / [n] 两种形态。
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
protected function extractCitationRefNosFromMainContent(string $text, int $pArticleId = 0): array
|
||||
{
|
||||
if ($text === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$nos = [];
|
||||
|
||||
$pReferIds = $this->extractMyciteIds($text);
|
||||
if (!empty($pReferIds) && $pArticleId > 0) {
|
||||
$refers = Db::name('production_article_refer')
|
||||
->where('p_article_id', $pArticleId)
|
||||
->whereIn('p_refer_id', $pReferIds)
|
||||
->where('state', 0)
|
||||
->field('p_refer_id,index')
|
||||
->select();
|
||||
$idToNo = [];
|
||||
foreach ($refers as $row) {
|
||||
$idToNo[intval($row['p_refer_id'])] = intval($row['index']) + 1;
|
||||
}
|
||||
foreach ($pReferIds as $pid) {
|
||||
if (isset($idToNo[$pid])) {
|
||||
$nos[] = $idToNo[$pid];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match_all('/(?:<\s*blue[^>]*>)?\[([^\]]+)\](?:<\/\s*blue\s*>)?/iu', $text, $m)) {
|
||||
foreach ($m[1] as $inner) {
|
||||
$innerNorm = str_replace(
|
||||
[',', '–', '—', '−', '‐', '‑'],
|
||||
[',', '-', '-', '-', '-', '-'],
|
||||
trim((string)$inner)
|
||||
);
|
||||
if (!preg_match('/^[\d\s,\-]+$/u', $innerNorm)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($this->expandCitationBracketNumbers($innerNorm) as $n) {
|
||||
if ($n > 0) {
|
||||
$nos[] = $n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nos = array_values(array_unique($nos));
|
||||
sort($nos, SORT_NUMERIC);
|
||||
return $nos;
|
||||
}
|
||||
|
||||
/**
|
||||
* table_data:二维数组 JSON [[{text,colspan,rowspan},...],...];支持双重 JSON 字符串编码。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user