Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken title search ut #411

Merged
merged 15 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions paperqa/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def repopulate_doc_id_from_doi(self) -> None:
if self.doi:
self.doc_id = encode_id(self.doi)

def __add__(self, other: DocDetails | int) -> DocDetails:
def __add__(self, other: DocDetails | int) -> DocDetails: # noqa: PLR0912
"""Merge two DocDetails objects together."""
# control for usage w. Python's sum() function
if isinstance(other, int):
Expand Down Expand Up @@ -650,13 +650,20 @@ def __add__(self, other: DocDetails | int) -> DocDetails:
# if we have multiple keys, we wipe them and allow regeneration
merged_data[field] = None # type: ignore[assignment]

elif (
field in {"citation_count", "year", "publication_date"}
and self_value is not None
and other_value is not None
):
elif field in {"citation_count", "year", "publication_date"}:
# get the latest data
merged_data[field] = max(self_value, other_value)
# this conditional is written in a way to handle if multiple doc objects
# are provided, we'll use the highest value
# if there's only one valid value, we'll use that regardless even if
# that value is 0
if self_value is None or other_value is None:
nadolskit marked this conversation as resolved.
Show resolved Hide resolved
merged_data[field] = (
self_value
if self_value is not None # Dance around 0
else other_value
)
else:
merged_data[field] = max(self_value, other_value)

