【发布时间】:2023-04-09 18:40:02
【问题描述】:
对于作业,我们手动使用停用词来返回没有它们的句子。但是,我们还必须删除句点、逗号、问号、标点符号,我不知道该怎么做,因为如果它附加到单词上,它就不会删除。这是我的代码。例如,如果我输入 prep_text('how was the game?') 它应该打印 'how was game'。没有问号或其他停用词。 (顺便说一句,停用词在代码中,我只是不知道如何将其放入此处的代码框中,哈哈:
my_stopwords = ['is', 'it', 'the', 'if', '.', 'Is', 'It', 'The', 'If']
def prep_text(sentence):
words = sentence.split(" ")
words_filtered= [word for word in words if not word in my_stopwords]
return (" ").join(words_filtered)
【问题讨论】:
-
网上有很多 NLP 教程,如果你用 Google 搜索如何为 NLP 准备数据,你肯定会看到关于如何做到这一点的整篇文章。
-
他想让我们用手动方法来做,但它仍然没有真正解释我如何删除问号之类的东西。
-
这能回答你的问题吗? Best way to strip punctuation from a string
-
我希望如此。但它并没有真正说明我需要如何修复我的代码。
标签: python list performance python-3.8 stop-words