fabiobatalha / crossrefapi

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

Question: matching titles to doi #42

Closed brunoamaral closed 2 years ago

brunoamaral commented 2 years ago

Apologies if this isn't the right channel to ask.

I'm trying to match titles to their DOI with a simple loop

for article in articles:
    work = works.query(bibliographic=article.title)
    for w in work:
        if hasattr(article, 'title') and hasattr(w,'title') and w['title'][0] == article.title:
            article.doi = w['DOI']
            print(article.doi)
            article.save()
        else:
            print('not found', article.title)

But since work contains over 80k results, the method is too slow to be valuable. I have also tried with .sample(20) hoping it would narrow the search, but it didn't match any titles. Is it because the sample is random?

Is there any way I can just fetch the first items from the work class? It seems they always contain the match I need.

Ankush-Chander commented 2 years ago

Hi @brunoamaral Thanks for trying out crossrefapi.

Yes .sample(20) sends random 20 results.

You can achieve desired result by applying .sort("relevance") Please checkout this comment for detailed code.

brunoamaral commented 2 years ago

That's it, fantastic 😁