def test_dmp_find(inputs, dmp_find_test_cases): updater = Blupdate(inputs['srcbl'], inputs['dstbl'], context_len=4) result = updater.dmp_find(dmp_find_test_cases['context'], dmp_find_test_cases['dstcoordestimate']) assert result == dmp_find_test_cases['expected_result']
def test_get_cctv_for_coord(inputs, cctv_for_coord_test_cases): updater = Blupdate(inputs["srcbl"], inputs["dstbl"]) result = updater.get_cctv_for_coord( cctv_for_coord_test_cases["srcblcoord"]) assert result == cctv_for_coord_test_cases["expected_result"]
def test_get_cctv_for_coord(inputs, cctv_for_coord_test_cases): updater = Blupdate(inputs['srcbl'], inputs['dstbl']) result = updater.get_cctv_for_coord( cctv_for_coord_test_cases['srcblcoord']) assert result == cctv_for_coord_test_cases['expected_result']
def test_updated_coord(inputs, get_updated_coord_test_cases): updater = Blupdate(inputs['srcbl'], inputs['dstbl'], context_len=4) result = updater.get_updated_coord( get_updated_coord_test_cases['srcblcoord']) assert result == get_updated_coord_test_cases['expected_result']
def test_dmp_find(inputs, dmp_find_test_cases): updater = Blupdate(inputs["srcbl"], inputs["dstbl"], context_len=4) result = updater.dmp_find(dmp_find_test_cases["context"], dmp_find_test_cases["dstcoordestimate"]) assert result == dmp_find_test_cases["expected_result"]
def test_update(): # prepare work to be updated update_path = data_path / 'update' if update_path.is_dir(): shutil.rmtree(str(update_path)) shutil.copytree(str(data_path / 'v1'), str(update_path)) srcbl = (update_path / 'v1.opf' / 'base.txt').read_text() dstbl = (data_path / 'v2' / 'v2.opf' / 'base.txt').read_text() updater = Blupdate(srcbl, dstbl) updater.update_annotations(update_path / 'v1.opf') for layer in ['title', 'yigchung', 'quotes', 'tsawa', 'sapche']: update_result, v2_result = get_layer(layer, 'update', 'v2') assert update_result == v2_result
def update(**kwargs): """ Command to update the base text with your edits. """ work_id = get_pecha_id(kwargs['work_number']) if work_id: if work_id in pecha_list(): repo_path = config["OP_DATA_PATH"] / work_id repo = Repo(str(repo_path)) # if edited branch exists, then to check for changes in edited branch branch_name = 'edited' if branch_name in repo.heads: current = repo.heads[branch_name] current.checkout() is_changed, srcbl, dstbl = check_edits(work_id) if is_changed: msg = f'Updating {work_id} base text.' click.echo(INFO.format(msg)) # Update layer annotations updater = Blupdate(srcbl, dstbl) opfpath = repo_path / f'{work_id}.opf' updater.update_annotations(opfpath) # Update base-text src = get_data_path() / f'{work_id}.txt' dst = opfpath / 'base.txt' shutil.copy(str(src), str(dst)) # Create edited branch and push to Github status = github_push(repo, branch_name) # logging if status: msg = f'Pecha edits {work_id} are uploaded for futher validation' click.echo(INFO.format(msg)) else: repo_reset(repo, branch_name) else: msg = f'There are no changes in Pecha {work_id}' click.echo(ERROR.format(msg)) else: msg = f'{work_id} does not exits, check the work-id' click.echo(ERROR.format(msg))
def update_base_layer(pecha_id, base_name, new_base, layers): pecha = get_pecha(pecha_id) old_base = pecha.get_base(base_name) pecha.base[base_name] = new_base pecha.save_base() updater = Blupdate(old_base, new_base) for layer in layers: update_ann_layer(layer, updater) pecha.save_layer( base_name, layer["annotation_type"].value, Layer.parse_obj(layer) ) return layers
def reinsert(pecha_path, notes_path, layer_name): pecha_opf_path = pecha_path / f"{pecha_path.name}.opf" pecha_index = get_index(pecha_opf_path) layer_ann = None prev_vol = None note_idx = 0 for text_ann in pecha_index["annotations"]: notes_fn = notes_path / f'{text_ann["work"]}_a_reinserted.txt' if not notes_fn.is_file(): continue # if not text_ann['work'] == 'D1115': continue print(f'[INFO] Processing {text_ann["work"]} ...') notes, base_text = get_notes(notes_fn) if not notes: continue # cross-vol text have mutlitple layer files in terms of volume for vol in text_ann["span"]: work_text = get_work_text(pecha_opf_path, vol) if prev_vol != vol["vol"]: # first save the layer of previous volume. if layer_ann: save_layer_ann(layer_ann, pecha_opf_path, prev_vol[5:], layer_name) # then load the layer of next volume if layer_name in ["peydurma"]: layer_ann = get_layer_ann( pecha_opf_path, vol["vol"][5:], layer_name ) else: layer_ann = create_layer(layer_name) note_idx = 0 # insert each foot_note of current text into layer with note_idx. bl = Blupdate(base_text, work_text) if len(bl.cctv) <= 1: error_msg = f'[diff-text] {text_ann["work"]} (derge-tengyur)\n' print(error_msg) error_log_fn.open("a").write(error_msg) break for note in notes: update_layer(note, bl, note_idx, vol, layer_ann) note_idx += 1 prev_vol = vol["vol"]
def test_compute_cctv(inputs, compute_cctv_test_cases): updater = Blupdate(inputs['srcbl'], inputs['dstbl']) result = updater.cctv assert result == compute_cctv_test_cases['expected_result']
def updater(): srcbl = (data_path / 'v1' / 'v1.opf' / 'base.txt').read_text() dstbl = (data_path / 'v2' / 'v2.opf' / 'base.txt').read_text() updater = Blupdate(srcbl, dstbl) return updater
def test_get_context(inputs, get_context_test_cases): updater = Blupdate(inputs["srcbl"], inputs["dstbl"], context_len=4) result = updater.get_context(get_context_test_cases["srcblcoord"]) assert result == get_context_test_cases["expected_result"]
def test_compute_cctv(inputs, compute_cctv_test_cases): updater = Blupdate(inputs["srcbl"], inputs["dstbl"]) result = updater.cctv assert result == compute_cctv_test_cases["expected_result"]
def updater(): srcbl = (data_path / "v1" / "v1.opf" / "base.txt").read_text() dstbl = (data_path / "v2" / "v2.opf" / "base.txt").read_text() updater = Blupdate(srcbl, dstbl) return updater
def test_updated_coord(inputs, updated_coord): updater = Blupdate(inputs["srcbl"], inputs["dstbl"], context_len=4) result = updater.get_updated_coord(updated_coord["srcblcoord"]) assert result == updated_coord["expected_result"]