参考文献校对升级

This commit is contained in:
wyn
2026-06-29 10:23:27 +08:00
parent edb3c1b27b
commit 6fdc4efb6f
11 changed files with 2680 additions and 380 deletions

View File

@@ -96,6 +96,68 @@ class PubmedService
return $info;
}
/**
* 按书目信息检索 PubMed标题 + 第一作者 + 年份)
*/
public function searchByBibliographic($title, $author = '', $year = ''): ?array
{
$title = trim((string)$title);
if ($title === '') {
return null;
}
$terms = ['(' . $this->quoteTerm($title) . '[Title])'];
$author = trim((string)$author);
if ($author !== '') {
$parts = preg_split('/[,;]/', $author);
$first = trim((string)($parts[0] ?? ''));
if ($first !== '') {
$terms[] = '(' . $this->quoteTerm($first) . '[Author])';
}
}
$year = trim((string)$year);
if ($year !== '' && preg_match('/^(19|20)\d{2}$/', $year)) {
$terms[] = '(' . $year . '[pdat])';
}
$pmid = $this->esearch(implode(' AND ', $terms));
if (!$pmid) {
return null;
}
$info = $this->fetchByPmid($pmid);
if (!$info) {
return null;
}
$info['pmid'] = $pmid;
$info['doi'] = $this->extractDoiFromPmidRecord($pmid);
return $info;
}
private function quoteTerm($text)
{
return str_replace('"', '', trim((string)$text));
}
private function extractDoiFromPmidRecord($pmid)
{
$url = $this->base . 'efetch.fcgi?' . http_build_query([
'db' => 'pubmed',
'id' => $pmid,
'retmode' => 'xml',
'tool' => $this->tool,
'email' => $this->email,
]);
$xml = $this->httpGet($url);
if ($xml === '') {
return '';
}
if (preg_match('/<ArticleId IdType="doi">([^<]+)<\/ArticleId>/i', $xml, $m)) {
return trim($m[1]);
}
return '';
}
// ----------------- Internals -----------------
private function esearch(string $term): ?string