序列相似性比对(1)

序列的相似索引和相似度计算

直接代码:

 def seq_match_pattern_2(self, list_char, list_char_other):
        """基于字符序列的比对
        @:param list_char 对比序列1
        @:param list_char_other 对比序列2
        """
        d = difflib.Differ()
        diff = d.compare(list_char, list_char_other)
        for ii in diff:
            print(ii)
        pass
        #获取编辑距离相似文本
        diff = difflib.get_close_matches(list_char,["你是谁", "你是谁呢", "你还怕谁", "我害怕", "我怕怕"])
        print(diff)
        #lambda表达式是不需要考虑的字符
        diff = difflib.SequenceMatcher(lambda x : x == " ",list_char, list_char_other )
        s = diff.ratio()
        print(s)

猜你喜欢

转载自blog.csdn.net/cyinfi/article/details/88047353
今日推荐