feat(mapper): Set publication date based on resource type - #595
feat(mapper): Set publication date based on resource type#595sakshamarora1 wants to merge 1 commit into
Conversation
7785752 to
3d8bf5c
Compare
| publication_date = normalize(publication_date_str) | ||
|
|
||
| return publication_date | ||
| store_priority_date(self, "article", publication_date) |
There was a problem hiding this comment.
I would prefer if this is done a bit cleaner, because this additional nested key is making things more complex.
let's map 260__c as publication_date (as is) and 269__c as preprint_date, then please check my comment in the mapper as next
There was a problem hiding this comment.
Yeah makes sense, I have updated the PR accordingly
3d8bf5c to
1bee54b
Compare
| priority_dates = dojson_entry.pop("_publication_date_candidates", {}) | ||
| article_date = priority_dates.get("article") | ||
| preprint_date = priority_dates.get("preprint") | ||
| resource_type = (dojson_entry.get("resource_type") or {}).get("id") |
There was a problem hiding this comment.
instead of nested _publication_date_candidates, could you use publication_date and preprint date here? it will be very similar in logic but you will not need the check in line 113
so basically
pub_date = dojson_entry["publication_date"]
if (restype != "article" and is_more_accurate(dojson_entry["preprint_date"])) or restype=="preprint":
pub_date = dojson_entry["preprint_date"]
1bee54b to
83a3b9c
Compare
| if resource_type == "publication-article": | ||
| if preprint_date: | ||
| dojson_entry.setdefault("dates", []).append( | ||
| { | ||
| "date": preprint_date, | ||
| "type": {"id": "submitted"}, | ||
| "description": "preprint", | ||
| } | ||
| ) |
There was a problem hiding this comment.
is it possible there’s only 269 (no 260)? In this case if there is no 260 preprint is moved to secondary dates and publication_date falls back to status week / file creation
| def _date_precision(date_str): | ||
| """Return how granular a normalized date string is (year=1, month=2, day=3).""" | ||
| if not date_str: | ||
| return 0 | ||
| return len(date_str.split("-")) |
There was a problem hiding this comment.
we're not always return in the format with "-" so maybe we should change that? or we can split with "-" and "/". See the date normalize method
example:
- for non-articles, if 260 is "2021" and 269 is "2021/05":
- precision(preprint="2021/05") = 1
- precision(pub="2021") = 1
- _is_more_accurate is False → 260 wins, even though 269 is month-level and should win.
fixes: #581