api.py 文件源码

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

项目:iqra-api 作者: Crescent-Labs 项目源码 文件源码
def checkForWordInQuran(value):
    wordMatch = dbGet(models.QuranWord, value)
    if wordMatch:
        return wordMatch.text
    else:
        # The original word is not in the Quran so we try alfanous' suggestions
        wordSuggestionList = []
        wordSuggestions = alfanous.do({
            "action": "suggest", "query": value
        })["suggest"]
        for word in wordSuggestions:
            for suggestion in wordSuggestions[word]:
                wordMatch = dbGet(models.QuranWord, value)
                if wordMatch:
                    wordSuggestionList.append(wordMatch.text)
        if len(wordSuggestionList) > 1:
            topRatioValue = 0
            topSuggestion = ""
            while len(wordSuggestionList) > 0:
                suggestion = wordSuggestionList.pop(0)
                suggestionRatio = ratio(value, suggestion)
                if suggestionRatio > topRatioValue:
                    topRatioValue = suggestionRatio
                    topSuggestion = suggestion
            return topSuggestion
        elif len(wordSuggestionList) == 1:
            return wordSuggestionList[0]
        else:
            return None


# Takes in a query and checks if any part of it is in the Quran
# Return the part in the Quran if one is found, otherwise it returns None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号