参考文献校对升级
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user