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
# print dumps(mods_json) 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. from document import (_enrich_json_with_data, _enrich_json_with_base, _enrich_json_with_text) from ApplicationScope import getAnnObject #~ j_dic = getAnnObject("/brat_vb/sentiment","test") #~ _enrich_json_with_base(j_dic) j_dic = {} _enrich_json_with_base(j_dic) txt_file_path = ann_obj.get_document() + '.' + TEXT_FILE_SUFFIX # 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 from logging import info as log_info from annotation import TextBoundAnnotation, TextBoundAnnotationWithText from copy import deepcopy