api.py 文件源码

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

项目:iqra-api 作者: Crescent-Labs 项目源码 文件源码
def mostCommon(spoken, lst, threshold):
    highestCountItem = max(lst, key=lst.count)
    highestCount = lst.count(highestCountItem)
    contenders = []
    for item in lst:
        if (lst.count(item) == highestCount) and (item not in contenders):
            contenders.append(item)
    if len(contenders) > 1:
        print "\nContending"
        bestMatch = [None, 0]
        for ayah in contenders:
            score = ratio(spoken, ayah)
            print ayah
            print score
            if score > threshold and score > bestMatch[1]:
                bestMatch = [ayah, score]
        return bestMatch[0]
    elif ratio(spoken, highestCountItem) > threshold:
        return highestCountItem
    else:
        return None


# Takes in a query and list of matches
# Returns the match with the highest similarity to the query
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号