Skip to content

Commit 98f5b41

Browse files
ghuronclaude
andcommitted
Unify source key, fix ADS auth, add parse() bool return convention
- Rename db_ref/source_item → source in all connector JSON configs - Registry now gates on source key instead of properties - Fix SourceItem.extract() to pass Request object directly (preserving headers like Authorization) - Change parse() signature to bool: True=return self, False=return None from extract() - Add tracing log in extract() for non-200 responses - Add extract() docstring describing None/empty-patch/non-empty-patch convention - Add ADS unit tests covering real lookups and not-found cases - Add CLAUDE.md noting unittest framework Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f02af74 commit 98f5b41

20 files changed

Lines changed: 160 additions & 31 deletions

CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Project Notes
2+
3+
## Testing
4+
5+
Unit tests use Python's built-in `unittest` framework. Run with:
6+
7+
```
8+
python -m unittest discover tests/
9+
```

src/wdpy/connectors/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .astro import *
22
from .exoplanet import *
3-
from .simbad import *
3+
from .simbad import *
4+
from .ads import *

src/wdpy/connectors/ads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"db_ref": "Q752099",
2+
"source": "Q752099",
33
"properties": {
44
"P819": "https://api.adsabs.harvard.edu/v1/search/query?q=bibcode:\"{}\"",
55
"P356": "https://api.adsabs.harvard.edu/v1/search/query?q=doi:\"{}\"",

src/wdpy/connectors/ads.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ def make_request(cls, ident: Statement) -> Optional[Request]:
1515
headers={'Authorization': 'Bearer ogOoi0uDxIebyeseB3tAbf5mBTJxXQQWQqE5TW40'}
1616
)
1717

18-
def parse(self, text: str) -> None:
18+
def parse(self, text: str) -> bool:
1919
docs = json.loads(text).get('response', {}).get('docs', [])
2020
if len(docs) != 1:
2121
if self.patch and self.patch[0].mainsnak.property == 'P819':
2222
logging.warning('Got %d results for %s', len(docs), self.patch[0].mainsnak.value)
23-
self.patch = []
24-
return
23+
self.patch = []
24+
return True
25+
return False
2526
d = docs[0]
2627
if 'page' in d:
2728
p = d['page'][0] if isinstance(d['page'], list) else d['page']
@@ -41,6 +42,7 @@ def parse(self, text: str) -> None:
4142
elif ident.startswith('10.') and 'ARXIV' not in ident.upper():
4243
self.add_claim('P356', ident)
4344
self.add_claim('P31', 'Q13442814')
45+
return True
4446

4547

4648
def _get_orcid(d: dict, idx: int) -> Optional[str]:

src/wdpy/connectors/arxiv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"db_ref": "Q118398",
2+
"source": "Q118398",
33
"properties": {
44
"P818": "https://export.arxiv.org/api/query?id_list={}",
55
"P356": "https://export.arxiv.org/api/query?search_query={}"

src/wdpy/connectors/arxiv.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from wdpy import SourceItem
33

44
class ArxivItem(SourceItem):
5-
def parse(self, text: str) -> None:
5+
def parse(self, text: str) -> bool:
66
ns = self._config['namespaces']
77
if (entry := ElementTree.fromstring(text).find('w3:entry', ns)) is None:
88
self.patch = []
9-
return
9+
return True
1010
id_text = getattr(entry.find('w3:id', ns), 'text', '') or ''
1111
arxiv_id = id_text.split('/')[-1].split('v')[0]
1212
self.add_claim('P31', 'Q13442814')
@@ -20,6 +20,7 @@ def parse(self, text: str) -> None:
2020
self.add_claim('P2093', name).set_qualifier('P1545', str(i := i + 1))
2121
if len(doi := entry.findall('arxiv:doi', ns)) == 1 and doi[0].text:
2222
self.add_claim('P356', doi[0].text.upper())
23+
return True
2324

2425
# r = ArxivItem.extract(Statement(Snak('P818', ('1309.0951',))))
2526
# r = ArxivItem.extract(Statement(Snak('P356', ('10.4171/161',))))

src/wdpy/connectors/astro.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any, Dict, List, Optional, Union
2-
from wdpy.core import build_request, parse_csv
3-
from wdpy.source_item import SourceItem
2+
from wdpy import build_request, parse_csv, SourceItem, Statement
43

54
class AstroItem(SourceItem):
65
@classmethod
@@ -36,4 +35,8 @@ def get_canonical_name(name: str) -> Optional[str]:
3635
)
3736
if (rows := SimbadItem.exec(query)) and (main_id := list(rows.keys())[0]):
3837
return main_id
39-
return None
38+
return None
39+
40+
@classmethod
41+
def extract(cls, ident: Statement) -> Optional[SourceItem]:
42+
return None # Temporary until ADQL extractor is implemented

src/wdpy/connectors/crossref.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"db_ref": "Q5188229",
2+
"source": "Q5188229",
33
"extract": [404],
44
"properties": {
55
"P356": "https://api.crossref.org/works/{}"

src/wdpy/connectors/crossref.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44

55
class Crossref(SourceItem):
6-
def parse(self, text: str) -> None:
6+
def parse(self, text: str) -> bool:
77
self.obtain(json.loads(text), self._config.get('fields', {}), self._config.get('translate', {}))
8+
return True

src/wdpy/connectors/europepmc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"db_ref": "Q5412157",
2+
"source": "Q5412157",
33
"properties": {
44
"P698": "https://www.ebi.ac.uk/europepmc/webservices/rest/search?resulttype=core&format=json&query=EXT_ID:{}",
55
"P356": "https://www.ebi.ac.uk/europepmc/webservices/rest/search?resulttype=core&format=json&query=DOI:{}"

0 commit comments

Comments
 (0)