def label(doc):
    if context_type == 'book':
        try:
            md = metadata[doc]
            return md['title'][0]
        except:
            return doc
    elif context_type == 'page':
        context_md = ctx_md['page']
        where = np.squeeze(np.where(np.in1d(context_md['page_label'], [doc])))
        page_no = context_md['file'][where]
        page_no = page_no.split('/')[-1]
        page_no = page_no.replace('.txt','')
        page_no = int(page_no)

        book_label = context_md['book_label'][where]
        md = metadata[book_label]
        try:
            xml = parse_marc(md['fullrecord'].encode('utf8'))
            vol = get_volume_from_marc(xml[0])
            return "p%s of %s of %s" % (page_no, vol, md['title'][0])
        except:
            pass
        try:
            return "p%s of %s" % (page_no, md['title'][0])
        except:
            return doc
dataset/ETHPy150Open inpho/topic-explorer/topicexplorer/extensions/htrc.py/label/original