simhash
Posted kayy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了simhash相关的知识,希望对你有一定的参考价值。
#-*- 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的主要内容,如果未能解决你的问题,请参考以下文章