coreMFAPCount.py 文件源码

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

项目:nlpcc2016 作者: huangxiangzhou 项目源码 文件源码
def calScoreSub(self, countCharDict):

        distance = Levenshtein.ratio
        q = self.qRaw
        scoreSub = 0

        sub = ''

        if type(self.sub) == str:

            sub = self.sub
            subSplit = sub.split(' ')
            if sub in q:   
                for w in subSplit:
                    if w in countCharDict:
                        scoreSub += 1/(countCharDict[w] + 1)
                    else:
                        scoreSub += 1
            else:
                subSet = set(subSplit)
                qSet = set(q.split(' '))
                for w in (subSet & qSet):
                    if w in countCharDict:
                        scoreSub += 1/(countCharDict[w] + 1)
                    else:
                        scoreSub += 1
                if len(subSet) != 0:
                    scoreSub = scoreSub/len(subSet)


        if type(self.sub) == list:
            for s in self.sub[0]:
                sub += s + ' '
            sub = sub.strip()


        if type(self.sub) == list:
            if len(self.sub[0]) == len(self.sub[1]):
                lenSub = len(self.sub[0])
                for i in range(lenSub):
                    w = self.sub[0][i]
                    wC = self.sub[1][i]
                    if w in countCharDict:
                        scoreSub += 1/(countCharDict[w] + 1)*distance(w,wC)
                    else:
                        scoreSub += 1*distance(w,wC)
                scoreSub = scoreSub / lenSub

            else:
                subIntersaction = set(self.sub[0]) & set(self.sub[1])
                scoreSub = len(subIntersaction) / len(set(self.sub[0]) | set(self.sub[1]))



        self.scoreSub = scoreSub

        return scoreSub
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号