参考文献bug

This commit is contained in:
wangjinlei
2026-06-10 15:31:10 +08:00
parent 0a2b053718
commit 249a04c109
5 changed files with 109 additions and 5 deletions

View File

@@ -300,6 +300,73 @@ class CrossrefService
return $authors;
}
/**
* 引用格式作者串:姓全写 + 名首字母,超过 $maxAuthors 个取前 N 个 + et al
* 例Smith JA, Jones B, Lee C, et al
*
* @param array $aDoiInfo Crossref message
* @param int $maxAuthors 最多展示作者数,超过则截断加 et al
* @return string
*/
public function getAuthorsCitation($aDoiInfo = [], $maxAuthors = 3)
{
$list = [];
if (!empty($aDoiInfo['author'])) {
foreach ($aDoiInfo['author'] as $author) {
$family = trim((string)($author['family'] ?? ''));
$given = trim((string)($author['given'] ?? ''));
if ($family === '' && $given === '') {
// 机构作者等无姓名结构的情况
$orgName = trim((string)($author['name'] ?? ''));
if ($orgName !== '') {
$list[] = $orgName;
}
continue;
}
$initials = $this->givenToInitials($given);
$name = $initials !== '' ? trim($family . ' ' . $initials) : $family;
if ($name !== '') {
$list[] = $name;
}
}
}
if (empty($list)) {
return '';
}
$maxAuthors = max(1, (int)$maxAuthors);
if (count($list) > $maxAuthors) {
$list = array_slice($list, 0, $maxAuthors);
return implode(', ', $list) . ', et al';
}
return implode(', ', $list);
}
/**
* 名转首字母:取每个组成部分(空格/连字符/点分隔)首字母大写并拼接。
* 例:"John A." -> "JA""Mary-Jane" -> "MJ"
*/
private function givenToInitials($given)
{
$given = trim((string)$given);
if ($given === '') {
return '';
}
$parts = preg_split('/[\s\-\.]+/u', $given, -1, PREG_SPLIT_NO_EMPTY);
$initials = '';
foreach ($parts as $p) {
$first = mb_substr($p, 0, 1);
if ($first !== '') {
$initials .= mb_strtoupper($first);
}
}
return $initials;
}
/**
* 提取发表年份
*/

View File

@@ -2,6 +2,7 @@
namespace app\common;
use think\Db;
use think\Env;
use app\common\CrossrefService;
class ProductionArticleRefer
{
@@ -78,6 +79,41 @@ class ProductionArticleRefer
return json_encode(['status' => 4,'msg' => 'Reference DOI is empty'.json_encode($aParam)]);
}
//开始用crossref接口的方式处理数据
$doiNorm = preg_replace('#^https?://(dx\.)?doi\.org/#i', '', $aRefer['refer_doi']);
$doiNorm = trim($doiNorm, " \t\n\r\0\x0B/");
$svc = new CrossrefService([
'mailto' => trim((string)Env::get('crossref_mailto', '')),
]);
$summary = $svc->fetchWorkSummary($doiNorm);
if ($summary !== null && !empty($summary['doi'])) {
$update_a = [];
$title = trim((string)($summary['title'] ?? ''));
$jouraRaw = trim((string)($summary['joura'] ?? ''));
// 姓全写 + 名首字母,超过 3 个作者取前 3 个 + et al
$authorCitation = $svc->getAuthorsCitation($summary['raw'] ?? [], 3);
$dateno = trim((string)($summary['dateno'] ?? ''));
$doilink = trim((string)($summary['doilink'] ?? ''));
$update_a['title'] = $title;
$update_a['author'] = $authorCitation !== '' ? $authorCitation . '.' : '';
$update_a['joura'] = $jouraRaw;
$update_a['dateno'] = $dateno;
$update_a['refer_type'] = "journal";
$update_a['is_ja'] = 1;
$update_a['doilink'] = $doilink;
$update_a['cs'] = 1;
$update_a['update_time'] = time();
$update_a['is_deal'] = 1;
Db::name('production_article_refer')->where(['p_refer_id' => $iPReferId])->limit(1)->update($update_a);
return json_encode(['status' => 1,'msg' => 'Update successful']);
}
//结束---用crossref接口的方式处理数据
//数据处理
$doi = str_replace('/', '%2F', $aRefer['refer_doi']);
$url = "https://citation.doi.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";

View File

@@ -27,7 +27,7 @@ use think\Env;
class LocalModelService
{
/** 上下文长度阈值(字符数):<= 用小模型,> 用大模型 */
const CONTEXT_THRESHOLD = 3000;
const CONTEXT_THRESHOLD = 1000;
/** 请求超时(秒) */
const TIMEOUT = 120;