示例#1
0
 def answer_questions(self, questions):
   """
   Answers questions given a list of question objects.
   """
   for question in questions:
     answers = get_answers(self.es_question_host, self.es_question_index,
                           self.es_question_type, question, 10,
                           self.query_function)
     response = self.generate_response_string(answers)
     if response:
       self.piazza.post_followup(self.course_id, response, cid=question['cid'])
示例#2
0
                      default='test_answers')
  parser.add_argument('--query_function',
                      help='The query function to search for matches with.',
                      required=True)
  args = parser.parse_args()

  test_iterator = ElasticsearchIterator(
      [args.es_test_question_host], args.es_test_question_index,
      args.es_test_question_type)

  dest_es = Elasticsearch([args.es_dest_host])

  current_doc = test_iterator.next()
  while current_doc is not None:
    answer_pair = get_answers([args.es_question_host], args.es_question_index,
                              args.es_question_type, current_doc, 1,
                              query_functions[args.query_function])
    answer_doc = {
        'answer_id': answer_pair[0][0],
        'answer': answer_pair[0][1],
        'c_id': current_doc['c_id']
    }

    # check if the question answer pair has already been completed by a
    # previous version.
    query_string = """
    {
      "query": {
        "bool": {
          "must": [
            {