首页 > 其他 > 详细

simhash

时间:2018-11-16 10:11:58      阅读:172      评论:0      收藏:0      [点我收藏+]
#-*- coding: utf-8 -*-

import jieba.analyse
import numpy as np

def word_hash(t, w):
if int(t)==1:
return w
else:
return -w
def content_hash(t):
if float(t)<=0:
return ‘0‘
else:
return ‘1‘


def simhash(content):

tags = jieba.analyse.extract_tags(content, topK=100, withWeight=True)

hash_init = np.zeros(64)

for t, w in tags:
print t, w

hash_str = str(bin(hash(t)).replace(‘0b‘, ‘‘).replace(‘-‘, ‘‘).zfill(64)[-64:])

hash_str_deal = map(lambda x: word_hash(x, w), hash_str)

hash_init = hash_str_deal + hash_init
return ‘‘.join(map(lambda x: content_hash(x), hash_init))

def similarity(hash1, hash2):
pass
======================================================================================================================================================================
#-*- coding: utf-8 -*-

from simhash import simhash

if __name__ == ‘__main__‘:
content1 = ‘而在感怀的热潮过后,关于人人网以及人人直播的价值讨论,开始浮出水面。‘
content2 = ‘陈一舟还认为,相比年轻创业者,老江湖更适合做产业互联网。‘

hash1 = simhash(content1)
hash2 = simhash(content2)

print len(filter(lambda x: x[0]==x[1], zip(hash1, hash2)))/64.0

simhash

原文:https://www.cnblogs.com/kayy/p/9967494.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!