maxSim.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:easy-expression 作者: earlybackhome 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号