align_text.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:errant 作者: chrisjbryant 项目源码 文件源码
def get_opcodes(alignment):
    s_start = 0
    s_end   = 0
    t_start = 0
    t_end   = 0
    opcodes = []
    for op in alignment:
        if op[0] == "D": # Deletion
                s_end += 1
        elif op[0] == "I": # Insertion
                t_end += 1
        elif op[0].startswith("T"): # Transposition
                # Extract number of elements involved (default is 2)
                k = int(op[1:] or 2)
                s_end += k
                t_end += k
        else: # Match or substitution
                s_end += 1
                t_end += 1
        # Save
        opcodes.append((op, s_start, s_end, t_start, t_end))
        # Start from here
        s_start = s_end
        t_start = t_end
    return opcodes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号