def w_question(analysis): """ verbalises a w_question Input=class sentence Output=sentence """ if analysis.sv: #Opinion is a what question so we have to make some changes if analysis.sv[0].vrb_main[0].endswith('like'): verb = analysis.sv[0].vrb_main[0] analysis.sv[0].vrb_main[0] = verb[:len(verb) - 4] + 'think+of' #processing as yes or no question phrase = y_o_question(analysis) #Specific processing for invitation if analysis.aim == 'invitation': return ['how', 'about'] + phrase[1:] #Specific processing for classification if analysis.aim.startswith('classification'): aim_question = other_functions.list_rebuilding(analysis.aim) return ['what', 'kind', 'of'] + aim_question[1:] + phrase #It is an how question if other_functions.is_an_adj(analysis.aim) == 1: return ['how'] + [analysis.aim] + phrase elif analysis.aim == 'manner': return ['how'] + phrase if analysis.aim == 'thing' or analysis.aim == 'situation' or analysis.aim == 'explication' or analysis.aim == 'opinion': return ['what'] + phrase return ['what'] + [analysis.aim] + phrase
def scd_vrb_rebuilding(sec_vrb, phrase, flg): """ recovers the part of the second verb Input=class sentence, phrase and a flag Output=phrase """ if flg == 1: phrase = phrase + sec_vrb.vrb_adv + other_functions.list_rebuilding( sec_vrb.vrb_main[0]) else: #Add this verb with 'to' phrase = phrase + [ 'to' ] + sec_vrb.vrb_adv + other_functions.list_rebuilding( sec_vrb.vrb_main[0]) #We add the direct and indirect complement if sec_vrb.i_cmpl != [] and sec_vrb.i_cmpl[0].prep != []: phrase = phrase + nom_struc_rebuilding(sec_vrb.d_obj) for x in sec_vrb.i_cmpl: phrase = phrase + indirect_compl_rebuilding(x) else: if sec_vrb.i_cmpl: phrase = phrase + indirect_compl_rebuilding(sec_vrb.i_cmpl[0]) phrase = phrase + nom_struc_rebuilding(sec_vrb.d_obj) #init x = 1 while x < len(sec_vrb.i_cmpl): phrase = phrase + indirect_compl_rebuilding(sec_vrb.i_cmpl[x]) x += 1 flag = 0 for j in ResourcePool().verb_need_to: if sec_vrb.vrb_main[0] == j: flag = 1 for z in sec_vrb.sv_sec: phrase = scd_vrb_rebuilding(z, phrase, flag) #We add the adverb of the sentence phrase = phrase + sec_vrb.advrb return phrase
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 scd_vrb_rebuilding(sec_vrb, phrase, flg): """ recovers the part of the second verb Input=class sentence, phrase and a flag Output=phrase """ if flg == 1: phrase = phrase + sec_vrb.vrb_adv + other_functions.list_rebuilding(sec_vrb.vrb_main[0]) else: #Add this verb with 'to' phrase = phrase + ['to'] + sec_vrb.vrb_adv + other_functions.list_rebuilding(sec_vrb.vrb_main[0]) #We add the direct and indirect complement if sec_vrb.i_cmpl != [] and sec_vrb.i_cmpl[0].prep != []: phrase = phrase + nom_struc_rebuilding(sec_vrb.d_obj) for x in sec_vrb.i_cmpl: phrase = phrase + indirect_compl_rebuilding(x) else: if sec_vrb.i_cmpl: phrase = phrase + indirect_compl_rebuilding(sec_vrb.i_cmpl[0]) phrase = phrase + nom_struc_rebuilding(sec_vrb.d_obj) #init x = 1 while x < len(sec_vrb.i_cmpl): phrase = phrase + indirect_compl_rebuilding(sec_vrb.i_cmpl[x]) x += 1 flag = 0 for j in ResourcePool().verb_need_to: if sec_vrb.vrb_main[0] == j: flag = 1 for z in sec_vrb.sv_sec: phrase = scd_vrb_rebuilding(z, phrase, flag) #We add the adverb of the sentence phrase = phrase + sec_vrb.advrb return phrase
def vrb_stat_rebuilding(tense, verb, adv, sn, state, type, aim): """ This function recovers the verb part of a statement Input=tense, verb in infinitive form, his state, the adverb and subject Output=verb part """ #init vrb_condjugated = [] #If verb is empty if not verb: return [] #We take of the '+' vrb = other_functions.list_rebuilding(verb[0]) #If there is modal => no processing for i in ResourcePool().modal: if i == vrb[0]: vrb_condjugated = vrb #No modal => normal processing if not vrb_condjugated: vrb_condjugated = conjugate_vrb(tense, vrb, sn, type, aim) elif tense == 'present passive' or tense == 'passive conditional': vrb_condjugated = [vrb[0]] + ['be'] + conjugate_vrb( 'present passive', vrb[1:], sn, '', aim)[1:] #Affirmative case if state == VerbalGroup.affirmative: if len(vrb) > 1: return [vrb_condjugated[0]] + adv + vrb_condjugated[1:] else: return adv + vrb_condjugated #Negative case : we have to use do or have or be or modal if there is no elif state == VerbalGroup.negative: if vrb[0] == 'be' or vrb[0] == 'do' or vrb[0] == 'have': return [vrb_condjugated[0]] + ['not'] + adv + vrb_condjugated[1:] if tense != 'present simple' and tense != 'past simple': return [vrb_condjugated[0]] + ['not'] + adv + vrb_condjugated[1:] for i in ResourcePool().modal: if i == vrb[0]: return [vrb_condjugated[0]] + ['not' ] + adv + vrb_condjugated[1:] return conjugate_vrb(tense, ['do'], sn, type, aim) + ['not' ] + adv + vrb
def vrb_ques_rebuilding(tense, verb, adverb, sn, state, aim): """ recovers the verb part of a question Input=tense, verb in infinitive form, his state, the adverb and subject Output=verb part """ #If verb is empty if not verb: return [] #We take of the '+' vrb = other_functions.list_rebuilding(verb[0]) #If there is be or have : it is ok if vrb[0] == 'be' or vrb[0] == 'have': vrb_condjugated = conjugate_vrb(tense, vrb, sn, '', aim) if state == VerbalGroup.negative: return [vrb_condjugated[0]] + ['not' ] + adverb + vrb_condjugated[1:] return [vrb_condjugated[0]] + adverb + vrb_condjugated[1:] #Modal also for i in ResourcePool().modal: if i == vrb[0]: if state == VerbalGroup.negative: if tense == 'present passive' or tense == 'passive conditional': return [vrb[0] ] + ['not'] + adverb + ['be'] + conjugate_vrb( 'present passive', vrb[1:], sn, '', aim)[1:] return [vrb[0]] + ['not'] + adverb + vrb[1:] elif tense == 'present passive' or tense == 'passive conditional': return [vrb[0]] + adverb + ['be'] + conjugate_vrb( 'present passive', vrb[1:], sn, '', aim)[1:] return [vrb[0]] + adverb + vrb[1:] if tense == 'present simple' or tense == 'past simple': #We need to add the auxilary aux = conjugate_vrb(tense, ['do'], sn, '', aim) if state == VerbalGroup.negative: return aux + ['not'] + adverb + vrb return aux + adverb + vrb else: vrb_condjugated = conjugate_vrb(tense, vrb, sn, '', aim) if state == VerbalGroup.negative: return [vrb_condjugated[0]] + ['not' ] + adverb + vrb_condjugated[1:] return [vrb_condjugated[0]] + adverb + vrb_condjugated[1:]
def vrb_stat_rebuilding(tense, verb, adv, sn, state, type, aim): """ This function recovers the verb part of a statement Input=tense, verb in infinitive form, his state, the adverb and subject Output=verb part """ #init vrb_condjugated = [] #If verb is empty if not verb: return [] #We take of the '+' vrb = other_functions.list_rebuilding(verb[0]) #If there is modal => no processing for i in ResourcePool().modal: if i == vrb[0]: vrb_condjugated = vrb #No modal => normal processing if not vrb_condjugated: vrb_condjugated = conjugate_vrb(tense, vrb, sn, type, aim) elif tense == 'present passive' or tense == 'passive conditional': vrb_condjugated = [vrb[0]] + ['be'] + conjugate_vrb('present passive', vrb[1:], sn, '', aim)[1:] #Affirmative case if state == Verbal_Group.affirmative: if len(vrb) > 1: return [vrb_condjugated[0]] + adv + vrb_condjugated[1:] else: return adv + vrb_condjugated #Negative case : we have to use do or have or be or modal if there is no elif state == Verbal_Group.negative: if vrb[0] == 'be' or vrb[0] == 'do' or vrb[0] == 'have': return [vrb_condjugated[0]] + ['not'] + adv + vrb_condjugated[1:] if tense != 'present simple' and tense != 'past simple': return [vrb_condjugated[0]] + ['not'] + adv + vrb_condjugated[1:] for i in ResourcePool().modal: if i == vrb[0]: return [vrb_condjugated[0]] + ['not'] + adv + vrb_condjugated[1:] return conjugate_vrb(tense, ['do'], sn, type, aim) + ['not'] + adv + vrb
def vrb_ques_rebuilding(tense, verb, adverb, sn, state, aim): """ recovers the verb part of a question Input=tense, verb in infinitive form, his state, the adverb and subject Output=verb part """ #If verb is empty if not verb: return [] #We take of the '+' vrb = other_functions.list_rebuilding(verb[0]) #If there is be or have : it is ok if vrb[0] == 'be' or vrb[0] == 'have': vrb_condjugated = conjugate_vrb(tense, vrb, sn, '', aim) if state == Verbal_Group.negative: return [vrb_condjugated[0]] + ['not'] + adverb + vrb_condjugated[1:] return [vrb_condjugated[0]] + adverb + vrb_condjugated[1:] #Modal also for i in ResourcePool().modal: if i == vrb[0]: if state == Verbal_Group.negative: if tense == 'present passive' or tense == 'passive conditional': return [vrb[0]] + ['not'] + adverb + ['be'] + conjugate_vrb('present passive', vrb[1:], sn, '', aim)[1:] return [vrb[0]] + ['not'] + adverb + vrb[1:] elif tense == 'present passive' or tense == 'passive conditional': return [vrb[0]] + adverb + ['be'] + conjugate_vrb('present passive', vrb[1:], sn, '', aim)[1:] return [vrb[0]] + adverb + vrb[1:] if tense == 'present simple' or tense == 'past simple': #We need to add the auxilary aux = conjugate_vrb(tense, ['do'], sn, '', aim) if state == Verbal_Group.negative: return aux + ['not'] + adverb + vrb return aux + adverb + vrb else: vrb_condjugated = conjugate_vrb(tense, vrb, sn, '', aim) if state == Verbal_Group.negative: return [vrb_condjugated[0]] + ['not'] + adverb + vrb_condjugated[1:] return [vrb_condjugated[0]] + adverb + vrb_condjugated[1:]