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
评论列表
文章目录