Beispiel #1
0
def replace_lines(inst, clean_lines, norm_lines):
    """
    Given an instance and a list of clean lines and normal lines,
    add a cleaned tier and normalized if they do not already exist,
    otherwise, replace them.

    :param inst:
    :type inst: xigt.Igt
    :param clean_lines:
    :type clean_lines: list[dict]
    :param norm_lines:
    :type norm_lines: list[dict]
    """

    # -------------------------------------------
    # Remove the old clean/norm lines.
    # -------------------------------------------
    old_clean_tier = cleaned_tier(inst)
    if old_clean_tier is not None:
        inst.remove(old_clean_tier)

    old_norm_tier = normalized_tier(inst)
    if old_norm_tier is not None:
        inst.remove(old_norm_tier)

    # -------------------------------------------
    # Now, add the clean/norm lines, if provided.
    # -------------------------------------------
    if clean_lines:
        new_clean_tier = create_text_tier_from_lines(inst, clean_lines, CLEAN_ID, CLEAN_STATE)
        inst.append(new_clean_tier)

    if norm_lines:
        new_norm_tier = create_text_tier_from_lines(inst, norm_lines, NORM_ID, NORM_STATE)
        inst.append(new_norm_tier)

    return inst
Beispiel #2
0
 def test_add_norm_lines(self):
     inst = Igt(id='i1')
     add_normal_tier(inst, self.lines)
     self.assertEqual(len(normalized_tier(inst)), 2)
Beispiel #3
0
def add_editor_metadata(igt):
    ct = cleaned_tier(igt)
    nt = normalized_tier(igt)
    for tier in [ct, nt]:
        if tier is not None:
            set_meta_attr(tier, DATA_PROV, DATA_SRC_ATTR, EDITOR_DATA_SRC, metadata_type=EDITOR_METADATA_TYPE)