Я работаю над проектом с Flask/python3.7
, и я заблокирован для создания хорошего пользовательского ввода, который может быть чистым, чтобы получить конкретный ответ из медиа-вики 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)