终审邀请界面,多加一些信息,,,,解决参考文献有时候的中文问题
This commit is contained in:
@@ -273,26 +273,83 @@ class CrossrefService
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取标题
|
||||
* 提取标题(英文优先)
|
||||
*
|
||||
* CrossRef 的 title / original-title 可能包含多个语言版本(中文期刊/双语文章常见)。
|
||||
* 这里优先返回不含中日韩字符的版本,全部为中文时才退回第一个。
|
||||
*/
|
||||
public function getTitle($aDoiInfo = [])
|
||||
{
|
||||
return $aDoiInfo['title'][0] ?? '';
|
||||
$candidates = [];
|
||||
if (!empty($aDoiInfo['title']) && is_array($aDoiInfo['title'])) {
|
||||
$candidates = array_merge($candidates, $aDoiInfo['title']);
|
||||
}
|
||||
if (!empty($aDoiInfo['original-title']) && is_array($aDoiInfo['original-title'])) {
|
||||
$candidates = array_merge($candidates, $aDoiInfo['original-title']);
|
||||
}
|
||||
return $this->pickPreferredLatin($candidates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取期刊/出版社相关信息
|
||||
* 提取期刊/出版社相关信息(期刊名英文优先)
|
||||
*/
|
||||
public function getPublisher($aDoiInfo = [])
|
||||
{
|
||||
$containerTitles = (!empty($aDoiInfo['container-title']) && is_array($aDoiInfo['container-title']))
|
||||
? $aDoiInfo['container-title'] : [];
|
||||
$shortTitles = (!empty($aDoiInfo['short-container-title']) && is_array($aDoiInfo['short-container-title']))
|
||||
? $aDoiInfo['short-container-title'] : [];
|
||||
|
||||
return [
|
||||
'title' => isset($aDoiInfo['container-title'][0]) ? $aDoiInfo['container-title'][0] : '',
|
||||
'short_title' => isset($aDoiInfo['short-container-title'][0]) ? $aDoiInfo['short-container-title'][0] : '',
|
||||
'title' => $this->pickPreferredLatin($containerTitles),
|
||||
'short_title' => $this->pickPreferredLatin($shortTitles),
|
||||
'ISSN' => $aDoiInfo['ISSN'] ?? [],
|
||||
'publisher' => $aDoiInfo['publisher'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否包含中日韩(CJK)字符
|
||||
*/
|
||||
public function hasCjk($str)
|
||||
{
|
||||
$str = (string)$str;
|
||||
if ($str === '') {
|
||||
return false;
|
||||
}
|
||||
return preg_match('/[\x{4e00}-\x{9fff}\x{3040}-\x{30ff}\x{ac00}-\x{d7af}\x{3400}-\x{4dbf}]/u', $str) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从多个候选字符串中优先挑选「不含 CJK 字符」的一个;
|
||||
* 全部为空则返回空串,全部含 CJK 则返回第一个非空值。
|
||||
*
|
||||
* @param array $candidates
|
||||
* @return string
|
||||
*/
|
||||
private function pickPreferredLatin($candidates)
|
||||
{
|
||||
if (!is_array($candidates) || empty($candidates)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$firstNonEmpty = '';
|
||||
foreach ($candidates as $item) {
|
||||
$s = trim((string)$item);
|
||||
if ($s === '') {
|
||||
continue;
|
||||
}
|
||||
if ($firstNonEmpty === '') {
|
||||
$firstNonEmpty = $s;
|
||||
}
|
||||
if (!$this->hasCjk($s)) {
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
|
||||
return $firstNonEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用 PubMed/NLM 反查期刊规范缩写(CrossRef 无缩写时的兜底)。
|
||||
* 任何异常都吞掉并返回空串,保证不影响主流程。
|
||||
|
||||
Reference in New Issue
Block a user