最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

論文查重python文本相似性計(jì)算simhash源碼

 更新時(shí)間:2022年02月10日 14:26:07   作者:別None了  
這篇文章主要為大家介紹了python文本相似性計(jì)算simhash源碼來實(shí)現(xiàn)論文的查重,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步

場(chǎng)景:

1.計(jì)算SimHash值,及Hamming距離。
2.SimHash適用于較長文本(大于三五百字)的相似性比較,文本越短誤判率越高。

Python實(shí)現(xiàn):

代碼如下

# -*- encoding:utf-8 -*-
import math
import jieba
import jieba.analyse
class SimHash(object):
    def getBinStr(self, source):
        if source == "":
            return 0
        else:
            x = ord(source[0]) << 7
            m = 1000003
            mask = 2 ** 128 - 1
            for c in source:
                x = ((x * m) ^ ord(c)) & mask
            x ^= len(source)
            if x == -1:
                x = -2
            x = bin(x).replace('0b', '').zfill(64)[-64:]
            return str(x)
    def getWeight(self, source):
        return ord(source)
    def unwrap_weight(self, arr):
        ret = ""
        for item in arr:
            tmp = 0
            if int(item) > 0:
                tmp = 1
            ret += str(tmp)
        return ret
    def sim_hash(self, rawstr):
        seg = jieba.cut(rawstr)
        keywords = jieba.analyse.extract_tags("|".join(seg), topK=100, withWeight=True)
        ret = []
        for keyword, weight in keywords:
            binstr = self.getBinStr(keyword)
            keylist = []
            for c in binstr:
                weight = math.ceil(weight)
                if c == "1":
                    keylist.append(int(weight))
                else:
                    keylist.append(-int(weight))
            ret.append(keylist)
        # 降維
        rows = len(ret)
        cols = len(ret[0])
        result = []
        for i in range(cols):
            tmp = 0
            for j in range(rows):
                tmp += int(ret[j][i])
            if tmp > 0:
                tmp = "1"
            elif tmp <= 0:
                tmp = "0"
            result.append(tmp)
        return "".join(result)
    def distince(self, hashstr1, hashstr2):
        length = 0
        for index, char in enumerate(hashstr1):
            if char == hashstr2[index]:
                continue
            else:
                length += 1
        return length
if __name__ == "__main__":
    simhash = SimHash()
    str1 = '咱哥倆誰跟誰啊'
    str2 = '咱們倆誰跟誰啊'
    hash1 = simhash.sim_hash(str1)
    print(hash1)
    hash2 = simhash.sim_hash(str2)
    distince = simhash.distince(hash1, hash2)
    value = 5
    print("simhash", distince, "距離:", value, "是否相似:", distince<=value)

以上就是論文查重python文本相似性計(jì)算simhash源碼的詳細(xì)內(nèi)容,更多關(guān)于python文本相似性計(jì)算simhash的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

河北省| 中宁县| 石景山区| 虹口区| 黔南| 济阳县| 太谷县| 凉城县| 灵石县| 乌兰察布市| 四子王旗| 榕江县| 荔波县| 囊谦县| 伊川县| 唐河县| 杭州市| 徐闻县| 含山县| 峡江县| 杂多县| 贡嘎县| 伊春市| 丽江市| 阿鲁科尔沁旗| 潞西市| 峨边| 浦县| 平定县| 常山县| 卫辉市| 麻阳| 邳州市| 临洮县| 积石山| 泰和县| 凉城县| 阿鲁科尔沁旗| 银川市| 大兴区| 邵武市|