【发布时间】:2019-11-06 17:08:44
【问题描述】:
我正在尝试在给定的文本中搜索指定的单词列表。代码非常简单。
# put the words you want to match into a list
word_list = ["eat", "car", "house", "pick up", "child"]
# get input text from the user
user_prompt = input("Please enter some text: ")
# loop over each word in word_list and check if it is a substring of user_prompt
for word in word_list:
if word in user_prompt:
print("{} is in the user string".format(word))
问题是,当我输入以下文本时:“我在车上接我的孩子,他们吃了一些梨。” 它与单词不匹配 “pick up " 或 "吃"。我想这是因为在文本中它们是过去形式,而在单词表中它们是不定式。因此,它只会搜索完全匹配,不会考虑变形(动词形式、不规则动词等)。
有没有一种方法可以搜索文本以匹配单词列表中的单词而不考虑变形? 谢谢!
【问题讨论】:
-
吃/吃会很困难,换句话说stemming应该可以工作。
-
第二个用于词干化/词形还原。对于诸如吃/吃之类的时态转换,您可能需要使用常用词词典来替换文本,或者使用可以自动执行此操作的 NLP 包