def _json_from_ann_and_txt(ann_obj, txt_file_path): j_dic = {} from document import _enrich_json_with_data, _enrich_json_with_base, _enrich_json_with_text _enrich_json_with_base(j_dic) _enrich_json_with_text(j_dic, txt_file_path) _enrich_json_with_data(j_dic, ann_obj) return j_dic
def _json_from_ann(ann_obj): # Returns json with ann_obj contents and the relevant text. Used # for saving a round-trip when modifying annotations by attaching # the latest annotation data into the response to the edit # request. j_dic = {} txt_file_path = ann_obj.get_document() + '.' + TEXT_FILE_SUFFIX from document import (_enrich_json_with_data, _enrich_json_with_base, _enrich_json_with_text) _enrich_json_with_base(j_dic) # avoid reading text file if the given ann_obj already holds it try: doctext = ann_obj.get_document_text() except AttributeError: # no such luck doctext = None _enrich_json_with_text(j_dic, txt_file_path, doctext) _enrich_json_with_data(j_dic, ann_obj) return j_dic