else:
# Prefer non-null values, default preference for 'other' object.
Expand Down
132 changes: 66 additions & 66 deletions tests/cassettes/test_title_search[paper_attributes0].yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@
interactions:
- request:
body: null
headers: {}
method: GET
uri: https://api.unpaywall.org/v2/search?query=Effect%20of%20native%20oxide%20layers%20on%20copper%20thin-film%20tensile%20properties:%20A%20reactive%20molecular%20dynamics%20study&[email protected]
response:
body:
string:
'{"elapsed_seconds":0.293,"results":[{"response":{"best_oa_location":null,"data_standard":2,"doi":"10.1063/1.4938384","doi_url":"https://doi.org/10.1063/1.4938384","first_oa_location":null,"genre":"journal-article","has_repository_copy":false,"is_oa":false,"is_paratext":false,"journal_is_in_doaj":false,"journal_is_oa":false,"journal_issn_l":"0021-8979","journal_issns":"0021-8979,1089-7550","journal_name":"Journal
of Applied Physics","oa_locations":[],"oa_locations_embargoed":[],"oa_status":"closed","published_date":"2015-12-21","publisher":"AIP
Publishing","title":"Effect of native oxide layers on copper thin-film tensile
properties: A reactive molecular dynamics study","updated":"2023-07-31T05:28:57.007821","year":2015,"z_authors":[{"affiliation":[{"name":"University
of Rochester 1 Materials Science Program, , Rochester, New York 14627, USA"}],"family":"Skarlinski","given":"Michael
D.","sequence":"first"},{"affiliation":[{"name":"University of Rochester 1
Materials Science Program, , Rochester, New York 14627, USA"},{"name":"University
of Rochester 2 Department of Mechanical Engineering, , Rochester, New York
14627, USA"}],"family":"Quesnel","given":"David J.","sequence":"additional"}]},"score":0.009231734,"snippet":"<b>Effect</b>
of <b>native</b> <b>oxide</b> <b>layers</b> on <b>copper</b> <b>thin</b>-<b>film</b>
<b>tensile</b> <b>properties</b>: A <b>reactive</b> <b>molecular</b> <b>dynamics</b>
<b>study</b>"}]}
'
headers:
Access-Control-Allow-Headers:
- origin, content-type, accept, x-requested-with
Access-Control-Allow-Methods:
- POST, GET, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Origin:
- "*"
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- "706"
Content-Type:
- application/json
Date:
- Mon, 16 Sep 2024 14:27:14 GMT
Nel:
- '{"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]}'
Report-To:
- '{"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1726496834&sid=c46efe9b-d3d2-4a0c-8c76-bfafa16c5add&s=8Yb6yS3oBlsm7GItef5gXCaZZ5ZTUCpWzHxYNQaGnzk%3D"}]}'
Reporting-Endpoints:
- heroku-nel=https://nel.heroku.com/reports?ts=1726496834&sid=c46efe9b-d3d2-4a0c-8c76-bfafa16c5add&s=8Yb6yS3oBlsm7GItef5gXCaZZ5ZTUCpWzHxYNQaGnzk%3D
Server:
- gunicorn
Vary:
- Accept-Encoding
Via:
- 1.1 vegur
status:
code: 200
message: OK
- request:
body: null
headers: {}
Expand All @@ -21,7 +75,7 @@ interactions:
tensile properties: A reactive molecular dynamics study},\n volume = {118},\n
year = {2015}\n}\n"}, "authors": [{"authorId": "9821934", "name": "Michael
Skarlinski"}, {"authorId": "37723150", "name": "D. Quesnel"}], "matchScore":
283.23224}]}
283.16406}]}
'
headers:
Expand All @@ -34,27 +88,27 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 04 Sep 2024 22:54:18 GMT
- Mon, 16 Sep 2024 14:27:15 GMT
Via:
- 1.1 e8075a4d83e15c8c6543597e1a8de938.cloudfront.net (CloudFront)
- 1.1 ad82d8a3c91257adecf18541576c7e72.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- vB0latP66Hte1od43bgj7T8qLdb6UzgZtdqHNa2gxDLLvDKO6z_zQg==
- tzP7nmuXE6ItJQWbUpPZ2NM0OcRWRQnHsH4xNcUm1ww6zfKlEeF7Qg==
X-Amz-Cf-Pop:
- SFO53-C1
X-Cache:
- Miss from cloudfront
x-amz-apigw-id:
- dmi8GFhlvHcErEg=
- eM76cF3EPHcEbeQ=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- "1109"
x-amzn-Remapped-Date:
- Wed, 04 Sep 2024 22:54:18 GMT
- Mon, 16 Sep 2024 14:27:15 GMT
x-amzn-Remapped-Server:
- gunicorn
x-amzn-RequestId:
- 88340ebb-a44f-4660-aa0f-f42e231133a9
- 63c346cc-8764-4aea-a3d2-f29ca40b0d70
status:
code: 200
message: OK
Expand All @@ -66,7 +120,7 @@ interactions:
response:
body:
string:
'{"status":"ok","message-type":"work-list","message-version":"1.0.0","message":{"facets":{},"total-results":11790075,"items":[{"indexed":{"date-parts":[[2023,9,29]],"date-time":"2023-09-29T22:47:50Z","timestamp":1696027670718},"reference-count":57,"publisher":"AIP
'{"status":"ok","message-type":"work-list","message-version":"1.0.0","message":{"facets":{},"total-results":11817992,"items":[{"indexed":{"date-parts":[[2023,9,29]],"date-time":"2023-09-29T22:47:50Z","timestamp":1696027670718},"reference-count":57,"publisher":"AIP
Publishing","issue":"23","funder":[{"DOI":"10.13039\/100000006","name":"Office
of Naval Research","doi-asserted-by":"publisher","award":["N00014-12-1-0542"],"id":[{"id":"10.13039\/100000006","id-type":"DOI","asserted-by":"publisher"}]}],"content-domain":{"domain":["pubs.aip.org"],"crossmark-restriction":true},"published-print":{"date-parts":[[2015,12,21]]},"abstract":"<jats:p>Metal-oxide
layers are likely to be present on metallic nano-structures due to either
Expand Down Expand Up @@ -160,7 +214,7 @@ interactions:
Sci. Eng. A"},{"key":"2023062402360541600_c55","doi-asserted-by":"publisher","first-page":"057129","DOI":"10.1063\/1.4880241","volume":"4","year":"2014","journal-title":"AIP
Adv."},{"key":"2023062402360541600_c56","doi-asserted-by":"publisher","first-page":"94","DOI":"10.1016\/j.susc.2014.10.017","volume":"633","year":"2015","journal-title":"Surf.
Sci."},{"key":"2023062402360541600_c57","doi-asserted-by":"publisher","first-page":"710","DOI":"10.1016\/j.pmatsci.2010.04.001","volume":"55","year":"2010","journal-title":"Prog.
Mater. Sci."}],"container-title":["Journal of Applied Physics"],"language":"en","link":[{"URL":"https:\/\/pubs.aip.org\/aip\/jap\/article-pdf\/doi\/10.1063\/1.4938384\/15174088\/235306_1_online.pdf","content-type":"application\/pdf","content-version":"vor","intended-application":"syndication"},{"URL":"https:\/\/pubs.aip.org\/aip\/jap\/article-pdf\/doi\/10.1063\/1.4938384\/15174088\/235306_1_online.pdf","content-type":"unspecified","content-version":"vor","intended-application":"similarity-checking"}],"deposited":{"date-parts":[[2023,6,24]],"date-time":"2023-06-24T15:07:33Z","timestamp":1687619253000},"score":64.015274,"resource":{"primary":{"URL":"https:\/\/pubs.aip.org\/jap\/article\/118\/23\/235306\/141678\/Effect-of-native-oxide-layers-on-copper-thin-film"}},"issued":{"date-parts":[[2015,12,21]]},"references-count":57,"journal-issue":{"issue":"23","published-print":{"date-parts":[[2015,12,21]]}},"URL":"http:\/\/dx.doi.org\/10.1063\/1.4938384","ISSN":["0021-8979","1089-7550"],"issn-type":[{"value":"0021-8979","type":"print"},{"value":"1089-7550","type":"electronic"}],"published-other":{"date-parts":[[2015,12,21]]},"published":{"date-parts":[[2015,12,21]]}}],"items-per-page":1,"query":{"start-index":0,"search-terms":null}}}'
Mater. Sci."}],"container-title":["Journal of Applied Physics"],"language":"en","link":[{"URL":"https:\/\/pubs.aip.org\/aip\/jap\/article-pdf\/doi\/10.1063\/1.4938384\/15174088\/235306_1_online.pdf","content-type":"application\/pdf","content-version":"vor","intended-application":"syndication"},{"URL":"https:\/\/pubs.aip.org\/aip\/jap\/article-pdf\/doi\/10.1063\/1.4938384\/15174088\/235306_1_online.pdf","content-type":"unspecified","content-version":"vor","intended-application":"similarity-checking"}],"deposited":{"date-parts":[[2023,6,24]],"date-time":"2023-06-24T15:07:33Z","timestamp":1687619253000},"score":63.781567,"resource":{"primary":{"URL":"https:\/\/pubs.aip.org\/jap\/article\/118\/23\/235306\/141678\/Effect-of-native-oxide-layers-on-copper-thin-film"}},"issued":{"date-parts":[[2015,12,21]]},"references-count":57,"journal-issue":{"issue":"23","published-print":{"date-parts":[[2015,12,21]]}},"URL":"http:\/\/dx.doi.org\/10.1063\/1.4938384","ISSN":["0021-8979","1089-7550"],"issn-type":[{"value":"0021-8979","type":"print"},{"value":"1089-7550","type":"electronic"}],"published-other":{"date-parts":[[2015,12,21]]},"published":{"date-parts":[[2015,12,21]]}}],"items-per-page":1,"query":{"start-index":0,"search-terms":null}}}'
headers:
Access-Control-Allow-Headers:
- X-Requested-With, Accept, Accept-Encoding, Accept-Charset, Accept-Language,
Expand All @@ -174,11 +228,11 @@ interactions:
Content-Encoding:
- gzip
Content-Length:
- "3945"
- "3947"
Content-Type:
- application/json
Date:
- Wed, 04 Sep 2024 22:54:18 GMT
- Mon, 16 Sep 2024 14:27:15 GMT
Server:
- Jetty(9.4.40.v20210413)
Vary:
Expand Down Expand Up @@ -225,7 +279,7 @@ interactions:
Connection:
- close
Date:
- Wed, 04 Sep 2024 22:54:19 GMT
- Mon, 16 Sep 2024 14:27:16 GMT
Server:
- Jetty(9.4.40.v20210413)
Transfer-Encoding:
Expand All @@ -245,58 +299,4 @@ interactions:
status:
code: 200
message: OK
- request:
body: null
headers: {}
method: GET
uri: https://api.unpaywall.org/v2/search?query=Effect%20of%20native%20oxide%20layers%20on%20copper%20thin-film%20tensile%20properties:%20A%20reactive%20molecular%20dynamics%20study&[email protected]
response:
body:
string:
'{"elapsed_seconds":0.357,"results":[{"response":{"best_oa_location":null,"data_standard":2,"doi":"10.1063/1.4938384","doi_url":"https://doi.org/10.1063/1.4938384","first_oa_location":null,"genre":"journal-article","has_repository_copy":false,"is_oa":false,"is_paratext":false,"journal_is_in_doaj":false,"journal_is_oa":false,"journal_issn_l":"0021-8979","journal_issns":"0021-8979,1089-7550","journal_name":"Journal
of Applied Physics","oa_locations":[],"oa_locations_embargoed":[],"oa_status":"closed","published_date":"2015-12-21","publisher":"AIP
Publishing","title":"Effect of native oxide layers on copper thin-film tensile
properties: A reactive molecular dynamics study","updated":"2023-07-31T05:28:57.007821","year":2015,"z_authors":[{"affiliation":[{"name":"University
of Rochester 1 Materials Science Program, , Rochester, New York 14627, USA"}],"family":"Skarlinski","given":"Michael
D.","sequence":"first"},{"affiliation":[{"name":"University of Rochester 1
Materials Science Program, , Rochester, New York 14627, USA"},{"name":"University
of Rochester 2 Department of Mechanical Engineering, , Rochester, New York
14627, USA"}],"family":"Quesnel","given":"David J.","sequence":"additional"}]},"score":0.009231734,"snippet":"<b>Effect</b>
of <b>native</b> <b>oxide</b> <b>layers</b> on <b>copper</b> <b>thin</b>-<b>film</b>
<b>tensile</b> <b>properties</b>: A <b>reactive</b> <b>molecular</b> <b>dynamics</b>
<b>study</b>"}]}

