Exemple #1
0
def segment_ins_del(tmp_pwa, tmp_pwb):
    base_a = get_base(tmp_pwa)
    base_b = get_base(tmp_pwb)
    index_a = re.findall(digit, base_a)
    index_b = re.findall(digit, base_b)
    count_a = 0
    count_b = 0
    for i in range(len(index_a)):
        tmp_a = tmp_pwa[count_a:count_a + int(index_a[i])]
        tmp_b = tmp_pwb[count_b:count_b + int(index_b[i])]
        count_a += int(index_a[i])
        count_b += int(index_b[i])

        sub = get_substring(tmp_a, tmp_b)
        len_sub = len(sub)
        start1 = tmp_a.find(sub)
        start2 = tmp_b.find(sub)
        hd_ = tmp_a[:start1]
        td_ = tmp_a[start1 + len_sub:]
        hi_ = tmp_b[:start2]
        ti_ = tmp_b[start2 + len_sub:]
        if not (hd_ + td_ + hi_ + ti_):
            # do not change!
            base_a = get_base(tmp_a)
            if not base_a in segment_dict:
                segment_dict[base_a] = base_table()
            segment_dict[base_a]._insert(0, 'No')
            continue
        if hd_:
            base_a = get_base(tmp_a)
            if not base_a in segment_dict:
                segment_dict[base_a] = base_table()
            segment_dict[base_a]._insert(hd_, 'hd')
            tmp_a = tmp_a[len(hd_):]
        if td_:
            base_a = get_base(tmp_a)
            if not base_a in segment_dict:
                segment_dict[base_a] = base_table()
            segment_dict[base_a]._insert(td_, 'td')
            tmp_a = tmp_a[:-len(td_)]
        if hi_:
            base_a = get_base(tmp_a)
            if not base_a in segment_dict:
                segment_dict[base_a] = base_table()
            segment_dict[base_a]._insert(hi_, 'hi')
            tmp_a = hi_ + tmp_a
        if ti_:
            base_a = get_base(tmp_a)
            if not base_a in segment_dict:
                segment_dict[base_a] = base_table()
            segment_dict[base_a]._insert(ti_, 'ti')
            tmp_a = tmp_a + ti_
Exemple #2
0
def structure_hi(pwaE, pwb, hi, hi_len):
    hi_len = hi_len.copy()
    hi_len_ = hi_len.copy()
    for i in range(len(hi)):
        if hi[i] not in 'LDS':
            typ = hi[i] + hi_len_[i]
            hi_len_[i] = str(len(type_dict[typ]))
    hi_str = pwb[:sum([int(x) for x in hi_len_])]
    hi_len_.reverse()
    hi_len.reverse()
    hi = hi[::-1]

    for i in range(len(hi)):
        base_a = get_base(pwaE, type_dict)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        if hi[i] in 'LDS':
            tmp = hi_str[-int(hi_len_[i]):]
            structure_dict[base_a]._insert(tmp, 'hi')
            #hi_str = hi_str[:-int(hi_len_[i])]
            pwaE = tmp + pwaE
        else:
            #hi_str = hi_str[:-len(base)]
            typ = hi[i] + hi_len[i]
            structure_dict[base_a]._insert(typ, 'ti')
            pwaE = type_dict[typ] + pwaE
        #base_hi = get_base(hi)
    return pwaE, hi_len_
Exemple #3
0
def structure_hd(pwaE, hd_len=None):
    for i in hd_len:
        hd_str = pwaE[:int(i)]
        base_a = get_base(pwaE)
        pwaE = pwaE[int(i):]
        #base_hd = get_base(hd)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        structure_dict[base_a]._insert(hd_str, 'hd')
    return pwaE
Exemple #4
0
def structure_ti(pwaE, ti_len=None, ti_str=None):
    count = 0
    for i in ti_len:
        base_a = get_base(pwaE)
        pwaE = pwaE + ti_str[count:count + int(i)]
        #base_ti = get_base(ti)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        structure_dict[base_a]._insert(ti_str[count:count + int(i)], 'ti')
        count += int(i)
    return pwaE
Exemple #5
0
def structure_td(pwaE, td_len=None):
    td_len = td_len.copy()
    td_len.reverse()
    for i in td_len:
        td_str = pwaE[-int(i):]
        base_a = get_base(pwaE)
        pwaE = pwaE[:-int(i)]
        #base_td = get_base(td)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        structure_dict[base_a]._insert(td_str, 'td')
    return pwaE
Exemple #6
0
def structure_hd(pwaE, hd, hd_len):
    for i in range(len(hd)):
        base_a = get_base(pwaE, type_dict)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        if hd[i] in 'LDS':
            hd_str = pwaE[:int(hd_len[i])]
            hd_base = get_base(hd_str, type_dict)
            pwaE = pwaE[int(hd_len[i]):]
        else:
            hd_base = hd[i] + hd_len[i]
            pwaE = pwaE[len(type_dict[hd_base]):]
        structure_dict[base_a]._insert(hd_base, 'hd')
    return pwaE
