【发布时间】:2013-12-16 13:46:18
【问题描述】:
我在创建从字符串输入中删除停用词的代码时遇到问题。目前,这是我的代码:
stopWords = [ "a", "i", "it", "am", "at", "on", "in", "to", "too", "very", \
"of", "from", "here", "even", "the", "but", "and", "is", "my", \
"them", "then", "this", "that", "than", "though", "so", "are" ]
stemEndings = [ "-s", "-es", "-ed", "-er", "-ly" "-ing", "-'s", "-s'" ]
punctuation = [ ".", ",", ":", ";", "!", "?" ]
line = raw_input ("Type in lines, finish with a . at start of line only:")
while line != ".":
def remove_punctuation(input): #removes punctuation from input
output = ""
text= 0
while text<=(len(input)-1) :
if input[text] not in punctuation:
output=output + input[text]
text+=1
return output
newline= remove_punctuation(line)
newline= newline.lower()
可以添加什么代码来根据上面的 stopWords 列表从字符串中删除 stopWords?提前谢谢你。
【问题讨论】: