Skip to content

Commit

Permalink
Preserve quotes in question search strings
Browse files Browse the repository at this point in the history
  • Loading branch information
zachd committed Jul 25, 2018
1 parent cadb5bf commit d2bf35a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def build_queries(question_text, answers):

def build_urls(self, question_text, answers):
""" build URLs with search queries """
parsed_question_text = get_raw_words(
question_text.replace(' NOT ', ' ').replace(' NEVER ', ' ')
, lowercase=False)
queries = self.build_queries('{}?'.format(parsed_question_text), answers)
parsed_question_text = question_text.replace(' NOT ', ' ').replace(' NEVER ', ' ')
parsed_question_text = re.sub(r'[^A-Za-z0-9\“\”\? ]', '', parsed_question_text).replace(' ', ' ')
queries = self.build_queries(parsed_question_text, answers)
return [self.service_url.format(quote_plus(query)) for query in queries]

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def get_significant_words(question_words):
return list(filter(lambda word: word not in our_stopwords, question_words.split(' ')))


def get_raw_words(data, lowercase=True):
def get_raw_words(data):
""" Extract raw words from data """
data = re.sub(r'[^A-Za-z0-9 ]', '', data).replace(' and ', ' ').strip()
words = data.replace(' ', ' ')
return words.lower() if lowercase else words
words = data.replace(' ', ' ').lower()
return words

0 comments on commit d2bf35a

Please sign in to comment.