Skip to content

Commit d7f9669

Browse files
ghuronclaude
andcommitted
Detect ADS bibcode redirects in parse()
When querying by P819 and ADS returns a different bibcode (e.g. arXiv preprint → published), set prior_ident/new_ident instead of silently adding the new bibcode to patch. Also switch P819 query to use identifier: field for broader matching, and skip bibcode from obtain() when querying by P819 to avoid redundant claims. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ff055cf commit d7f9669

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/wdpy/connectors/ads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"source": "Q752099",
33
"properties": {
4-
"P819": "https://api.adsabs.harvard.edu/v1/search/query?q=bibcode:\"{}\"",
4+
"P819": "https://api.adsabs.harvard.edu/v1/search/query?q=identifier:\"{}\"",
55
"P356": "https://api.adsabs.harvard.edu/v1/search/query?q=doi:\"{}\"",
66
"P818": "https://api.adsabs.harvard.edu/v1/search/query?q=doi:\"10.48550%2FarXiv.{}\""
77
},

src/wdpy/connectors/ads.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from typing import Optional
44
from urllib.request import Request
5-
from wdpy import SourceItem, Statement, build_request
5+
from wdpy import Snak, SourceItem, Statement, build_request
66

77

88
class ADS(SourceItem):
@@ -33,7 +33,17 @@ def parse(self, text: str, ident: Statement) -> None:
3333
d['page'] = f'{p} - {int(p) + d["page_count"] - 1}'
3434
except (ValueError, KeyError):
3535
pass
36-
self.obtain(d, self._config.get('fields', {}), self._config.get('translate', {}))
36+
fields = self._config.get('fields', {})
37+
translate = self._config.get('translate', {})
38+
39+
if ident.mainsnak.property == 'P819':
40+
bibcode = d.get('bibcode')
41+
if bibcode and bibcode != ident.mainsnak.value[0]:
42+
self.prior_ident = ident
43+
self.new_ident = Statement(Snak('P819', (bibcode,)))
44+
fields = {k: v for k, v in fields.items() if k != 'bibcode'}
45+
46+
self.obtain(d, fields, translate)
3747
for i, name in enumerate(d.get('author', []), 1):
3848
self.add_author(name, _get_orcid(d, i - 1))
3949
for identifier in d.get('identifier', []):

tests/integration/test_ads.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ def test_nonexistent_arxiv_returns_empty(self):
3333
self.assertIsNone(result.prior_ident)
3434
self.assertIsNone(result.patch)
3535
self.assertIsNone(result.new_ident)
36+
37+
def test_bibcode_redirect(self):
38+
ident = Statement(Snak('P819', ('2023arXiv230313424H',)))
39+
result = ADS.extract(ident)
40+
self.assertIs(result.prior_ident, ident)
41+
self.assertEqual(result.new_ident.mainsnak.property, 'P819')
42+
self.assertEqual(result.new_ident.mainsnak.value, ('2023A&A...673A.114H',))
43+
self.assertTrue(result.patch)

0 commit comments

Comments
 (0)