def test_26(self): logger.info( '\n######################## test 1.26 ##############################' ) utterance = "shelf." logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup([], ['it'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['shelf'], [], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_06(self): logger.info('\n######################## test 1.6 ##############################') utterance = "the bottle on the table" logger.info('Add adverbial as a relative this case is only for SUCCESS') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = Nominal_Group(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = Nominal_Group(['the'], ['bottle'], [], [], [Sentence('relative', 'which', [], [Verbal_Group(['be'], [], 'present simple', [], [Indirect_Complement(['on'], [ Nominal_Group(['the'], ['table'], [], [], [])])], [], [], 'affirmative', [])])]) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_08(self): logger.info( '\n######################## test 1.8 ##############################' ) utterance = "sorry. I mean the green one" logger.info('Correct adjective this case is only for FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['green', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_04(self): logger.info( '\n######################## test 1.4 ##############################' ) utterance = "the blue one. I mean" logger.info('Add adjectives if we have FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['blue', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_10(self): logger.info( '\n######################## test 1.10 ##############################' ) utterance = "sorry. I want to say this plush" logger.info('Correct noun this case is only for FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bear'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['this'], ['plush'], [], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_23(self): logger.info('\n######################## test 1.23 ##############################') utterance = "no. It is not on the table but on the shelf." logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [], [Sentence('relative', 'which', [], [VerbalGroup(['be'], [], 'present simple', [], [IndirectComplement(['on'], [ NominalGroup(['the'], ['shelf'], [], [], [])])], [], [], 'affirmative', [])])]) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_14(self): logger.info( '\n######################## test 1.14 ##############################' ) utterance = "I mean the bottle of Jido" logger.info('Add noun complement if we have FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [NominalGroup([], ['Jido'], [], [], [])], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_12(self): logger.info( '\n######################## test 1.12 ##############################' ) utterance = "No. He means the one which he bought yesterday." logger.info('Add relative if we have SUCCESS') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [], [ Sentence('relative', 'which', [NominalGroup([], ['he'], [], [], [])], [ VerbalGroup(['buy'], [], 'past simple', [ NominalGroup(['the'], ['bottle'], [], [], []) ], [], [], ['yesterday'], 'affirmative', []) ]) ]) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_12(self): logger.info('\n######################## test 1.12 ##############################') utterance = "No. He means the one which he bought yesterday." logger.info('Add relative if we have SUCCESS') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [], [Sentence('relative', 'which', [NominalGroup([], ['he'], [], [], [])], [VerbalGroup(['buy'], [], 'past simple', [NominalGroup(['the'], ['bottle'], [], [], [])], [], [], ['yesterday'], 'affirmative', [])])]) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_15(self): logger.info( '\n######################## test 1.15 ##############################' ) utterance = "Sorry. it is the best one" logger.info('Case of SUCCESS used with FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['best', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_17(self): logger.info( '\n######################## test 1.17 ##############################' ) utterance = "no. The bottle is not blue. It is red" logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [['blue', []]], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['red', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_22(self): logger.info( '\n######################## test 1.22 ##############################' ) utterance = "This one is not the bottle of my uncle but it is the bottle of my brother." logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup( ['the'], ['bottle'], [], [NominalGroup(['my'], ['uncle'], [], [], [])], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [NominalGroup(['my'], ['brother'], [], [], [])], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_23(self): logger.info( '\n######################## test 1.23 ##############################' ) utterance = "no. It is not on the table but on the shelf." logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [], [ Sentence('relative', 'which', [], [ VerbalGroup(['be'], [], 'present simple', [], [ IndirectComplement( ['on'], [NominalGroup(['the'], ['shelf'], [], [], [])]) ], [], [], 'affirmative', []) ]) ]) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_01(self): logger.info( '\n######################## test 1.1 ##############################' ) utterance = "sorry" logger.info('It is an empty test with SUCCESS') logger.info('The speaker said :') logger.info(utterance) logger.info( '#################################################################\n' ) sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def preprocess(self, nl_input, active_sentence=None): #Return active_sentence if not empty, possibly send from Dialog. if active_sentence: return [active_sentence] #Do all basic replacements (like capitals, n't -> not, etc) + splits in several #sentence with points. sentence_list = preprocessing.process_sentence(nl_input) return sentence_list
def test_08(self): """ ## TEST 8 """ print('') print('######################## test 1.8 ##############################') utterance = "Using 'it' so we have to replace automatically" print('The object of our test is this utterance :') print(utterance) print('#################################################################') print('') list_gr = recover_nominal_group_list(sentences) print('The list of the nominal group') for i in list_gr: print((str(i))) print('#####################################') print('') print('the nominal group that we have to change') nominal_group_struc = NominalGroup(['this'], [], [], [], []) print((str(nominal_group_struc))) print('#####################################') print('After the first replacement') gr = first_replacement(list_gr, nominal_group_struc) print("the id of the nominal group: ", gr.id) print((str(gr))) print('') result = NominalGroup(['the'], ['table'], [], [], []) result_test = compare_nominal_group([gr], [result]) self.assertEquals(result_test, 0) print('#####################################') utterance = "no. I mean the blue bottle." print('The speaker said :') print(utterance) print('') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) print('#####################################') nominal_group_struc = replacement(class_list, nominal_group_struc, list_gr[1:], gr) print('the nominal group after processing') print((str(nominal_group_struc[0]))) print('the flag') print((str(nominal_group_struc[1]))) result = NominalGroup(['the'], ['bottle'], [['blue', []]], [], []) result_test = compare_nominal_group([nominal_group_struc[0]], [result]) self.assertEquals(result_test, 0)
def test_17(self): logger.info('\n######################## test 1.17 ##############################') utterance = "no. The bottle is not blue. It is red" logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [['blue', []]], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['red', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_22(self): logger.info('\n######################## test 1.22 ##############################') utterance = "This one is not the bottle of my uncle but it is the bottle of my brother." logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [NominalGroup(['my'], ['uncle'], [], [], [])], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [NominalGroup(['my'], ['brother'], [], [], [])], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_26(self): logger.info('\n######################## test 1.26 ##############################') utterance = "shelf." logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup([], ['it'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['shelf'], [], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_16(self): logger.info('\n######################## test 1.16 ##############################') utterance = "He means that he want the bottle of Jido" logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = Nominal_Group(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = Nominal_Group(['the'], ['bottle'], [], [Nominal_Group([], ['Jido'], [], [], [])], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_01(self): logger.info('\n######################## test 1.1 ##############################') utterance = "sorry" logger.info('It is an empty test with SUCCESS') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_08(self): logger.info('\n######################## test 1.8 ##############################') utterance = "sorry. I mean the green one" logger.info('Correct adjective this case is only for FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['green', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_10(self): logger.info('\n######################## test 1.10 ##############################') utterance = "sorry. I want to say this plush" logger.info('Correct noun this case is only for FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bear'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['this'], ['plush'], [], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_13(self): logger.info('\n######################## test 1.13 ##############################') utterance = "I mean the bottle of Jido" logger.info('Add noun complement if we have SUCCESS') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'SUCCESS' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [], [NominalGroup([], ['Jido'], [], [], [])], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_15(self): logger.info('\n######################## test 1.15 ##############################') utterance = "Sorry. it is the best one" logger.info('Case of SUCCESS used with FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['best', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def test_04(self): logger.info('\n######################## test 1.4 ##############################') utterance = "the blue one. I mean" logger.info('Add adjectives if we have FAILURE') logger.info('The speaker said :') logger.info(utterance) logger.info('#################################################################\n') sentence_list = preprocessing.process_sentence(utterance) class_list = analyse_sentence.sentences_analyzer(sentence_list) flag = 'FAILURE' nom_gr_struc = NominalGroup(['the'], ['bottle'], [], [], []) logger.info('the nominal group of the last out put') logger.info(str(nom_gr_struc)) nom_gr_struc = nominal_group_remerge(class_list, flag, nom_gr_struc) logger.info('the nominal group after processing') logger.info(str(nom_gr_struc)) rslt = NominalGroup(['the'], ['bottle'], [['blue', []]], [], []) self.assertTrue(is_equal(nom_gr_struc, rslt))
def check_valid(self, utterance, valid=True): sentence_list = preprocessing.process_sentence(utterance) sentences = analyse_sentence.sentences_analyzer(sentence_list) for s in sentences: self.assertTrue(s.isvalid() == valid)