Exemple #7
0
def structure_hi(pwaE, hi_len=None, hi_str=None):
    hi_len = hi_len.copy()
    hi_len.reverse()
    for i in hi_len:
        base_a = get_base(pwaE)
        tmp = hi_str[-int(i):]
        hi_str = hi_str[:-int(i)]
        pwaE = tmp + pwaE

        #base_hi = get_base(hi)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        structure_dict[base_a]._insert(tmp, 'hi')
    return pwaE
Exemple #8
0
def structure_td(pwaE, td, td_len):
    td_len = td_len.copy()
    td_len.reverse()
    td = td[::-1]
    for i in range(len(td)):
        base_a = get_base(pwaE, type_dict)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        if td[i] in 'LDS':
            td_str = pwaE[-int(td_len[i]):]
            td_base = get_base(td_str, type_dict)
            pwaE = pwaE[:-int(td_len[i])]
        else:
            td_base = td[i] + td_len[i]
            pwaE = pwaE[:-len(type_dict[td_base])]
        structure_dict[base_a]._insert(td_base, 'td')
    return pwaE
Exemple #9
0
def structure_ins_del(pwaE, pwb):
    # 对齐structure
    base_a = get_base(pwaE)
    base_b = get_base(pwb)
    if base_a == base_b:
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        structure_dict[base_a]._insert(0, 'No')
        return
    struct_a = ''.join(re.findall(struct, base_a))
    index_a = re.findall(digit, base_a)
    struct_b = ''.join(re.findall(struct, base_b))
    index_b = re.findall(digit, base_b)
    # 'L3D4S1','L2S3'
    sub = get_substring(struct_a, struct_b)
    pos1 = struct_a.find(sub)
    pos2 = struct_b.find(sub)

    hd = struct_a[:pos1]
    hd_len = index_a[:pos1]
    #hd_str = pwaE[:sum([int(x) for x in hd_len])]
    td = struct_a[pos1 + len(sub):]
    td_len = index_a[pos1 + len(sub):]
    #td_str = pwaE[-sum([int(x) for x in td_len]):]
    hi = struct_b[:pos2]
    hi_len = index_b[:pos2]
    hi_str = pwb[:sum([int(x) for x in hi_len])]
    ti = struct_b[pos2 + len(sub):]
    ti_len = index_b[pos2 + len(sub):]
    ti_str = pwb[-sum([int(x) for x in ti_len]):]

    if hd:
        pwaE = structure_hd(pwaE, hd_len)
    if td:
        pwaE = structure_td(pwaE, td_len)
    tmp_pwa = pwaE
    # 删除完之后就可以进行结构内的hi'、ti'等操作
    if hi:
        pwaE = structure_hi(pwaE, hi_len, hi_str)
    if ti:
        pwaE = structure_ti(pwaE, ti_len, ti_str)

    return tmp_pwa, pwaE, hi_len, ti_len
Exemple #10
0
def structure_ins_del(pwaE, pwb):
    # 对齐structure
    base_a = get_base(pwaE, type_dict)
    base_b = get_base(pwb, type_dict)
    if base_a == base_b:
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        structure_dict[base_a]._insert(0, 'No')
        return
    struct_a = ''.join(re.findall(struct, base_a))
    index_a = re.findall(digit, base_a)
    struct_b = ''.join(re.findall(struct, base_b))
    index_b = re.findall(digit, base_b)

    # 'L3D4S1','L2S3'
    sub = get_substring(struct_a, struct_b)
    pos1 = struct_a.find(sub)
    pos2 = struct_b.find(sub)
    hd = struct_a[:pos1]
    hd_len = index_a[:pos1]

    td = struct_a[pos1 + len(sub):]
    td_len = index_a[pos1 + len(sub):]

    hi = struct_b[:pos2]
    hi_len = index_b[:pos2]

    ti = struct_b[pos2 + len(sub):]
    ti_len = index_b[pos2 + len(sub):]

    if hd:
        pwaE = structure_hd(pwaE, hd, hd_len)
    if td:
        pwaE = structure_td(pwaE, td, td_len)
    # 删除完之后就可以进行结构内的hi'、ti'等操作
    tmp_pwa = pwaE
    if hi:
        pwaE, hi_len = structure_hi(pwaE, pwb, hi, hi_len)
    if ti:
        pwaE, ti_len = structure_ti(pwaE, pwb, ti, ti_len)

    return tmp_pwa, pwaE, hi_len, ti_len
Exemple #11
0
def structure_ti(pwaE, pwb, ti, ti_len):
    ti_len_ = ti_len.copy()
    for i in range(len(ti)):
        if ti[i] not in 'LDS':
            typ = ti[i] + ti_len_[i]
            ti_len_[i] = len(type_dict[typ])
    ti_str = pwb[:sum([int(x) for x in ti_len_])]

    count = 0
    for i in range(len(ti)):
        base_a = get_base(pwaE, type_dict)
        if not base_a in structure_dict:
            structure_dict[base_a] = base_table()
        if ti[i] in 'LDS':
            pwaE = pwaE + ti_str[count:count + int(ti_len_[i])]
            structure_dict[base_a]._insert(
                ti_str[count:count + int(ti_len_[i])], 'ti')
            count += int(ti_len_[i])
        else:
            typ = ti[i] + ti_len[i]
            structure_dict[base_a]._insert(typ, 'ti')
            pwaE = pwaE + type_dict[typ]
            count += len(type_dict[typ])
    return pwaE, ti_len_