def juziSim_vec(self, intxt, questionWordset, posWeight=None): # juziIn??????juziLi???????
if posWeight == None:
log.warning('there is no posWeight')
return 0
intxtSet = set(list(pseg.cut(intxt)))
if not len(intxtSet):
return 0
simWeight = 0
totalWeight = 0
for word, pos in intxtSet:
if word in self.vecmodel.wv.index2word:
wordPosWeight = posWeight.get(pos, 1)
totalWeight += wordPosWeight
wordMaxWeight = 0
for t in questionWordset:
# print(word, t)
tmp = self.vecmodel.wv.similarity(word, t)
if wordMaxWeight < tmp:
wordMaxWeight = tmp
simWeight += wordPosWeight * wordMaxWeight
if totalWeight == 0:
return 0
return simWeight/totalWeight
评论列表
文章目录