def quantity_ques(analysis): """ This function verbalises a question about quantity Input=class sentence Output=sentence """ #init phrase = [] #We have to memorise the verb verb = other_functions.list_rebuilding(analysis.sv[0].vrb_main[0]) if analysis.sv: #First case : aim is the subject with verb be if analysis.sv[0].d_obj == [] and (verb[0] == 'be' or (len(verb) > 1 and verb[1] == 'be')): phrase = statement(analysis) return ['how', 'much'] + phrase[1:len(phrase) - 1] + ['?'] #Second case : aim is the subject without verb be elif not analysis.sv[0].d_obj: return ['how', 'much'] + y_o_question(analysis) #Third case : as yes no question without the direct complement else: subject = element_rebuilding.nom_struc_rebuilding(analysis.sn) #Same processing with yes no question phrase = element_rebuilding.vrb_ques_rebuilding(analysis.sv[0].vrb_tense, analysis.sv[0].vrb_main, analysis.sv[0].vrb_adv, analysis.sn, analysis.sv[0].state, analysis.aim) for x in analysis.sv[0].i_cmpl: phrase = phrase + element_rebuilding.indirect_compl_rebuilding(x) phrase = phrase + analysis.sv[0].advrb flag = 0 for j in ResourcePool().verb_need_to: if analysis.sv[0].vrb_main[0] == j: flag = 1 for k in analysis.sv[0].sv_sec: phrase = element_rebuilding.scd_vrb_rebuilding(k, phrase, flag) for s in analysis.sv[0].vrb_sub_sentence: phrase = phrase + sub_process(s) #processing of the state if analysis.sv[0].state == VerbalGroup.negative: phrase = phrase[0:2] + subject + phrase[2:] else: phrase = [phrase[0]] + subject + phrase[1:] return ['how', 'much'] + analysis.sv[0].d_obj[0].noun + phrase + ['?']
def statement(analysis): """ verbalises a statment Input=class sentence Output=sentence """ #Recovering the subject phrase = element_rebuilding.nom_struc_rebuilding(analysis.sn) if not phrase: return [] if analysis.sv: #Recovering the end of the sentence phrase = element_rebuilding.end_statement_rebuilding(phrase, analysis.sv, analysis.sn, analysis.data_type, analysis.aim) #Recovering subsentences for s in analysis.sv[0].vrb_sub_sentence: phrase = phrase + sub_process(s) #Eliminate redundancies if there are phrase = other_functions.eliminate_redundancy(phrase) #If it is a relative form if analysis.data_type == RELATIVE or analysis.data_type.startswith(SUBSENTENCE): if phrase[len(phrase) - 1][len(phrase[len(phrase) - 1]) - 1] != ',': phrase[len(phrase) - 1] += ',' return phrase if analysis.data_type == W_QUESTION: return phrase + ['?'] #To take of all not useless comma while phrase[len(phrase) - 1][len(phrase[len(phrase) - 1]) - 1] == ',': phrase[len(phrase) - 1] = phrase[len(phrase) - 1][:len(phrase[len(phrase) - 1]) - 1] return phrase + ['.']
def y_o_question(analysis): """ This function verbalises an yes or no question Input=class sentence Output=sentence """ #init phrase = [] #Recovering the subject subject = element_rebuilding.nom_struc_rebuilding(analysis.sn) if analysis.sv: #Recovering the end of the sentence phrase = element_rebuilding.end_question_rebuilding(phrase, analysis.sv, analysis.sn, analysis.aim) #We need special processing to find the position of the subject if analysis.sv[0].state == VerbalGroup.negative: phrase = phrase[0:2] + subject + phrase[2:] else: phrase = [phrase[0]] + subject + phrase[1:] #Recovering subsentences for s in analysis.sv[0].vrb_sub_sentence: phrase = phrase + sub_process(s) else: phrase = subject #Eliminate redundancies if there are phrase = other_functions.eliminate_redundancy(phrase) #If it is a question about the origin if analysis.aim == 'origin': return phrase + ['from'] + ['?'] return phrase + ['?']