fabiobatalha / crossrefapi

A python library that implements the Crossref API.
BSD 2-Clause "Simplified" License
265 stars 44 forks source link

Result inconsistency #32

Closed priyam-maheshwari closed 3 years ago

priyam-maheshwari commented 3 years ago

If I run below code it gives me 0 results, which is expected journals.works('1946-3944').filter(type='journal-article').filter(from_created_date='2021-11-05').filter(until_created_date='2021-11-05').count()

But when I run the same code with all(), it gives me some random results. journals.works('1946-3944').filter(type='journal-article').filter(from_created_date='2021-11-05').filter(until_created_date='2021-11-05').all() If I iterate over the results, it gives me some random results. Even this code should return an empty array

fabiobatalha commented 3 years ago

Hello @priyam-maheshwari

This can be interpreted as a bad design decision.

What happens is the method "all" override/ignore all the previous parameters, once it intends to retrieve all records of the journal '1946-2944'.

So, when you put all() in any place, it will delivery an iterable for the query https://api.crossref.org/journals/1946-3944/works.

It is the same of iterate through journals.works('1946-3944').

for articles in journals.works('1946-3944'):
    print(article['DOI'])

if you want to retrieve the data related to your query and filters, you only need to iterate over it.

In [1]: from crossref.restful import Journals                                                                                                                                                               

In [2]: journals = Journals()                                                                                                                                                                               

In [3]: journals.works('1946-3944').url                                                                                                                                                                     
Out[3]: 'https://api.crossref.org/journals/1946-3944/works'

In [4]: journals.works('1946-3944').count()                                                                                                                                                                 
Out[4]: 1940

In [5]: journals.works('1946-3944').filter(type='journal-article').url                                                                                                                                      
Out[5]: 'https://api.crossref.org/journals/1946-3944/works?filter=type%3Ajournal-article'

In [6]: journals.works('1946-3944').filter(type='journal-article').count()                                                                                                                                  
Out[6]: 1940

In [7]: for article in journals.works('1946-3944').filter(type='journal-article'): 
   ...:     print(article['DOI'], article['created']['date-time'], article['short-container-title'][0], f"{article['title'][0][:10]}...") 
   ...:                                                                                                                                                                                                     
10.4271/2017-01-0329 2017-03-28T10:24:28Z SAE Int. J. Engines A Computat...
10.4271/2017-24-0041 2017-09-04T09:02:23Z SAE Int. J. Engines A 3D CFD S...
10.4271/2018-01-0264 2018-04-03T09:01:56Z SAE Int. J. Engines System and...

The reason your query retrieve 0 records is because the from_created_date and until_created_date has a value out of scope.

Try to use a valid date, as for example:

In [1]: from crossref.restful import Journals                                                                                                                                                               

In [2]: journals = Journals()                                                                                                                                                                               

In [3]: journals.works('1946-3944').filter(type='journal-article').filter(from_created_date='2011-09-15').filter(until_created_date='2011-09-15').url                                                       
Out[3]: 'https://api.crossref.org/journals/1946-3944/works?filter=type%3Ajournal-article%2Cfrom-created-date%3A2011-09-15%2Cuntil-created-date%3A2011-09-15'

In [4]: journals.works('1946-3944').filter(type='journal-article').filter(from_created_date='2011-09-15').filter(until_created_date='2011-09-15').count()                                                   
Out[4]: 23

In [5]: for article in journals.works('1946-3944').filter(type='journal-article').filter(from_created_date='2011-09-15').filter(until_created_date='2011-09-15'): 
   ...:     print(article['DOI'], article['created']['date-time'], article['short-container-title'][0], f"{article['title'][0][:10]}...") 
   ...:                                                                                                                                                                                                     
10.4271/2011-24-0064 2011-09-15T18:01:05Z SAE Int. J. Engines Measuremen...
10.4271/2011-24-0054 2011-09-15T18:01:05Z SAE Int. J. Engines The Effect...
10.4271/2011-24-0191 2011-09-15T14:00:35Z SAE Int. J. Engines High Tempe...
10.4271/2011-24-0201 2011-09-15T14:00:35Z SAE Int. J. Engines Toxic Impa...
10.4271/2011-24-0210 2011-09-15T18:00:35Z SAE Int. J. Engines Analysis o...
10.4271/2011-24-0209 2011-09-15T14:00:35Z SAE Int. J. Engines Crankcase ...
10.4271/2011-24-0215 2011-09-15T18:00:35Z SAE Int. J. Engines The 3Dcell...
10.4271/2011-01-2206 2011-09-15T18:00:24Z SAE Int. J. Engines Meeting No...
10.4271/2011-01-2212 2011-09-15T18:00:24Z SAE Int. J. Engines Automated ...
10.4271/2011-24-0134 2011-09-15T18:01:05Z SAE Int. J. Engines Applicatio...
10.4271/2011-24-0089 2011-09-15T18:01:05Z SAE Int. J. Engines 2-Stroke H...
10.4271/2011-24-0126 2011-09-15T18:01:05Z SAE Int. J. Engines Map-Based ...
10.4271/2011-24-0221 2011-09-15T18:00:35Z SAE Int. J. Engines Investigat...
10.4271/2011-24-0096 2011-09-15T14:01:05Z SAE Int. J. Engines Mixture Fo...
10.4271/2011-01-2221 2011-09-15T18:00:24Z SAE Int. J. Engines The Achate...
10.4271/2011-24-0098 2011-09-15T18:01:05Z SAE Int. J. Engines Influence ...
10.4271/2011-24-0151 2011-09-15T18:01:05Z SAE Int. J. Engines Cfd Diagno...
10.4271/2011-24-0110 2011-09-15T18:01:05Z SAE Int. J. Engines CO2 Reduct...
10.4271/2011-01-2232 2011-09-15T14:00:24Z SAE Int. J. Engines Developmen...
10.4271/2011-24-0123 2011-09-15T14:01:05Z SAE Int. J. Engines Modeling a...
10.4271/2011-24-0074 2011-09-15T18:01:05Z SAE Int. J. Engines One Dimens...
10.4271/2011-01-2176 2011-09-15T18:00:24Z SAE Int. J. Engines Pneumatic ...
10.4271/2011-24-0142 2011-09-15T18:01:05Z SAE Int. J. Engines Misfire an...
priyam-maheshwari commented 3 years ago

ok thanks