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
def label(doc): if context_type == 'book': md = metadata[doc] try: 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
def label(doc): if app.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]) if vol: return "p%s of %s of %s" % (page_no, vol, md['titles'][0]) else: raise ValueError("No Volume") except: pass try: return "p%s of %s" % (page_no, md['titles'][0]) except: return doc else: # app.context_type == 'book': try: md = metadata[doc] titles = md.get('titles') if not titles: titles = md.get('title') return titles[0] except (TypeError, KeyError, IndexError): return doc
def label(doc): if context_type == 'document': doc = doc.replace('.txt', '') try: md = metadata[doc] return "BOOK -- " + md['title'][0] except: newdoc = doc.replace('_', ' ') try: id, details = newdoc.split('--', 1) details = details.lower() id = id.replace("LETTER ", '') #newdoc = id + " -- " + string.capwords(details) newdoc = string.capwords(details) except: pass return "LETTER -- " + newdoc 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
def label(doc): if context_type == 'document': doc = doc.replace('.txt','') try: md = metadata[doc] return "BOOK -- " + md['title'][0] except: newdoc = doc.replace('_', ' ') try: id, details = newdoc.split('--',1) details = details.lower() id = id.replace("LETTER ",'') #newdoc = id + " -- " + string.capwords(details) newdoc = string.capwords(details) except: pass return "LETTER -- " + newdoc 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