コード例 #1
0
def imperative(analysis):
    """
    verbalises an imperative                                           
    Input=class sentence                              Output=sentence                
    """

    #init
    phrase = []

    if analysis.sv:
        #Recovering the basic part 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 analysis.data_type == RELATIVE:
        if phrase[len(phrase) - 1][len(phrase[len(phrase) - 1]) - 1] != ',':
            phrase[len(phrase) - 1] += ','
        return phrase

    return phrase + ['.']
コード例 #2
0
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 + ['.']
コード例 #3
0
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 + ['?']