def extract_keywords(sentence, keywords):
# check if there are keywords for the sentence language
language = sentence['Language']
if language in keywords:
languageKeywords = keywords[language]
keywordMatches = []
if languageKeywords != None:
message = sentence['Sentence']
# tokenize the sentence
for keyword in sorted(languageKeywords):
keywordRegex = languageKeywords[keyword]
if keywordRegex.search(message):
# if match, add keyword canonical form to list
keywordMatches.append(keyword)
sentence['Keywords'] = keywordMatches
return sentence
评论列表
文章目录