'
headers:
Access-Control-Allow-Headers:
- origin, content-type, accept, x-requested-with
Access-Control-Allow-Methods:
- POST, GET, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Origin:
- "*"
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- "706"
Content-Type:
- application/json
Date:
- Wed, 04 Sep 2024 22:54:20 GMT
Nel:
- '{"report_to":"heroku-nel","max_age":3600,"success_fraction":0.005,"failure_fraction":0.05,"response_headers":["Via"]}'
Report-To:
- '{"group":"heroku-nel","max_age":3600,"endpoints":[{"url":"https://nel.heroku.com/reports?ts=1725490458&sid=c46efe9b-d3d2-4a0c-8c76-bfafa16c5add&s=3iH3mreiGrF6hHOFWXTx5avt8oC7DhAjNvJhBq5sqs8%3D"}]}'
Reporting-Endpoints:
- heroku-nel=https://nel.heroku.com/reports?ts=1725490458&sid=c46efe9b-d3d2-4a0c-8c76-bfafa16c5add&s=3iH3mreiGrF6hHOFWXTx5avt8oC7DhAjNvJhBq5sqs8%3D
Server:
- gunicorn
Vary:
- Accept-Encoding
Via:
- 1.1 vegur
status:
code: 200
message: OK
version: 1
Loading