def test_empty(self): mock_atom_index = mock.Mock() mock_atom_index.query.return_value = [] mock_grammar = mock.Mock() mock_grammar.get_atoms.return_value = [] mock_grammar.get_phrase_patterns.return_value = [] mock_grammar.get_query_patterns.return_value = [] result = interpret(mock_atom_index, mock_grammar, 'This is the way?') self.assertEqual(result, []) mock_atom_index.query.assert_called_with('This is the way')
def search(): query = request.query.q queries = interpret(atom_index, grammar, query) results = [] for query in queries: results.append({ 'url' : '/results?sql=' + urllib.quote(query.get_sql()) + '&english=' + urllib.quote(query.get_english()), 'short' : query.get_english_highlighted(), 'sql' : query.get_sql() }) return { 'results' : results }
def test_who_won(self): user_input = 'athletes most golds 2012' user_intent = 'Which athletes won the most golds in 2012?' results = interpret(self.atom_index, grammar, user_input) self.assertNotEqual(results, []) english_results = map(lambda r: r.get_english(), results) self.assertTrue(user_intent in english_results) sql_results = map(lambda r: r.get_sql(), results) data_results = map(self.db.query, sql_results) print map(lambda dr: dr[1], data_results) self.assertTrue(('Manster Bones', 2) in map(lambda dr: dr[1], data_results))
def test_no_dupes(self): results = interpret(self.atom_index, grammar, 'Manster Bones') english_results = map(lambda q: q.get_english(), results) self.assertEqual(len(english_results), len(list(set(english_results))))
def test_what_sports(self): user_input = 'what sports were contested?' results = interpret(self.atom_index, grammar, user_input) self.assertNotEqual(results, []) data_results = self.db.query(results[0].get_sql())
def test_how_many(self): user_input = 'how many silvers did Manster Bones win' results = interpret(self.atom_index, grammar, user_input) self.assertNotEqual(results, [])
def test_empty(self): result = interpret(self.atom_index, grammar, '') self.assertEqual(result, [])