0

I am using Mendeley as a reference manager. The common notation for the references list in my field of work is the Guidelines by APA (7th). These guidelines recommend Sentence case for the title of the work in a reference list.

However my Mendeley database consists meanwhile of thousands of articles which are not coherently named (some are in Title Case - Meaning Written Like This Example other in Sentence case, thus common use of capital and small letters). Instead of working through every of the examples by hand, I thought there have to be a smarter solution.

I know that there is the Mendeley API feature as well as a Python library for using Mendeley API (here). I was wondering if anyone knows of a ready to use & open-source Python script that:

  1. Helps you set up the API (Access Token)
  2. Reads in your Library
  3. Changes all entries of type article or book-chapter to sentence case.

I might jump on that task if there is no such thing, as I can not be the only person, who encounters this issue.

Also is this the right place to ask, or would this be a better fit for Academia Stack Exchange?

1 Answer 1

0

I developed a Python script which can do the task. Important one would need to first register the script unter https://dev.mendeley.com/myapps.html just login and register the app and update the credentials in the code below.

I decided against using it, because the script stringently converts everything to sentence case, however it ignores exception, e.g., acronym for questionnaires (BDI for Beck Depression Inventory) would be converted by the script to "bdi". Anyways in case somebody in the future wants to pick up, here would be a good starting point.

I utilized only two libraries which would be needed to install before

pip install nltk
pip install mendeley

For string manipulation I used i.a. these useful answer

from mendeley import Mendeley
import requests
import nltk.data

# required for capitalizing
sent_tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')

# These values should match the ones supplied when registering your application.
# under https://dev.mendeley.com/myapps.html
redirect_uri = "http://localhost:5000/oauth"
client_id = 1111                    # please update
client_secret = "1jm12n2n2n3n2"     # please update

mendeley = Mendeley(client_id, redirect_uri=redirect_uri)
auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

res = requests.post(login_url, allow_redirects = False, data = {
    'username': 'urmail@urprovider.com',    # please update
    'password': 'urpassword'                # please update
})
res.headers
auth_response = res.headers['Location']

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)
print(session.files.list().items)

# Iterate over every document in your mendeley library
for document in session.documents.iter():
    # Uncomment below to see al titles and ids
    # print(document.id)
    # print(document.title)
    title = document.title
    # Note I would recommend you doing a backup of old titles by e.g. saving all ID and titles to a dataframe and saving it as .csv file

    title = document.title
    sentences = sent_tokenizer.tokenize(title)
    sentences = [sent.capitalize() for sent in sentences]
    title = ' '.join(sentences)
    # Capitalize after :
    ind = title.find(":")
    if ind != -1:
        first = title[:ind]
        second = title[ind + 1:].strip().capitalize()
        title = ': '.join([first, second])

    # Capitalize after "- "
    ind = title.find("- ")
    if ind != -1:
        first = title[:ind]
        second = title[ind + 1:].strip().capitalize()
        title = '- '.join([first, second])

    ind = title.find("– ")
    if ind != -1:
        first = title[:ind]
        second = title[ind + 1:].strip().capitalize()
        title = '- '.join([first, second])

    # WARNING IF UNCOMMENTED BELOW IT CHANGES TITLE OF DOC IN YOUR MENDELEY LIB PERMANENTLY
    # document.update(title=title)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.