def bold_citations(content,citation_title): found_citation_dict={} for citation in citation_title: cit=citation if(cit.strip().isdigit()): continue if(cit.strip()==""): continue citation_pos_list=marking(cit,content) if(len(citation_pos_list)!=0): found_citation_dict[cit]=citation_pos_list else: continue used_strings=[] replacing_dict={} for cit_title in found_citation_dict: position_list=found_citation_dict[cit_title] for position in position_list: to_be_replace=content[position[0]:position[1]] if(to_be_replace in used_strings): continue used_strings.append(to_be_replace) replace_string='<b>'+to_be_replace+'</b>' replacing_dict[to_be_replace]=replace_string list_of_citrepl=replacing_dict.keys() list_of_citrepl.sort(key = len,reverse=True) for ah in list_of_citrepl: content=content.replace(ah,replacing_dict[ah]) return(content)
def mark_citations(content,citation_title): found_citation_dict={} judge_mapping={} for k in citation_title: judge_mapping[k[0]]=[k[1],k[2]] for citation in citation_title: cit=citation[0] if(cit.strip().isdigit()): continue if(cit.strip()==""): continue citation_pos_list=marking(cit,content) if(len(citation_pos_list)!=0): found_citation_dict[cit]=citation_pos_list else: continue used_strings=[] replacing_dict={} for cit_title in found_citation_dict: position_list=found_citation_dict[cit_title] for position in position_list: to_be_replace=content[position[0]:position[1]] if(to_be_replace in used_strings): continue used_strings.append(to_be_replace) judgement_string=judge_mapping[cit_title][0] replace_string='<a href ='+'"'+'/judgement/'+judgement_string.__str__()+'"'+ ' id='+'"'+'jud'+str(judge_mapping[cit_title][1])+'"'+'>'+to_be_replace+'</a>' replacing_dict[to_be_replace]=replace_string list_of_citrepl=replacing_dict.keys() list_of_citrepl.sort(key = len,reverse=True) for ah in list_of_citrepl: content=content.replace(ah,replacing_dict[ah]) return(content)