def format_element(bfo, newline=False, show_doi=False): """Print link to proceedings if the proceedings exist. @param newline: if True, add <br /> at the end @param show_doi: if True, show DOI of the proceeding in brackets """ cnum = str(bfo.field('111__g')) out = "" if not cnum: # something is wrong, return empty string return out search_result = perform_request_search(p="773__w:" + cnum + " and 980__a:proceedings") if search_result: if len(search_result) > 1: # multiple proceedings proceedings = [] for i, recID in enumerate(search_result): # check for the DOI and put it in brackets in the output doi = get_fieldvalues(recID, '0247_a') if show_doi and doi: proceedings.append('<a href="/record/%(ID)s">#%(number)s</a> (DOI: <a href="http://dx.doi.org/%(doi)s">%(doi)s</a>)' % {'ID': recID, 'number': i+1, 'doi': doi[0]}) else: proceedings.append('<a href="/record/%(ID)s">#%(number)s</a>' % {'ID': recID, 'number': i+1}) out = 'Proceedings: ' out += ', '.join(proceedings) elif len(search_result) == 1: # only one proceeding out += '<a href="/record/' + str(search_result[0]) + '">Proceedings</a>' if newline: out += '<br/>' return out
def get_record_year(recid): record_date = [] for tag in DATE_TAGS: record_date = get_fieldvalues(recid, tag) if record_date: break return record_date
def _get_phrases_for_tokenizing(self, tag, recIDs): """ Gets phrases for later tokenization for a range of records and specific tag. @param tag: MARC tag @param recIDs: list of specific recIDs (not range) """ if len(recIDs) == 0: return () bibXXx = "bib" + tag[0] + tag[1] + "x" bibrec_bibXXx = "bibrec_" + bibXXx query = """SELECT bb.id_bibrec,b.value FROM %s AS b, %s AS bb WHERE bb.id_bibrec BETWEEN %%s AND %%s AND bb.id_bibxxx=b.id AND tag LIKE %%s""" % (bibXXx, bibrec_bibXXx) phrases = run_sql(query, (self.first_recID, self.last_recID, tag)) if tag == '8564_u': ## FIXME: Quick hack to be sure that hidden files are ## actually indexed. phrases = set(phrases) for recID in recIDs: for bibdocfile in BibRecDocs(recID).list_latest_files(): phrases.add((recID, bibdocfile.get_url())) #authority records pattern = tag.replace('%', '*') matches = fnmatch.filter( CFG_BIBAUTHORITY_CONTROLLED_FIELDS_BIBLIOGRAPHIC.keys(), pattern) if not len(matches): return phrases phrases = set(phrases) for tag_match in matches: authority_tag = tag_match[0:3] + "__0" for recID in recIDs: control_nos = get_fieldvalues(recID, authority_tag) for control_no in control_nos: new_strings = get_index_strings_by_control_no(control_no) for string_value in new_strings: phrases.add((recID, string_value)) return phrases
def _get_phrases_for_tokenizing(self, tag, recIDs): """ Gets phrases for later tokenization for a range of records and specific tag. @param tag: MARC tag @param recIDs: list of specific recIDs (not range) """ if len(recIDs) == 0: return () bibXXx = "bib" + tag[0] + tag[1] + "x" bibrec_bibXXx = "bibrec_" + bibXXx query = """SELECT bb.id_bibrec,b.value FROM %s AS b, %s AS bb WHERE bb.id_bibrec BETWEEN %%s AND %%s AND bb.id_bibxxx=b.id AND tag LIKE %%s""" % (bibXXx, bibrec_bibXXx) phrases = run_sql(query, (self.first_recID, self.last_recID, tag)) if tag == '8564_u': ## FIXME: Quick hack to be sure that hidden files are ## actually indexed. phrases = set(phrases) for recID in recIDs: for bibdocfile in BibRecDocs(recID).list_latest_files(): phrases.add((recID, bibdocfile.get_url())) #authority records pattern = tag.replace('%', '*') matches = fnmatch.filter(CFG_BIBAUTHORITY_CONTROLLED_FIELDS_BIBLIOGRAPHIC.keys(), pattern) if not len(matches): return phrases phrases = set(phrases) for tag_match in matches: authority_tag = tag_match[0:3] + "__0" for recID in recIDs: control_nos = get_fieldvalues(recID, authority_tag) for control_no in control_nos: new_strings = get_index_strings_by_control_no(control_no) for string_value in new_strings: phrases.add((recID, string_value)) return phrases
def get_tag_values(recid, tags): for tag in tags: for value in get_fieldvalues(recid, tag): yield value
def get_tag_values(recid, tags): for tag in tags: for value in get_fieldvalues(recid, tag): yield value