import json


def get_passage_id(ctx_entry):
    """Retrieve a passage ID from the positive or negative context entry:
       an element in an array with a key positive_ctxs, negative_ctxs, or
       hard_negative_ctxs. The problem is that some entries encode them
       using the key psg_id and some use the key passage_id.
    """
    for psg_key in ['psg_id', 'passage_id']:
        if psg_key in ctx_entry:
            return ctx_entry[psg_key]

    raise Exception('No passage keys in the entry: ' + json.dumps(ctx_entry))