我正在使用Flask/python3.7
进行一个项目,我无法提供一个好的用户输入,这可以从media wiki API获得具体的答案
我试图创建一个stopWords
文件,但这还不足以让用户提出的问题变得清晰,得到一个好的答案,并得到用户期望的数据
下面是我用来解决这个问题的两种方法
def __init__(self, ask):
self.ask = ask
self.stopwords = []
self.result = []
def ReadSW(self):
""" Method to creat a list of the words that
must be ignored to have a specific question """
with open('app/stopwords.txt', 'r') as my_words :
for line in my_words:
line = line.rstrip()
self.stopwords.append(line)
return self.stopwords
def SelectWord(self):
"""Select and filter the worlds we need from the user input"""
response = self.ask.split()
for elt in response:
if elt not in self.stopwords:
self.result.append(elt)
return ' '.join(self.result)
目前没有回答
相关问题 更多 >
编程相关推荐