标签:pre sim 创业 from weight name zip hash ash
#-*- 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
标签:pre sim 创业 from weight name zip hash ash
原文地址:https://www.cnblogs.com/kayy/p/9967494.html