예제 #1
0
 def test_questions_are_consulted_in_given_order(self):
     q1 = self.create_question(u'Tom', u'Pizza', 'Tom eats Pizza happily .')
     q2 = self.create_question(u'Tom', u'Cheese',
                               'Tom eats Cheese happily .')
     self.term = TerminalInterviewer([q1, q2], mock.MagicMock())
     self.term()
     self.assertEqual(self.mock_get_answer.call_count, 2)
     self.assertEqual(self.mock_get_answer.call_args_list,
                      [mock.call(q1[0]), mock.call(q2[0])])
예제 #2
0
 def test_user_can_say_he_is_tired_and_no_more_questions_are_shown(self):
     q1 = self.create_question(u'Tom', u'Pizza', 'Tom eats Pizza happily .')
     q2 = self.create_question(u'Tom', u'Cheese', 'Tom eats Cheese happily .')
     self.term = TerminalInterviewer([q1, q2], mock.MagicMock())
     self.mock_get_answer.side_effect = [self.term.RUN, self.term.YES]
     result = self.term()
     # after user says is tired, no more questions
     self.assertEqual(self.mock_get_answer.call_count, 1)
     self.assertIsNone(result)
예제 #3
0
 def test_custom_options_stop_execution_and_are_returned(self):
     CUSTOM = u'custom'
     q1 = self.create_question(u'Tom', u'Pizza', 'Tom eats Pizza happily .')
     q2 = self.create_question(u'Tom', u'Cheese', 'Tom eats Cheese happily .')
     self.term = TerminalInterviewer(
         [q1, q2], mock.MagicMock(),
         extra_options=[(CUSTOM, u'some explanation')])
     self.mock_get_answer.side_effect = [CUSTOM, self.term.YES]
     result = self.term()
     # after user picks custom option, no more questions, and returned option
     self.assertEqual(self.mock_get_answer.call_count, 1)
     self.assertEqual(result, CUSTOM)
예제 #4
0
 def test_YES_NO_answers_are_passed_with_callback_and_proceeds(self):
     q1 = self.create_question(u'Tom', u'Pizza', 'Tom eats Pizza happily .')
     q2 = self.create_question(u'Tom', u'Cheese', 'Tom eats Cheese happily .')
     callback = mock.MagicMock()
     self.term = TerminalInterviewer([q1, q2], callback)
     self.mock_get_answer.side_effect = [self.term.YES, self.term.NO]
     result = self.term()
     self.assertIsNone(result)
     self.assertEqual(callback.call_count, 2)
     self.assertEqual(
         callback.call_args_list,
         [mock.call(q1[0], True), mock.call(q2[0], False)])
예제 #5
0
 def test_user_is_confused_then_callback_is_not_invoken_but_next_question_goes(self):
     q1 = self.create_question(u'Tom', u'Cheese', 'Tom Cheese happily eats.')
     q2 = self.create_question(u'Tom', u'Pizza', 'Tom eats Pizza happily .')
     q3 = self.create_question(u'Tom', u'Cheese', 'Tom eats Cheese happily .')
     callback = mock.MagicMock()
     self.term = TerminalInterviewer([q1, q2, q3], callback)
     self.mock_get_answer.side_effect = [self.term.DONT_KNOW, self.term.YES,
                                         self.term.YES]
     result = self.term()
     self.assertEqual(callback.call_count, 2)
     self.assertEqual(
         callback.call_args_list,
         [mock.call(q2[0], True), mock.call(q3[0], True)])
     self.assertEqual(self.mock_get_answer.call_count, 3)
     self.assertIsNone(result)
예제 #6
0
    output_file = opts[u'<output_file>']
    gold_standard_file = opts[u'--gold']
    if gold_standard_file:
        gold_standard = Knowledge.load_from_csv(gold_standard_file)
    else:
        gold_standard = None

    p = BootstrappedIEPipeline(connection, seed_facts, gold_standard)

    logging.basicConfig(
        level=logging.DEBUG,
        format=u"%(asctime)s - %(name)s - %(levelname)s - %(message)s")

    STOP = u'STOP'

    p.start()  # blocking
    keep_looping = True
    while keep_looping:
        qs = list(p.questions_available())
        if not qs:
            keep_looping = False
        term = TerminalInterviewer(qs, p.add_answer,
                                   [(STOP, u'Stop execution ASAP')])
        result = term()
        if result == STOP:
            keep_looping = False
        else:
            p.force_process()
    facts = p.known_facts()  # profit
    facts.save_to_csv(output_file)
예제 #7
0
 def setUp(self):
     self.c1 = colorama.Fore.GREEN
     self.c2 = colorama.Fore.RED
     self.reset = colorama.Style.RESET_ALL
     self.term = TerminalInterviewer([], lambda x: x)