Exemplo n.º 1
0
def w_quest_which(type, request, sentence):
    """
    process which question                       
    Input=type of sentence, the sentence      Output=class Sentence                  
    """

    #We start by finding the nominal group
    gr = preprocessing.determination_nominal_group(sentence, 0, 'of')

    #If the nominal group contain just 2 elements
    if len(gr) == 2:
        return y_n_ques(type, sentence[1], sentence[2:])
    else:
        #After the first gr if there is no nominal group
        if not analyse_nominal_group.find_sn_pos(sentence, len(gr)):
            for i in ResourcePool().sentence_starts:
                #If just after we have an a auxiliary
                if sentence[len(gr)] == i[0] and i[1] == '3':
                    #With subject => it is a yes or no question form
                    if analyse_nominal_group.find_sn_pos(
                            sentence,
                            len(gr) + 1):
                        analysis = y_n_ques(type, request, sentence[len(gr):])
                        nominal_gr = other_sentence(type, request, gr)
                        analysis.sv[0].d_obj = nominal_gr.sn
                        return analysis
                #Else it is like a statement
            return other_sentence(type, request, sentence)

        #Else if not, the first nominal group is the subject
        else:
            analysis = other_sentence(type, request, sentence[len(gr):])
            nominal_gr = other_sentence(type, request, gr)
            analysis.sv[0].d_obj = nominal_gr.sn
            return analysis
Exemplo n.º 2
0
def create_nom_gr_and(sentence):
    """ 
    adds determinant after 'and' if there is                 
    Input=sentence                                  Output=sentence                      
    """
    #init
    i = 0

    while i < len(sentence):
        #If we have a nominal group
        nom_gr = analyse_nominal_group.find_sn_pos(sentence, i)
        i += len(nom_gr)

        while nom_gr != [] and i < len(sentence) and (sentence[i] == 'and' or sentence[i] == ';'):
            #If we have 'and'
            if sentence[i] == ';':
                sentence[i] = 'and'
                #We add the determinant
            sentence = sentence[:i + 1] + ['a'] + sentence[i + 1:]
            i += 1
            #We continue
            nom_gr = analyse_nominal_group.find_sn_pos(sentence, i)
            i += len(nom_gr)
        i += 1

    return sentence
Exemplo n.º 3
0
def create_nom_gr_and(sentence):
    """ 
    adds determinant after 'and' if there is                 
    Input=sentence                                  Output=sentence                      
    """
    #init
    i = 0

    while i < len(sentence):
        #If we have a nominal group
        nom_gr = analyse_nominal_group.find_sn_pos(sentence, i)
        i += len(nom_gr)

        while nom_gr != [] and i < len(sentence) and (sentence[i] == 'and'
                                                      or sentence[i] == ';'):
            #If we have 'and'
            if sentence[i] == ';':
                sentence[i] = 'and'
                #We add the determinant
            sentence = sentence[:i + 1] + ['a'] + sentence[i + 1:]
            i += 1
            #We continue
            nom_gr = analyse_nominal_group.find_sn_pos(sentence, i)
            i += len(nom_gr)
        i += 1

    return sentence
Exemplo n.º 4
0
def correct_i_compl(phrase, verb):
    """
    transform indirect complement to relative
    Input=sentence and verbal class         Output=sentence and verbal class         
    """

    #If we have a direct transitive verb
    if verb in ResourcePool().direct_transitive:

        #init
        x = 0
        while x < len(phrase):
            #If there is a proposal with an adverbial
            if x + 1 < len(phrase) and phrase[x] in ResourcePool().compelement_proposals:
                #If there is a plural
                phrase = phrase[:x] + analyse_nominal_group.find_plural(phrase[x:])

                if analyse_nominal_group.find_sn_pos(phrase, x + 1):
                    adverbial = analyse_nominal_group.find_sn_pos(phrase, x + 1)
                    begin_pos = x - 1

                    #We will find the subject of the relative
                    while not analyse_nominal_group.find_sn_pos(phrase, begin_pos):
                        begin_pos -= 1
                    nom_gr = analyse_nominal_group.find_sn_pos(phrase, begin_pos)

                    #If there nominal group is just before the adverbial
                    if begin_pos + len(nom_gr) == x:
                        phrase = phrase[:x] + ['which', 'is'] + [phrase[x]] + adverbial + [';'] + phrase[x + len(
                            adverbial) + 1:]
            x += 1
    return phrase
Exemplo n.º 5
0
def but(sentence):
    """
    find 'but' that need preporcessing
    Input=sentence                         Output=sentence
    """

    # init
    i = 0

    while i < len(sentence):
        # The 'but' must be between 2 nominal groups
        if sentence[i] == 'but':
            #After 'but' of subsentence we must have a nominal group (subject)
            scd_nominal_group = analyse_nominal_group.find_sn_pos(
                sentence, i + 1)
            if not scd_nominal_group:
                sentence[i] = ':but'
            else:

                #We have to find the first nominal group
                begin_pos = i - 1
                fst_nominal_group = analyse_nominal_group.find_sn_pos(
                    sentence, begin_pos)
                while fst_nominal_group == [] and begin_pos > 0:
                    begin_pos -= 1
                    fst_nominal_group = analyse_nominal_group.find_sn_pos(
                        sentence, begin_pos)
                #The case when but is between 2 adjectives and we have the same noun
                if fst_nominal_group[len(fst_nominal_group) - 1] == 'but':
                    sentence[i] = ':but'
        i += 1
    return sentence
Exemplo n.º 6
0
def but(sentence):
    """
    find 'but' that need preporcessing
    Input=sentence                         Output=sentence
    """

    #init
    i = 0

    while i < len(sentence):
        #The 'but' must be between 2 nominal groups
        if sentence[i] == 'but':
            #After 'but' of subsentence we must have a nominal group (subject)
            scd_nominal_group = analyse_nominal_group.find_sn_pos(sentence, i + 1)
            if not scd_nominal_group:
                sentence[i] = ':but'
            else:

                #We have to find the first nominal group
                begin_pos = i - 1
                fst_nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)
                while fst_nominal_group == [] and begin_pos > 0:
                    begin_pos -= 1
                    fst_nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)
                #The case when but is between 2 adjectives and we have the same noun
                if fst_nominal_group[len(fst_nominal_group) - 1] == 'but':
                    sentence[i] = ':but'
        i += 1
    return sentence
Exemplo n.º 7
0
def w_quest_which(type, request, sentence):
    """
    process which question                       
    Input=type of sentence, the sentence      Output=class Sentence                  
    """

    #We start by finding the nominal group
    gr = preprocessing.determination_nominal_group(sentence, 0, 'of')

    #If the nominal group contain just 2 elements
    if len(gr) == 2:
        return y_n_ques(type, sentence[1], sentence[2:])
    else:
        #After the first gr if there is no nominal group
        if not analyse_nominal_group.find_sn_pos(sentence, len(gr)):
            for i in ResourcePool().sentence_starts:
                #If just after we have an a auxiliary
                if sentence[len(gr)] == i[0] and i[1] == '3':
                    #With subject => it is a yes or no question form
                    if analyse_nominal_group.find_sn_pos(sentence, len(gr) + 1):
                        analysis = y_n_ques(type, request, sentence[len(gr):])
                        nominal_gr = other_sentence(type, request, gr)
                        analysis.sv[0].d_obj = nominal_gr.sn
                        return analysis
                #Else it is like a statement
            return other_sentence(type, request, sentence)

        #Else if not, the first nominal group is the subject
        else:
            analysis = other_sentence(type, request, sentence[len(gr):])
            nominal_gr = other_sentence(type, request, gr)
            analysis.sv[0].d_obj = nominal_gr.sn
            return analysis
Exemplo n.º 8
0
def move_prep(sentence):
    """
    put the preposition before the nominal group
    Input=sentence                              Output=sentence
    """

    # init
    i = 0

    while i < len(sentence):
        for p in ResourcePool().prep_change_place:

            # If there is a preposal
            if sentence[i] == p:
                position = i

                #If after preposition we have nominal group, it is for this nominal group
                if not analyse_nominal_group.find_sn_pos(sentence, i + 1):
                    #We have to find the nominal group just before
                    while not analyse_nominal_group.find_sn_pos(
                            sentence, position):
                        position -= 1
                    sentence = sentence[:position] + [
                        p
                    ] + sentence[position:i] + sentence[i + 1:]
        i += 1
    return sentence
Exemplo n.º 9
0
def possesion_form(sentence):
    """
    convert 's to possession form 'of'
    Input=sentence                                     Output=sentence
    """

    # init
    begin_pos = 0
    flag = 0

    # We will find the possession case
    while begin_pos < len(sentence):

        #We found a posssession case
        if sentence[begin_pos].endswith("'s") or sentence[begin_pos].endswith(
                "s'"):

            #We have to find the first nominal group
            nominal_group = analyse_nominal_group.find_sn_pos(
                sentence, begin_pos)

            #In the case of a propre name
            while nominal_group != [] and begin_pos != 0 and other_functions.find_cap_lettre(
                    nominal_group[0]) == 1:
                begin_pos -= 1

                nominal_group = analyse_nominal_group.find_sn_pos(
                    sentence, begin_pos)
                flag = 1

            #If flag=1 => there is a propre name so we haven't decrement the begin_pos
            if flag == 0:
                while not nominal_group:
                    begin_pos -= 1
                    nominal_group = analyse_nominal_group.find_sn_pos(
                        sentence, begin_pos)

            else:
                #If there is a propre name, begin_pos is wrong, we have to increment
                begin_pos += 1
                flag = 0

            #We recover the list of nominal groups
            nominal_group_list = find_nominal_group_list(sentence[begin_pos:])
            #We create the final phrase
            end_pos = nominal_group_list[len(nominal_group_list) -
                                         1] + begin_pos
            sentence = sentence[:begin_pos] + create_possession_claus(
                nominal_group_list[:len(nominal_group_list) -
                                   1]) + sentence[end_pos:]

            #We continue processing from the end's position
            begin_pos = end_pos

        else:
            begin_pos += 1

    return sentence
Exemplo n.º 10
0
def recover_ns(phrase, analysis, position):
    """ Retrieves the nominal structure of the sentence

    :param list phrase: sentence
    :param Sentence analysis: the instance of class sentence
    :param position: the position of the nominal structure

    :return: the class sentence and sentence
    """

    #init
    conjunction = 'AND'

    #We recover the first part of the subject
    sbj = analyse_nominal_group.find_sn_pos(phrase, position)

    #We loop until we don't have a nominal group
    while sbj:

        #We refine the nominal group if there is an error like ending with question mark
        sbj = analyse_nominal_group.refine_nom_gr(sbj)

        analysis.sn = analysis.sn + [fill_nom_gr(phrase, sbj, position, conjunction)]

        #We take off the nominal group
        phrase = analyse_nominal_group.take_off_nom_gr(phrase, sbj, phrase.index(sbj[0]))

        if phrase[0] in ResourcePool().relatives:
            end_pos_rel = other_functions.recover_end_pos_sub(phrase, ResourcePool().relatives)
            #We remove the relative part of the phrase
            phrase = phrase[end_pos_rel:]

        #If there is 'and', we need to duplicate the information
        if len(phrase) > position and (
                    phrase[position] == 'and' or phrase[position] == 'or' or phrase[position] == ':but'):

            #Reperform the 'and' or 'or' processing
            sbj = analyse_nominal_group.find_sn_pos(phrase[1:], position)

            #We process the 'or' like the 'and' and remove it
            if phrase[position] == 'or':
                conjunction = 'OR'
            elif phrase[position] == ':but':
                conjunction = 'BUT'
            else:
                conjunction = 'AND'
            phrase = phrase[1:]

            #This case is used by whose
            if not sbj:
                phrase = ['that'] + phrase
                sbj = analyse_nominal_group.find_sn_pos(phrase, position)

        else:
            sbj = []

    return phrase
Exemplo n.º 11
0
def recover_ns(phrase, analysis, position):
    """ Retrieves the nominal structure of the sentence

    :param list phrase: sentence
    :param Sentence analysis: the instance of class sentence
    :param position: the position of the nominal structure

    :return: the class sentence and sentence
    """

    #init
    conjunction = 'AND'

    #We recover the first part of the subject
    sbj = analyse_nominal_group.find_sn_pos(phrase, position)

    #We loop until we don't have a nominal group
    while sbj:

        #We refine the nominal group if there is an error like ending with question mark
        sbj = analyse_nominal_group.refine_nom_gr(sbj)

        analysis.sn = analysis.sn + [fill_nom_gr(phrase, sbj, position, conjunction)]

        #We take off the nominal group
        phrase = analyse_nominal_group.take_off_nom_gr(phrase, sbj, phrase.index(sbj[0]))

        if phrase[0] in ResourcePool().relatives:
            end_pos_rel = other_functions.recover_end_pos_sub(phrase, ResourcePool().relatives)
            #We remove the relative part of the phrase
            phrase = phrase[end_pos_rel:]

        #If there is 'and', we need to duplicate the information
        if len(phrase) > position and (
                    phrase[position] == 'and' or phrase[position] == 'or' or phrase[position] == ':but'):

            #Reperform the 'and' or 'or' processing
            sbj = analyse_nominal_group.find_sn_pos(phrase[1:], position)

            #We process the 'or' like the 'and' and remove it
            if phrase[position] == 'or':
                conjunction = 'OR'
            elif phrase[position] == ':but':
                conjunction = 'BUT'
            else:
                conjunction = 'AND'
            phrase = phrase[1:]

            #This case is used by whose
            if not sbj:
                phrase = ['that'] + phrase
                sbj = analyse_nominal_group.find_sn_pos(phrase, position)

        else:
            sbj = []

    return phrase
Exemplo n.º 12
0
def and_nominal_group_comma(sentence):
    """
    process the case when there is a comma between nominal groups
    Input=sentence                                     Output=sentence
    """

    #init
    i = 0
    flag = 2
    list_nominal_group = []

    #If we find ','
    while i < len(sentence):
        if sentence[i] == ',':
            nominal_group = determination_nominal_group(sentence, i + 1, 'of')
            end_pos = len(nominal_group) + i + 1

            #First we recover the all nominal groups preceded by ','
            while nominal_group != [] and sentence[end_pos] == ',':
                list_nominal_group = ['and'] + nominal_group
                nominal_group = determination_nominal_group(sentence, end_pos + 1, 'of')
                end_pos = len(nominal_group) + end_pos + 1
                #Flag still 2 because this stage is not compulsory
                flag = 2

            #We will find the last nominal group of this phrase
            if nominal_group != [] and sentence[end_pos] == 'and':
                list_nominal_group = list_nominal_group + ['and'] + nominal_group
                nominal_group = determination_nominal_group(sentence, end_pos + 1, 'of')
                end_pos = len(nominal_group) + end_pos + 1
                list_nominal_group = list_nominal_group + ['and'] + nominal_group
                #Flag will be 1 because this stage is compulsory
                flag -= 1

            #If flag=1 => we can have the and_nominal_group_comma case
            if flag == 1:
                #We have to find the first nominal group
                begin_pos = i - 1
                nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)
                while nominal_group == [] and begin_pos > 0:
                    begin_pos -= 1
                    nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)
                #If this nominal group preceded the first ',' => OK
                if nominal_group != [] and begin_pos + len(nominal_group) == i:
                    flag -= 1
                    list_nominal_group = nominal_group + list_nominal_group

            #We have an and_nominal_group_comma case
            if flag == 0:
                sentence = sentence[:begin_pos] + list_nominal_group + sentence[end_pos:]
                i = end_pos

        i += 1

    return sentence
Exemplo n.º 13
0
def conjunction_processing(sentence, cjt):
    """
    creates a nominal group before and after the 'or'
    Input=sentence and the conjunction                     Output=sentence
    """

    # init
    i = 0
    fst_nominal_group = []

    while i < len(sentence):

        if sentence[i] == cjt:
            # We have to find the first and the second nominal group in the sentence
            position = i
            #Until we find the first nominal group
            while position > 0 and fst_nominal_group == []:
                position -= 1
                fst_nominal_group = analyse_nominal_group.find_sn_pos(
                    sentence, position)

            if fst_nominal_group:

                #We will find the second nominal group
                scd_nominal_group = analyse_nominal_group.find_sn_pos(
                    sentence, i + 1)

                if fst_nominal_group[len(fst_nominal_group) -
                                     1] == cjt and scd_nominal_group == []:
                    #We have to know the second nominal group
                    sentence = sentence[:i + 1] + [fst_nominal_group[0]
                                                   ] + sentence[i + 1:]
                    scd_nominal_group = analyse_nominal_group.find_sn_pos(
                        sentence, i + 1)

                    #We insert word to have 2 nominal groups in the sentence
                    sentence = sentence[:position] + fst_nominal_group[:len(
                        fst_nominal_group) - 1] + [
                            scd_nominal_group[len(scd_nominal_group) - 1]
                        ] + [cjt] + sentence[i + 1:]

                elif fst_nominal_group[len(fst_nominal_group) - 1] == cjt:
                    #We insert word to have 1 nominal group in the sentence
                    sentence = sentence[:position] + fst_nominal_group[:len(
                        fst_nominal_group) - 1] + [
                            scd_nominal_group[len(scd_nominal_group) - 1]
                        ] + sentence[i:]
                i += 1
        i += 1

    return sentence
Exemplo n.º 14
0
def possesion_form(sentence):
    """
    convert 's to possession form 'of'
    Input=sentence                                     Output=sentence
    """

    #init
    begin_pos = 0
    flag = 0

    #We will find the possession case
    while begin_pos < len(sentence):

        #We found a posssession case
        if sentence[begin_pos].endswith("'s") or sentence[begin_pos].endswith("s'"):

            #We have to find the first nominal group
            nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)

            #In the case of a propre name
            while nominal_group != [] and begin_pos != 0 and other_functions.find_cap_lettre(nominal_group[0]) == 1:
                begin_pos -= 1

                nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)
                flag = 1

            #If flag=1 => there is a propre name so we haven't decrement the begin_pos
            if flag == 0:
                while not nominal_group:
                    begin_pos -= 1
                    nominal_group = analyse_nominal_group.find_sn_pos(sentence, begin_pos)

            else:
                #If there is a propre name, begin_pos is wrong, we have to increment
                begin_pos += 1
                flag = 0

            #We recover the list of nominal groups
            nominal_group_list = find_nominal_group_list(sentence[begin_pos:])
            #We create the final phrase
            end_pos = nominal_group_list[len(nominal_group_list) - 1] + begin_pos
            sentence = sentence[:begin_pos] + create_possession_claus(
                nominal_group_list[:len(nominal_group_list) - 1]) + sentence[end_pos:]

            #We continue processing from the end's position
            begin_pos = end_pos

        else:
            begin_pos += 1

    return sentence
Exemplo n.º 15
0
def determination_nominal_group(sentence, position, prop):
    """
    return the nominal group with his complement
    Input=sentence                             Output=nominal group
    """

    nominal_group = analyse_nominal_group.find_sn_pos(sentence, position)
    list_nominal_group = nominal_group

    while position + len(nominal_group) < len(sentence) and sentence[position + len(nominal_group)] == prop:
        position = position + len(nominal_group) + 1
        nominal_group = analyse_nominal_group.find_sn_pos(sentence, position)
        list_nominal_group = list_nominal_group + [prop] + nominal_group

    return list_nominal_group
Exemplo n.º 16
0
def determination_nominal_group(sentence, position, prop):
    """
    return the nominal group with his complement
    Input=sentence                             Output=nominal group
    """

    nominal_group = analyse_nominal_group.find_sn_pos(sentence, position)
    list_nominal_group = nominal_group

    while position + len(nominal_group) < len(sentence) and sentence[
            position + len(nominal_group)] == prop:
        position = position + len(nominal_group) + 1
        nominal_group = analyse_nominal_group.find_sn_pos(sentence, position)
        list_nominal_group = list_nominal_group + [prop] + nominal_group

    return list_nominal_group
Exemplo n.º 17
0
def other_processing(sentence):
    """
    This function performs processing to facilitate the analysis that comes after
    Input=sentence                              Output=sentence
    """

    #init
    i = 0

    #Question with which starts with nominal group without determinant
    if sentence != [] and sentence[0] == 'which':
        sentence = [sentence[0]] + ['the'] + sentence[1:]

    while i < len(sentence):
        #When we have 'think', in some case we need to have 'that'
        if sentence[i] == 'think' and sentence[i + 1] != 'that' and analyse_nominal_group.find_sn_pos(sentence,
                                                                                                      i + 1) != []:
            sentence = sentence[:i + 1] + ['that'] + sentence[i + 1:]

        #'in front of' is the same with 'at the front of'
        if sentence[i] == 'front' and sentence[i - 1] == 'in' and sentence[i + 1] == 'of':
            #sentence=sentence[:i-1]+['at'] +['the']+sentence[i:]
            sentence = sentence[:i - 1] + ['in+front+of'] + sentence[i + 2:]

        if sentence[i] == 'i':
            sentence[i] = 'I'

        # Split 'another' into 'an other' -> undefinite det + other
        if sentence[i] == 'another':
            sentence = sentence[:i - 1] + ['an', 'other'] + sentence[i + 1:]

        i += 1
    return sentence
Exemplo n.º 18
0
def other_processing(sentence):
    """
    This function performs processing to facilitate the analysis that comes after
    Input=sentence                              Output=sentence
    """

    # init
    i = 0

    # Question with which starts with nominal group without determinant
    if sentence != [] and sentence[0] == 'which':
        sentence = [sentence[0]] + ['the'] + sentence[1:]

    while i < len(sentence):
        #When we have 'think', in some case we need to have 'that'
        if sentence[i] == 'think' and sentence[
                i + 1] != 'that' and analyse_nominal_group.find_sn_pos(
                    sentence, i + 1) != []:
            sentence = sentence[:i + 1] + ['that'] + sentence[i + 1:]

        #'in front of' is the same with 'at the front of'
        if sentence[i] == 'front' and sentence[i - 1] == 'in' and sentence[
                i + 1] == 'of':
            #sentence=sentence[:i-1]+['at'] +['the']+sentence[i:]
            sentence = sentence[:i - 1] + ['in+front+of'] + sentence[i + 2:]

        if sentence[i] == 'i':
            sentence[i] = 'I'

        # Split 'another' into 'an other' -> undefinite det + other
        if sentence[i] == 'another':
            sentence = sentence[:i - 1] + ['an', 'other'] + sentence[i + 1:]

        i += 1
    return sentence
Exemplo n.º 19
0
def process_conjunctive_sub(phrase, vg):
    """
    process the conjunctive subsentence
    Input=sentence and verbal class         Output=sentence and verbal class         
    """

    #init
    begin_pos = -1

    #We will find conjunctive subsentence if there is
    if len(phrase
           ) > 0 and phrase[0] == 'that' and analyse_nominal_group.find_sn_pos(
               phrase, 1) != []:
        begin_pos = 0

    if len(phrase) > 2 and phrase[0] in ResourcePool(
    ).pronouns and phrase[1] == 'that' and analyse_nominal_group.find_sn_pos(
            phrase, 2) != []:
        begin_pos = 1

    if begin_pos != -1:
        #We include the relative's and subsentence's proposal if there are relatives or subsentences in this subsentence
        phrase = [phrase[0]] + preprocessing.remerge_sentences(phrase[1:])
        end_pos = other_functions.recover_end_pos_sub(
            phrase[begin_pos:],
            ['that'] + ResourcePool().subsentences + ResourcePool().relatives)

        #We have to remove the proposal
        subsentence = phrase[begin_pos + 1:end_pos]
        subsentence = other_functions.recover_scd_verb_sub(subsentence)

        #We perform processing
        vg.vrb_sub_sentence = vg.vrb_sub_sentence + [
            analyse_sentence.other_sentence(SUBSENTENCE, 'that', subsentence)
        ]
        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) -
                            1].data_type += '+statement'

        #We delete the subsentence
        phrase = phrase[:phrase.index('that')]
        phrase = phrase + phrase[end_pos:] + ['.']

    return phrase
Exemplo n.º 20
0
def conjunction_processing(sentence, cjt):
    """
    creates a nominal group before and after the 'or'
    Input=sentence and the conjunction                     Output=sentence
    """

    #init
    i = 0
    fst_nominal_group = []

    while i < len(sentence):

        if sentence[i] == cjt:
            #We have to find the first and the second nominal group in the sentence
            position = i
            #Until we find the first nominal group
            while position > 0 and fst_nominal_group == []:
                position -= 1
                fst_nominal_group = analyse_nominal_group.find_sn_pos(sentence, position)

            if fst_nominal_group:

                #We will find the second nominal group
                scd_nominal_group = analyse_nominal_group.find_sn_pos(sentence, i + 1)

                if fst_nominal_group[len(fst_nominal_group) - 1] == cjt and scd_nominal_group == []:
                    #We have to know the second nominal group
                    sentence = sentence[:i + 1] + [fst_nominal_group[0]] + sentence[i + 1:]
                    scd_nominal_group = analyse_nominal_group.find_sn_pos(sentence, i + 1)

                    #We insert word to have 2 nominal groups in the sentence
                    sentence = sentence[:position] + fst_nominal_group[:len(fst_nominal_group) - 1] + [
                        scd_nominal_group[len(scd_nominal_group) - 1]] + [cjt] + sentence[i + 1:]

                elif fst_nominal_group[len(fst_nominal_group) - 1] == cjt:
                    #We insert word to have 1 nominal group in the sentence
                    sentence = sentence[:position] + fst_nominal_group[:len(fst_nominal_group) - 1] + [
                        scd_nominal_group[len(scd_nominal_group) - 1]] + sentence[i:]
                i += 1
        i += 1

    return sentence
Exemplo n.º 21
0
def find_nominal_group_list(phrase):
    """
    break phrase into nominal groups with ('s)
    And return also the elements number of the end of this list in the sentence
    Input=sentence                    Output=list of nominal group
    """

    # init
    list = []
    nb_element = 0

    nominal_group = analyse_nominal_group.find_sn_pos(phrase, 0)
    # We use the length of the nominal group because it will be different with len(nominal_group)
    nominal_group_lent = len(nominal_group)

    #We loop until there is no more nominal group
    while nominal_group != [] and (
            nominal_group[len(nominal_group) - 1].endswith("'s")
            or nominal_group[len(nominal_group) - 1].endswith("s'")):

        list = [nominal_group] + list
        nb_element += nominal_group_lent

        #re-init phrase and nominal group
        phrase = phrase[nominal_group_lent:]
        nominal_group = analyse_nominal_group.find_sn_pos(phrase, 0)
        nominal_group_lent = len(nominal_group)

        #We need to have a nominal group so we forced it
        if not nominal_group:
            nominal_group = analyse_nominal_group.find_sn_pos(['the'] + phrase,
                                                              0)
            nominal_group_lent = len(nominal_group) - 1

    list = [nominal_group] + list
    nb_element += nominal_group_lent

    #We put the elments number at the end of the list
    list = list + [nb_element]

    return list
Exemplo n.º 22
0
def find_nominal_group_list(phrase):
    """
    break phrase into nominal groups with ('s)
    And return also the elements number of the end of this list in the sentence
    Input=sentence                    Output=list of nominal group
    """

    # init
    list = []
    nb_element = 0

    nominal_group = analyse_nominal_group.find_sn_pos(phrase, 0)
    # We use the length of the nominal group because it will be different with len(nominal_group)
    nominal_group_lent = len(nominal_group)

    #We loop until there is no more nominal group
    while nominal_group != [] and (
                nominal_group[len(nominal_group) - 1].endswith("'s") or nominal_group[len(nominal_group) - 1].endswith(
                    "s'")):

        list = [nominal_group] + list
        nb_element += nominal_group_lent

        #re-init phrase and nominal group
        phrase = phrase[nominal_group_lent:]
        nominal_group = analyse_nominal_group.find_sn_pos(phrase, 0)
        nominal_group_lent = len(nominal_group)

        #We need to have a nominal group so we forced it
        if not nominal_group:
            nominal_group = analyse_nominal_group.find_sn_pos(['the'] + phrase, 0)
            nominal_group_lent = len(nominal_group) - 1

    list = [nominal_group] + list
    nb_element += nominal_group_lent

    #We put the elments number at the end of the list
    list = list + [nb_element]

    return list
Exemplo n.º 23
0
def correct_i_compl(phrase, verb):
    """
    transform indirect complement to relative
    Input=sentence and verbal class         Output=sentence and verbal class         
    """

    #If we have a direct transitive verb
    if verb in ResourcePool().direct_transitive:

        #init
        x = 0
        while x < len(phrase):
            #If there is a proposal with an adverbial
            if x + 1 < len(phrase) and phrase[x] in ResourcePool(
            ).compelement_proposals:
                #If there is a plural
                phrase = phrase[:x] + analyse_nominal_group.find_plural(
                    phrase[x:])

                if analyse_nominal_group.find_sn_pos(phrase, x + 1):
                    adverbial = analyse_nominal_group.find_sn_pos(
                        phrase, x + 1)
                    begin_pos = x - 1

                    #We will find the subject of the relative
                    while not analyse_nominal_group.find_sn_pos(
                            phrase, begin_pos):
                        begin_pos -= 1
                    nom_gr = analyse_nominal_group.find_sn_pos(
                        phrase, begin_pos)

                    #If there nominal group is just before the adverbial
                    if begin_pos + len(nom_gr) == x:
                        phrase = phrase[:x] + ['which', 'is'] + [
                            phrase[x]
                        ] + adverbial + [';'] + phrase[x + len(adverbial) + 1:]
            x += 1
    return phrase
Exemplo n.º 24
0
def move_prep(sentence):
    """
    put the preposition before the nominal group
    Input=sentence                              Output=sentence
    """

    #init
    i = 0

    while i < len(sentence):
        for p in ResourcePool().prep_change_place:

            #If there is a preposal
            if sentence[i] == p:
                position = i

                #If after preposition we have nominal group, it is for this nominal group
                if not analyse_nominal_group.find_sn_pos(sentence, i + 1):
                    #We have to find the nominal group just before
                    while not analyse_nominal_group.find_sn_pos(sentence, position):
                        position -= 1
                    sentence = sentence[:position] + [p] + sentence[position:i] + sentence[i + 1:]
        i += 1
    return sentence
Exemplo n.º 25
0
def refine_possesion_form(sentence):
    """
    add determinant after 'of' if there is not
    Input=sentence                                     Output=sentence
    """

    #init
    i = 0

    while i < len(sentence):
        if sentence[i] == 'of' and analyse_nominal_group.find_sn_pos(sentence, i + 1) == []:
            sentence = sentence[:i + 1] + ['a'] + sentence[i + 1:]
        i += 1

    return sentence
Exemplo n.º 26
0
def process_conjunctive_sub(phrase, vg):
    """
    process the conjunctive subsentence
    Input=sentence and verbal class         Output=sentence and verbal class         
    """

    #init
    begin_pos = -1

    #We will find conjunctive subsentence if there is
    if len(phrase) > 0 and phrase[0] == 'that' and analyse_nominal_group.find_sn_pos(phrase, 1) != []:
        begin_pos = 0

    if len(phrase) > 2 and phrase[0] in ResourcePool().pronouns and phrase[
        1] == 'that' and analyse_nominal_group.find_sn_pos(phrase, 2) != []:
        begin_pos = 1

    if begin_pos != -1:
        #We include the relative's and subsentence's proposal if there are relatives or subsentences in this subsentence
        phrase = [phrase[0]] + preprocessing.remerge_sentences(phrase[1:])
        end_pos = other_functions.recover_end_pos_sub(phrase[begin_pos:],
                                                      ['that'] + ResourcePool().subsentences + ResourcePool().relatives)

        #We have to remove the proposal
        subsentence = phrase[begin_pos + 1:end_pos]
        subsentence = other_functions.recover_scd_verb_sub(subsentence)

        #We perform processing
        vg.vrb_sub_sentence = vg.vrb_sub_sentence + [analyse_sentence.other_sentence(SUBSENTENCE, 'that', subsentence)]
        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].data_type += '+statement'

        #We delete the subsentence
        phrase = phrase[:phrase.index('that')]
        phrase = phrase + phrase[end_pos:] + ['.']

    return phrase
Exemplo n.º 27
0
def remerge_sentences(sentence):
    """
    This function transform some sentences of the remerge part
    Input=sentence                              Output=sentence
    """

    gr = determination_nominal_group(sentence, 0, 'of')
    if gr and len(gr) < len(sentence):

        next_token = sentence[len(gr)]
        #Case of 'the bottle on the table'
        if next_token in ResourcePool().compelement_proposals:
            if analyse_nominal_group.find_sn_pos(sentence, len(gr) + 1):
                sentence = gr + ['which', 'is'] + sentence[sentence.index(sentence[len(gr)]):]

    return sentence
Exemplo n.º 28
0
def refine_possesion_form(sentence):
    """
    add determinant after 'of' if there is not
    Input=sentence                                     Output=sentence
    """

    # init
    i = 0

    while i < len(sentence):
        if sentence[i] == 'of' and analyse_nominal_group.find_sn_pos(
                sentence, i + 1) == []:
            sentence = sentence[:i + 1] + ['a'] + sentence[i + 1:]
        i += 1

    return sentence
Exemplo n.º 29
0
def find_scd_vrb(phrase):
    """
    This function recovers the second verb in a sentence                             
    Input=sentence                        Output=second verb of the sentence         
    """

    for i in phrase:
        #If there is 'to'
        if i == 'to':

            #It should not be followed by a noun or by an adverb
            if not analyse_nominal_group.find_sn_pos(phrase, phrase.index(i) + 1):
                #If there is a proposal after 'to'
                if phrase[phrase.index(i) + 1] in ResourcePool().proposals:
                    return []
                return [phrase[phrase.index(i) + 1]]
    return []
Exemplo n.º 30
0
def remerge_sentences(sentence):
    """
    This function transform some sentences of the remerge part
    Input=sentence                              Output=sentence
    """

    gr = determination_nominal_group(sentence, 0, 'of')
    if gr and len(gr) < len(sentence):

        next_token = sentence[len(gr)]
        # Case of 'the bottle on the table'
        if next_token in ResourcePool().compelement_proposals:
            if analyse_nominal_group.find_sn_pos(sentence, len(gr) + 1):
                sentence = gr + [
                    'which', 'is'
                ] + sentence[sentence.index(sentence[len(gr)]):]

    return sentence
Exemplo n.º 31
0
def find_scd_vrb(phrase):
    """
    This function recovers the second verb in a sentence                             
    Input=sentence                        Output=second verb of the sentence         
    """

    for i in phrase:
        #If there is 'to'
        if i == 'to':

            #It should not be followed by a noun or by an adverb
            if not analyse_nominal_group.find_sn_pos(phrase,
                                                     phrase.index(i) + 1):
                #If there is a proposal after 'to'
                if phrase[phrase.index(i) + 1] in ResourcePool().proposals:
                    return []
                return [phrase[phrase.index(i) + 1]]
    return []
Exemplo n.º 32
0
def add_scd_vrb(sentence):
    """
    transform the verb after the first verb into second verb
    Input=sentence                              Output=sentence
    """
    #init
    i = 0

    while i < len(sentence):
        #If we have a verb that need a second verb
        if sentence[i] in ResourcePool().verb_need_to:
            nominal_group = analyse_nominal_group.find_sn_pos(sentence, i + 1)
            if nominal_group:
                sentence = sentence[:i + len(nominal_group) + 1] + ['to'] + sentence[i + len(nominal_group) + 1:]
            else:
                sentence = sentence[:i + 1] + ['to'] + sentence[i + 1:]
        i += 1

    return sentence
Exemplo n.º 33
0
def add_scd_vrb(sentence):
    """
    transform the verb after the first verb into second verb
    Input=sentence                              Output=sentence
    """
    # init
    i = 0

    while i < len(sentence):
        # If we have a verb that need a second verb
        if sentence[i] in ResourcePool().verb_need_to:
            nominal_group = analyse_nominal_group.find_sn_pos(sentence, i + 1)
            if nominal_group:
                sentence = sentence[:i + len(nominal_group) + 1] + [
                    'to'
                ] + sentence[i + len(nominal_group) + 1:]
            else:
                sentence = sentence[:i + 1] + ['to'] + sentence[i + 1:]
        i += 1

    return sentence
Exemplo n.º 34
0
def dispatching(sentence):
    """
    distributes the sentence according to:                             
    Their functionality and their type                                               
    Input=sentence, beginning sentence list          Output=class Sentence           
    """

    if len(sentence) > 0:

        #For ending dialogue
        if sentence[0].endswith('bye'):
            return [Sentence(END, '', [], [])]

        #When others
        for x in ResourcePool().sentence_starts:
            #If we find a knowing case
            if sentence[0] == x[0]:


                #For
                if x[1] == '1':
                    return [Sentence(START, '', [], [])]

                #It's a w_question or subsentence
                if x[1] == '2':

                    #If there is which or no nominal group it is a question
                    if sentence[0] != 'which' and analyse_nominal_group.find_sn_pos(sentence, 1) != []:
                        #Here we have the condition of the subsentences
                        return [stc_start_subsentence(sentence)]

                    #For 'when'
                    if x[2] == '1':
                        #If we remove the first word => it becomes like y_n_question
                        return [y_n_ques(W_QUESTION, 'date', sentence[1:])]

                    #For 'where'
                    elif x[2] == '2':
                        return [w_quest_where(W_QUESTION, 'place', sentence)]

                    #For 'what'
                    elif x[2] == '3':
                        #Here we have to use a specific processing for 'type' and 'kind'
                        if sentence[1] == 'type' or sentence[1] == 'kind':
                            #We start by processing the end of the sentence like a y_n_question
                            return [w_quest_class(sentence)]

                        #For other type of 'what' question
                        else:
                            return [w_quest_what(W_QUESTION, sentence)]

                    #For 'how'
                    elif x[2] == '4':

                        if sentence[1] == 'many' or sentence[1] == 'much':
                            return [w_quest_quant(W_QUESTION, 'quantity', sentence)]

                        elif sentence[1] == 'about':
                            #We replace 'about' by 'is' to have a y_n_question
                            sentence[1] = 'is'
                            return [y_n_ques(W_QUESTION, 'invitation', sentence[1:])]

                        #For other type of 'how' question
                        else:
                            return [w_quest_how(W_QUESTION, sentence)]

                    #For 'why'
                    elif x[2] == '5':
                        return [y_n_ques(W_QUESTION, 'reason', sentence[1:])]

                    #For 'whose'
                    elif x[2] == '6':
                        return [w_quest_whose(W_QUESTION, 'owner', sentence)]

                    #For 'who'
                    elif x[2] == '7':
                        return [y_n_ques(W_QUESTION, 'people', sentence[1:])]

                    #For 'which'
                    elif x[2] == '8':
                        return [w_quest_which(W_QUESTION, 'choice', sentence[1:])]

                    #For 'to whom'
                    elif x[2] == '9':
                        return [w_quest_whom(W_QUESTION, 'people', sentence[1:])]

                #It's a y_n_question
                elif x[1] == '3':
                    return [y_n_ques(YES_NO_QUESTION, '', sentence)]

                #It's a conditional sentence
                elif x[1] == '4':
                    return [stc_start_subsentence(sentence)]

                #Agree
                elif x[1] == '5':
                    return separ_sentence(sentence, AGREEMENT)

                #Disagree
                elif x[1] == '6':
                    return separ_sentence(sentence, DISAGREEMENT)

                #Gratulation
                elif x[1] == '7':
                    return separ_sentence(sentence, GRATULATION)

                #Interjunction
                elif x[1] == '8':
                    return [exclama_sentence(sentence)]

        #For exclamatively
        if sentence[len(sentence) - 1] == '!':
            return [exclama_sentence(sentence)]

        #It's a statement or an imperative sentence
        return [other_sentence('', '', sentence)]

    #Default case
    return []
Exemplo n.º 35
0
def process_compare(sentence, vg):
    """
    process the compare
    Input=sentence and verbal structure      Output=sentence verbal structure        
    """

    #init
    i = 0
    conjunction = 'AND'
    gr_nom_list = []

    while i < len(sentence):
        #We will find 'than'
        if sentence[i] == 'than':
            compare = {'nom_gr': [], 'object': ''}

            object = analyse_nominal_group.find_sn_pos(sentence, i + 1)
            #It reproduces the same code as above
            while object:
                #We refine the nominal group if there is an error like ending with question mark
                object = analyse_nominal_group.refine_nom_gr(object)
                #Recovering nominal group
                gr_nom_list = gr_nom_list + [
                    analyse_nominal_structure.fill_nom_gr(sentence, object, i + 1, conjunction)]
                #We take off the nominal group
                sentence = analyse_nominal_group.take_off_nom_gr(sentence, object, i + 1)
                conjunction = 'AND'
                #If there is a relative
                begin_pos_rel = analyse_nominal_group.find_relative(object, sentence, i + 1, ResourcePool().relatives)
                if begin_pos_rel != -1:
                    end_pos_rel = other_functions.recover_end_pos_sub(sentence, ResourcePool().relatives)
                    #We remove the relative part of the sentence
                    sentence = sentence[:begin_pos_rel] + sentence[end_pos_rel:]
                if len(sentence) != i + 1 and (
                            sentence[i + 1] == 'and' or sentence[i + 1] == 'or' or sentence[i + 1] == ':but'):
                    sentence = [sentence[i + 1]] + analyse_nominal_group.find_plural(sentence[1:])
                    object = analyse_nominal_group.find_sn_pos(sentence[i + 2:], i + 1)
                    #We process the 'or' like the 'and' and remove it
                    if sentence[i + 1] == 'or':
                        conjunction = 'OR'
                    elif sentence[i + 1] == ':but':
                        conjunction = 'BUT'
                    else:
                        conjunction = 'AND'
                    sentence = sentence[i + 1:]
                else:
                    object = []

            #Add the nominal group
            compare['nom_gr'] = gr_nom_list

            #Comparator : ends with 'er'
            if sentence[i - 1].endswith('er'):
                compare['object'] = sentence[i - 1]
                sentence = sentence[:i - 1] + sentence[i + 1:]

            #Comparator : with 2 words
            elif sentence[i - 2] == 'more' or sentence[i - 2] == 'less':
                compare['object'] = sentence[i - 2] + '+' + sentence[i - 1]
                sentence = sentence[:i - 1] + sentence[i + 1:]

            #Comparator : exceptions
            elif sentence[i - 1] == 'more' or sentence[i - 1] == 'less':
                compare['object'] = sentence[i - 1]
                sentence = sentence[:i - 1] + sentence[i + 1:]

            vg.comparator = vg.comparator + [compare]
        i += 1
    return sentence
Exemplo n.º 36
0
def dispatching(sentence):
    """
    distributes the sentence according to:                             
    Their functionality and their type                                               
    Input=sentence, beginning sentence list          Output=class Sentence           
    """

    if len(sentence) > 0:

        #For ending dialogue
        if sentence[0].endswith('bye'):
            return [Sentence(END, '', [], [])]

        #When others
        for x in ResourcePool().sentence_starts:
            #If we find a knowing case
            if sentence[0] == x[0]:

                #For
                if x[1] == '1':
                    return [Sentence(START, '', [], [])]

                #It's a w_question or subsentence
                if x[1] == '2':

                    #If there is which or no nominal group it is a question
                    if sentence[
                            0] != 'which' and analyse_nominal_group.find_sn_pos(
                                sentence, 1) != []:
                        #Here we have the condition of the subsentences
                        return [stc_start_subsentence(sentence)]

                    #For 'when'
                    if x[2] == '1':
                        #If we remove the first word => it becomes like y_n_question
                        return [y_n_ques(W_QUESTION, 'date', sentence[1:])]

                    #For 'where'
                    elif x[2] == '2':
                        return [w_quest_where(W_QUESTION, 'place', sentence)]

                    #For 'what'
                    elif x[2] == '3':
                        #Here we have to use a specific processing for 'type' and 'kind'
                        if sentence[1] == 'type' or sentence[1] == 'kind':
                            #We start by processing the end of the sentence like a y_n_question
                            return [w_quest_class(sentence)]

                        #For other type of 'what' question
                        else:
                            return [w_quest_what(W_QUESTION, sentence)]

                    #For 'how'
                    elif x[2] == '4':

                        if sentence[1] == 'many' or sentence[1] == 'much':
                            return [
                                w_quest_quant(W_QUESTION, 'quantity', sentence)
                            ]

                        elif sentence[1] == 'about':
                            #We replace 'about' by 'is' to have a y_n_question
                            sentence[1] = 'is'
                            return [
                                y_n_ques(W_QUESTION, 'invitation',
                                         sentence[1:])
                            ]

                        #For other type of 'how' question
                        else:
                            return [w_quest_how(W_QUESTION, sentence)]

                    #For 'why'
                    elif x[2] == '5':
                        return [y_n_ques(W_QUESTION, 'reason', sentence[1:])]

                    #For 'whose'
                    elif x[2] == '6':
                        return [w_quest_whose(W_QUESTION, 'owner', sentence)]

                    #For 'who'
                    elif x[2] == '7':
                        return [y_n_ques(W_QUESTION, 'people', sentence[1:])]

                    #For 'which'
                    elif x[2] == '8':
                        return [
                            w_quest_which(W_QUESTION, 'choice', sentence[1:])
                        ]

                    #For 'to whom'
                    elif x[2] == '9':
                        return [
                            w_quest_whom(W_QUESTION, 'people', sentence[1:])
                        ]

                #It's a y_n_question
                elif x[1] == '3':
                    return [y_n_ques(YES_NO_QUESTION, '', sentence)]

                #It's a conditional sentence
                elif x[1] == '4':
                    return [stc_start_subsentence(sentence)]

                #Agree
                elif x[1] == '5':
                    return separ_sentence(sentence, AGREEMENT)

                #Disagree
                elif x[1] == '6':
                    return separ_sentence(sentence, DISAGREEMENT)

                #Gratulation
                elif x[1] == '7':
                    return separ_sentence(sentence, GRATULATION)

                #Interjunction
                elif x[1] == '8':
                    return [exclama_sentence(sentence)]

        #For exclamatively
        if sentence[len(sentence) - 1] == '!':
            return [exclama_sentence(sentence)]

        #It's a statement or an imperative sentence
        return [other_sentence('', '', sentence)]

    #Default case
    return []
Exemplo n.º 37
0
def y_n_ques(type, request, sentence):
    """
    process the yes or no question from of a sentence
    Input=type and requesting of sentence and the sentence                           
    Output=class Sentence                                                            
    """

    #init
    vg = VerbalGroup([], [], '', [], [], [], [], VerbalGroup.affirmative, [])
    analysis = Sentence(type, request, [], [])
    modal = []
    stc = sentence

    #We start with determination of probably second verb in subsentence
    sentence = other_functions.find_scd_verb_sub(sentence)

    #We have to add punctuation if there is not
    if sentence == [] or sentence[0] == '.' or sentence[0] == '?' or sentence[
            0] == '!':
        #We have probably the aim as an adverb
        analyse_verbal_structure.find_adv([request], vg)
        analysis.aim = 'thing'
        analysis.sv = [vg]
        return analysis

    #We recover the auxiliary
    aux = sentence[0]

    #We have to know if there is a modal
    if aux in ResourcePool().modal:
        modal = aux

    #If we have a negative form
    if sentence[1] == 'not':
        vg.state = VerbalGroup.negative
        #We remove 'not'
        sentence = sentence[:1] + sentence[2:]

    #Wrong is a noun but not followed by the determinant
    if sentence[1] == 'wrong' and request == 'thing':
        analysis.sn = [NominalGroup([], [], ['wrong'], [], [])]
        sentence = [sentence[0]] + sentence[2:]

    #In this case we have an imperative sentence
    elif analyse_nominal_group.find_sn_pos(sentence,
                                           1) == [] and type != W_QUESTION:
        #We have to reput the 'not'
        if vg.state == VerbalGroup.negative:
            sentence = sentence[:1] + ['not'] + sentence[1:]
        return other_sentence(type, request, sentence)

    #We delete the auxiliary
    sentence = sentence[1:]

    #We have to separate the case using these, this or there
    if sentence[0] in ResourcePool(
    ).demonstrative_det and analyse_verb.infinitive(
        [aux], 'present simple') == ['be']:
        #If we have a verb or an adverb just after (if not, we have a noun)
        if sentence[0].endswith('ed') or sentence[0].endswith(
                'ing') or sentence[0].endswith(
                    'ly') or sentence[0] in ResourcePool().adverbs:
            #We recover this information and remove it
            analysis.sn = [NominalGroup([sentence[0]], [], [], [], [])]
            if sentence[0] == 'there' and aux == 'are':
                analysis.sn[0]._quantifier = 'SOME'
            sentence = sentence[1:]

    if not analysis.sn:
        #We recover the subject
        sentence = analyse_nominal_structure.recover_ns(sentence, analysis, 0)

    if aux == 'do' and not analyse_verbal_structure.can_be_imperative(
            sentence):
        return other_sentence('', '', stc)

    #If there is one element => it is an auxiliary => verb 'be'
    if len(sentence) == 0:
        vg.vrb_tense = analyse_verb.find_tense_statement(aux)
        vg.vrb_main = ['be']
    else:
        sentence = analyse_verbal_structure.delete_unusable_word(sentence)
        sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
        vg.vrb_tense = analyse_verb.find_tense_question(sentence, aux)

        #We process the verb
        verb = analyse_verb.find_verb_question(sentence, aux, vg.vrb_tense)
        verb_main = analyse_verb.return_verb(sentence, verb, vg.vrb_tense)
        vg.vrb_main = [other_functions.convert_to_string(verb_main)]

        #We delete the verb if the aux is not the verb 'be'
        if vg.vrb_main != ['be']:
            sentence = sentence[sentence.index(verb[0]) + len(verb_main):]
        elif sentence[0] == 'be':
            sentence = sentence[1:]

        #Here we have special processing for different cases
        if sentence:
            #For 'what' descrition case
            if sentence[0] == 'like' and aux != 'would':
                vg.vrb_main = ['like']
                sentence = sentence[1:]

            #For 'how' questions with often
            elif sentence[0].endswith('ing') and not (
                    sentence[0].endswith('thing')):
                vg.vrb_main[0] = vg.vrb_main[0] + '+' + sentence[0]
                sentence = sentence[1:]

        #We recover the conjunctive subsentence
        sentence = analyse_verbal_structure.process_conjunctive_sub(
            sentence, vg)

        #It verifies if there is a secondary verb
        sec_vrb = analyse_verbal_structure.find_scd_vrb(sentence)
        if sec_vrb:
            sentence = analyse_verbal_structure.process_scd_sentence(
                sentence, vg, sec_vrb)

        #We recover the subsentence
        sentence = analyse_verbal_structure.process_subsentence(sentence, vg)

        #Process relative changes
        sentence = analyse_verbal_structure.correct_i_compl(
            sentence, vg.vrb_main[0])

        sentence = analyse_verbal_structure.process_compare(sentence, vg)

        sentence = analyse_nominal_group.find_plural(sentence)
        #We recover the direct, indirect complement and the adverbial
        sentence = analyse_verbal_structure.recover_obj_iobj(sentence, vg)

        #We have to take off adverbs form the sentence
        sentence = analyse_verbal_structure.find_adv(sentence, vg)

    #We perform the processing with the modal
    if modal:
        vg.vrb_main = [modal + '+' + vg.vrb_main[0]]

    #If there is a forgotten
    sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

    #In case there is a state verb followed by an adjective
    sentence = analyse_verbal_structure.state_adjective(sentence, vg)

    #We have to correct the mistake of the subject
    for p in ResourcePool().demonstrative_det:
        if analysis.sn and analysis.sn[0].det == [
                p
        ] and analysis.sn[0].noun == []:
            if sentence != [0] and sentence[0] == '.' and sentence[
                    0] == '?' and sentence[0] == '!':
                if sentence[0] in ResourcePool().proposals:
                    pass
                else:
                    analysis.sn[0].noun = [sentence[0]]
                    sentence = sentence[1:]
                    sentence = analyse_verbal_structure.state_adjective(
                        sentence, vg)

    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    while len(sentence) > 1:
        stc = analyse_verbal_structure.create_nom_gr(sentence, request)
        #We recover the direct, indirect complement and the adverbial
        stc = analyse_verbal_structure.recover_obj_iobj(stc, vg)
        if stc == sentence:
            #We leave the loop
            break
        else:
            sentence = stc

    vg = analyse_verbal_structure.refine_indirect_complement(vg)
    vg = analyse_verbal_structure.refine_subsentence(vg)
    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    analysis.sv = [vg]
    return analysis
Exemplo n.º 38
0
def other_sentence(type, request, sentence):
    """
    process the other from of a sentence                                
    Input=type and requesting of sentence and the sentence                               
    Output=class Sentence                                                            
    """

    #init
    vg = VerbalGroup([], [], '', [], [], [], [], VerbalGroup.affirmative, [])
    analysis = Sentence(type, request, [], [])
    modal = []

    if not sentence:
        return []

    #We have to add punctuation if there is not
    if sentence[len(sentence) - 1] not in ['.', '?', '!']:
        sentence = sentence + ['.']

    #We start with determination of probably second verb in subsentence
    sentence = other_functions.find_scd_verb_sub(sentence)

    #We search the subject
    sbj = analyse_nominal_group.find_sn_pos(sentence, 0)

    if sbj != [] or type == RELATIVE:
        #If we haven't a data type => it is a statement
        if type == '':
            analysis.data_type = STATEMENT

        #We have to separate the case using these, this or there
        if sentence[0] in ResourcePool(
        ).demonstrative_det and analyse_verb.infinitive(
            [sentence[1]], 'present simple') == ['be']:
            #We recover this information and remove it
            analysis.sn = [NominalGroup([sentence[0]], [], [], [], [])]
            if sentence[0] == 'there' and sentence[1] == 'are':
                analysis.sn[0]._quantifier = 'SOME'
            sentence = sentence[1:]

        if not analysis.sn:
            #We recover the subject
            sentence = analyse_nominal_structure.recover_ns(
                sentence, analysis, 0)

        #End of the sentence? -> nominal sentence
        if sentence == [] or sentence[0] in ['.', '!', '?']:
            analysis.sv = []
            return analysis

        #We have to know if there is a modal
        if sentence[0] in ResourcePool().modal:
            modal = sentence[0]
            if modal == 'can' or modal == 'must' or modal == 'shall' or modal == 'may':
                sentence = sentence[1:]

        #We must take into account all possible cases to recover the sentence's tense
        if len(sentence) > 1 and sentence[1] == 'not':
            vg.state = VerbalGroup.negative

            #Before the negative form we have an auxiliary for the negation
            if sentence[0] == 'do' or sentence[0] == 'does' or sentence[
                    0] == 'did':
                vg.vrb_tense = analyse_verb.find_tense_statement([sentence[0]])
                sentence = sentence[2:]
                sentence = analyse_verbal_structure.delete_unusable_word(
                    sentence)
                sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

            #There is a modal
            elif modal:
                sentence = [sentence[0]] + sentence[2:]
                sentence = analyse_verbal_structure.delete_unusable_word(
                    sentence)
                sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
                vg.vrb_tense = analyse_verb.find_tense_statement(sentence)

            else:
                #We remove 'not' and find the tense
                sentence = sentence[:1] + sentence[2:]
                sentence = analyse_verbal_structure.delete_unusable_word(
                    sentence)
                sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
                vg.vrb_tense = analyse_verb.find_tense_statement(sentence)

        #For the affirmative processing
        else:
            if sentence[0] == 'not':
                vg.state = VerbalGroup.negative
                sentence = sentence[1:]

            sentence = analyse_verbal_structure.delete_unusable_word(sentence)
            sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
            vg.vrb_tense = analyse_verb.find_tense_statement(sentence)

        verb = analyse_verb.find_verb_statement(sentence, vg.vrb_tense)
        verb_main = analyse_verb.return_verb(sentence, verb, vg.vrb_tense)
        vg.vrb_main = [other_functions.convert_to_string(verb_main)]

        #We delete the verb
        sentence = sentence[sentence.index(verb[0]) + len(verb_main):]

        #We perform the processing with the modal
        if modal:
            vg.vrb_main = [modal + '+' + vg.vrb_main[0]]

    #This is a imperative form
    else:
        #re-init
        analysis.data_type = IMPERATIVE
        vg.vrb_tense = 'present simple'

        if sentence[0] in ResourcePool().proposals:
            sentence = ['.'] + sentence

        #Negative form
        if sentence[1] == 'not':
            sentence = sentence[sentence.index('not') + 1:]
            sentence = analyse_verbal_structure.delete_unusable_word(sentence)
            sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
            vg.state = VerbalGroup.negative
        else:
            sentence = analyse_verbal_structure.delete_unusable_word(sentence)
            sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

        #We process the verb
        verb = [sentence[0]]
        verb_main = analyse_verb.return_verb(sentence, verb, vg.vrb_tense)
        vg.vrb_main = [other_functions.convert_to_string(verb_main)]

        #We delete the verb
        sentence = sentence[sentence.index(verb[0]) + len(verb_main):]

    if sentence and sentence[-1] == '?':
        analysis.data_type = YES_NO_QUESTION

    #We recover the conjunctive subsentence
    sentence = analyse_verbal_structure.process_conjunctive_sub(sentence, vg)

    #It verifies if there is a secondary verb
    sec_vrb = analyse_verbal_structure.find_scd_vrb(sentence)
    if sec_vrb:
        sentence = analyse_verbal_structure.process_scd_sentence(
            sentence, vg, sec_vrb)

    #We recover the subsentence
    sentence = analyse_verbal_structure.process_subsentence(sentence, vg)

    if sentence != [] and vg.vrb_main != []:
        #Process relative changes
        sentence = analyse_verbal_structure.correct_i_compl(
            sentence, vg.vrb_main[0])

    sentence = analyse_verbal_structure.process_compare(sentence, vg)

    sentence = analyse_nominal_group.find_plural(sentence)
    #We recover the direct, indirect complement and the adverbial
    sentence = analyse_verbal_structure.recover_obj_iobj(sentence, vg)

    #We have to take off abverbs form the sentence
    sentence = analyse_verbal_structure.find_adv(sentence, vg)

    #In case there is a state verb followed by an adjective
    sentence = analyse_verbal_structure.state_adjective(sentence, vg)

    #If there is a forgotten
    sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    while len(sentence) > 1:
        stc = analyse_verbal_structure.create_nom_gr(sentence, request)
        #We recover the direct, indirect complement and the adverbial
        stc = analyse_verbal_structure.recover_obj_iobj(stc, vg)
        if stc == sentence:
            #We leave the loop
            break
        else:
            sentence = stc

    vg = analyse_verbal_structure.refine_indirect_complement(vg)
    vg = analyse_verbal_structure.refine_subsentence(vg)
    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    analysis.sv = [vg]
    return analysis
Exemplo n.º 39
0
def recover_obj_iobj(phrase, vg):
    """
    finds the direct, indirect object and the adverbial                
    We, also, put these information in the class                                     
    Input=sentence and verbal class              Output=sentence and verbal class    
    """

    #init
    conjunction = 'AND'

    object = analyse_nominal_group.find_sn(phrase)

    if phrase and \
            not object and \
                    phrase[0] in ResourcePool().adverbs_at_end:
        vg.advrb = [phrase[0]]

    while object:

        #If it is not a direct object => there is a proposal
        proposal = check_proposal(phrase, object)

        if proposal:

            gr_nom_list = []
            #This 'while' is for duplicate with 'and'
            while object:
                pos_object = phrase.index(object[0])

                #We refine the nominal group if there is an error like ending with question mark
                object = analyse_nominal_group.refine_nom_gr(object)

                #Recovering nominal group
                gr_nom_list = gr_nom_list + [
                    analyse_nominal_structure.fill_nom_gr(phrase, object, pos_object, conjunction)]

                #We take off the nominal group
                phrase = analyse_nominal_group.take_off_nom_gr(phrase, object, pos_object)
                #We will take off the proposal
                phrase = phrase[:phrase.index(proposal[0])] + phrase[phrase.index(proposal[0]) + 1:]
                conjunction = 'AND'

                #If there is a relative
                begin_pos_rel = analyse_nominal_group.find_relative(object, phrase, pos_object,
                                                                    ResourcePool().relatives)

                if begin_pos_rel != -1:
                    end_pos_rel = other_functions.recover_end_pos_sub(phrase, ResourcePool().relatives)
                    #We remove the relative part of the phrase
                    phrase = phrase[:begin_pos_rel] + phrase[end_pos_rel:]

                #If there is 'and', we need to duplicate the information with the proposal if there is
                if len(phrase) != 0 and (phrase[0] == 'and' or phrase[0] == 'or' or phrase[0] == ':but'):

                    phrase = [phrase[0]] + analyse_nominal_group.find_plural(phrase[1:])

                    #We have not duplicate the proposal, it depends on the presence of the nominal group after  
                    if analyse_nominal_group.find_sn_pos(phrase, 1):
                        phrase = [phrase[0]] + proposal + phrase[1:]
                    else:
                        phrase = [phrase[0]] + phrase[1:]

                    object = analyse_nominal_group.find_sn_pos(phrase[1:], 0)

                    #We process the 'or' like the 'and' and remove it
                    if phrase[0] == 'or':
                        conjunction = 'OR'
                    elif phrase[0] == ':but':
                        conjunction = 'BUT'
                    else:
                        conjunction = 'AND'
                    phrase = phrase[1:]

                else:
                    object = []

            vg.i_cmpl = vg.i_cmpl + [Indirect_Complement(proposal, gr_nom_list)]

        else:
            #It is a direct complement
            gr_nom_list = []
            #It reproduces the same code as above
            while object:
                pos_object = phrase.index(object[0])

                #We refine the nominal group if there is an error like ending with question mark
                object = analyse_nominal_group.refine_nom_gr(object)

                #Recovering nominal group
                gr_nom_list = gr_nom_list + [
                    analyse_nominal_structure.fill_nom_gr(phrase, object, pos_object, conjunction)]

                #We take off the nominal group
                phrase = analyse_nominal_group.take_off_nom_gr(phrase, object, pos_object)
                conjunction = 'AND'

                #If there is a relative
                begin_pos_rel = analyse_nominal_group.find_relative(object, phrase, pos_object,
                                                                    ResourcePool().relatives)

                if begin_pos_rel != -1:
                    end_pos_rel = other_functions.recover_end_pos_sub(phrase, ResourcePool().relatives)
                    #We remove the relative part of the phrase
                    phrase = phrase[:begin_pos_rel] + phrase[end_pos_rel:]

                if len(phrase) != 0 and (phrase[0] == 'and' or phrase[0] == 'or' or phrase[0] == ':but'):

                    phrase = [phrase[0]] + analyse_nominal_group.find_plural(phrase[1:])
                    object = analyse_nominal_group.find_sn_pos(phrase[1:], 0)

                    #We process the 'or' like the 'and' and remove it
                    if phrase[0] == 'or':
                        conjunction = 'OR'
                    elif phrase[0] == ':but':
                        conjunction = 'BUT'
                    else:
                        conjunction = 'AND'
                    phrase = phrase[1:]

                else:
                    object = []

            #In a sentence there is just one direct complement if there is no second verb
            if not vg.d_obj:
                vg.d_obj = gr_nom_list
            else:
                #Else the first nominal group found is indirect and this one is direct complement
                vg.i_cmpl = vg.i_cmpl + [Indirect_Complement([], vg.d_obj)]
                vg.d_obj = gr_nom_list

        #If the last nominal group is followed by another one in plural form 
        phrase = analyse_nominal_group.find_plural(phrase)
        object = analyse_nominal_group.find_sn(phrase)

    return phrase
Exemplo n.º 40
0
def upper_to_lower(sentence):
    """
    converts the upper case to lower case
    Input=sentence, beginning sentence list                  Output=sentence
    """

    # If the sentence begins with upper case
    if other_functions.find_cap_lettre(sentence[0]):

        # We convert upper case to lower case if it is not 'I'
        if sentence[0] == 'I':
            sentence = expand_contractions(sentence)
            return sentence
        else:
            sentence[0] = sentence[0][0].lower() + sentence[0][1:]

        #We make changes here because we need lower case and not upper case
        sentence = expand_contractions(sentence)
        sentence = adverbial_or_subsentence(sentence)
        stc = process_and_beginning_sentence(sentence)

        #If sentence is modified we can return it
        if stc != sentence:
            return stc

        #We find an action verb => it is an imperative sentence
        if sentence[0] in ThematicRolesDict().get_all_verbs():
            return sentence

        #If we find the word in the Beginning_sentence list
        for v in ResourcePool().sentence_starts:
            if sentence[0] == v[0]:
                return sentence

        #We find a number
        if other_functions.number(sentence[0]) == 1:
            return sentence

        #If there is plural
        sentence = analyse_nominal_group.find_plural(sentence)
        #If it still start with adjective
        if analyse_nominal_group.is_an_adj(sentence[0]) == 1:
            sentence = ['the'] + sentence

        #If there is a nominal group
        if analyse_nominal_group.find_sn_pos(sentence, 0):
            return sentence

        #Default case: we assume a proper name, we convert lowercase to uppercase
        sentence[0] = sentence[0][0].upper() + sentence[0][1:]

    # If the sentence begins with lower case
    else:
        #We make changes here because we need lower case and not upper case
        sentence = expand_contractions(sentence)
        sentence = adverbial_or_subsentence(sentence)
        sentence = process_and_beginning_sentence(sentence)

        #If we find the word in the Beginning_sentence list so we can return it
        for v in ResourcePool().sentence_starts:
            if sentence[0] == v[0]:
                return sentence

        #If there is plural
        sentence = analyse_nominal_group.find_plural(sentence)
        #If it still start with adjective
        if analyse_nominal_group.is_an_adj(sentence[0]) == 1:
            sentence = ['the'] + sentence

    return sentence
Exemplo n.º 41
0
def process_compare(sentence, vg):
    """
    process the compare
    Input=sentence and verbal structure      Output=sentence verbal structure        
    """

    #init
    i = 0
    conjunction = 'AND'
    gr_nom_list = []

    while i < len(sentence):
        #We will find 'than'
        if sentence[i] == 'than':
            compare = {'nom_gr': [], 'object': ''}

            object = analyse_nominal_group.find_sn_pos(sentence, i + 1)
            #It reproduces the same code as above
            while object:
                #We refine the nominal group if there is an error like ending with question mark
                object = analyse_nominal_group.refine_nom_gr(object)
                #Recovering nominal group
                gr_nom_list = gr_nom_list + [
                    analyse_nominal_structure.fill_nom_gr(
                        sentence, object, i + 1, conjunction)
                ]
                #We take off the nominal group
                sentence = analyse_nominal_group.take_off_nom_gr(
                    sentence, object, i + 1)
                conjunction = 'AND'
                #If there is a relative
                begin_pos_rel = analyse_nominal_group.find_relative(
                    object, sentence, i + 1,
                    ResourcePool().relatives)
                if begin_pos_rel != -1:
                    end_pos_rel = other_functions.recover_end_pos_sub(
                        sentence,
                        ResourcePool().relatives)
                    #We remove the relative part of the sentence
                    sentence = sentence[:begin_pos_rel] + sentence[end_pos_rel:]
                if len(sentence) != i + 1 and (sentence[i + 1] == 'and'
                                               or sentence[i + 1] == 'or'
                                               or sentence[i + 1] == ':but'):
                    sentence = [
                        sentence[i + 1]
                    ] + analyse_nominal_group.find_plural(sentence[1:])
                    object = analyse_nominal_group.find_sn_pos(
                        sentence[i + 2:], i + 1)
                    #We process the 'or' like the 'and' and remove it
                    if sentence[i + 1] == 'or':
                        conjunction = 'OR'
                    elif sentence[i + 1] == ':but':
                        conjunction = 'BUT'
                    else:
                        conjunction = 'AND'
                    sentence = sentence[i + 1:]
                else:
                    object = []

            #Add the nominal group
            compare['nom_gr'] = gr_nom_list

            #Comparator : ends with 'er'
            if sentence[i - 1].endswith('er'):
                compare['object'] = sentence[i - 1]
                sentence = sentence[:i - 1] + sentence[i + 1:]

            #Comparator : with 2 words
            elif sentence[i - 2] == 'more' or sentence[i - 2] == 'less':
                compare['object'] = sentence[i - 2] + '+' + sentence[i - 1]
                sentence = sentence[:i - 1] + sentence[i + 1:]

            #Comparator : exceptions
            elif sentence[i - 1] == 'more' or sentence[i - 1] == 'less':
                compare['object'] = sentence[i - 1]
                sentence = sentence[:i - 1] + sentence[i + 1:]

            vg.comparator = vg.comparator + [compare]
        i += 1
    return sentence
Exemplo n.º 42
0
def and_nominal_group_comma(sentence):
    """
    process the case when there is a comma between nominal groups
    Input=sentence                                     Output=sentence
    """

    # init
    i = 0
    flag = 2
    list_nominal_group = []

    # If we find ','
    while i < len(sentence):
        if sentence[i] == ',':
            nominal_group = determination_nominal_group(sentence, i + 1, 'of')
            end_pos = len(nominal_group) + i + 1

            #First we recover the all nominal groups preceded by ','
            while nominal_group != [] and sentence[end_pos] == ',':
                list_nominal_group = ['and'] + nominal_group
                nominal_group = determination_nominal_group(
                    sentence, end_pos + 1, 'of')
                end_pos = len(nominal_group) + end_pos + 1
                #Flag still 2 because this stage is not compulsory
                flag = 2

            #We will find the last nominal group of this phrase
            if nominal_group != [] and sentence[end_pos] == 'and':
                list_nominal_group = list_nominal_group + ['and'
                                                           ] + nominal_group
                nominal_group = determination_nominal_group(
                    sentence, end_pos + 1, 'of')
                end_pos = len(nominal_group) + end_pos + 1
                list_nominal_group = list_nominal_group + ['and'
                                                           ] + nominal_group
                #Flag will be 1 because this stage is compulsory
                flag -= 1

            #If flag=1 => we can have the and_nominal_group_comma case
            if flag == 1:
                #We have to find the first nominal group
                begin_pos = i - 1
                nominal_group = analyse_nominal_group.find_sn_pos(
                    sentence, begin_pos)
                while nominal_group == [] and begin_pos > 0:
                    begin_pos -= 1
                    nominal_group = analyse_nominal_group.find_sn_pos(
                        sentence, begin_pos)
                #If this nominal group preceded the first ',' => OK
                if nominal_group != [] and begin_pos + len(nominal_group) == i:
                    flag -= 1
                    list_nominal_group = nominal_group + list_nominal_group

            #We have an and_nominal_group_comma case
            if flag == 0:
                sentence = sentence[:begin_pos] + list_nominal_group + sentence[
                    end_pos:]
                i = end_pos

        i += 1

    return sentence
Exemplo n.º 43
0
def upper_to_lower(sentence):
    """
    converts the upper case to lower case
    Input=sentence, beginning sentence list                  Output=sentence
    """

    #If the sentence begins with upper case
    if other_functions.find_cap_lettre(sentence[0]):

        #We convert upper case to lower case if it is not 'I'
        if sentence[0] == 'I':
            sentence = expand_contractions(sentence)
            return sentence
        else:
            sentence[0] = sentence[0][0].lower() + sentence[0][1:]

        #We make changes here because we need lower case and not upper case
        sentence = expand_contractions(sentence)
        sentence = adverbial_or_subsentence(sentence)
        stc = process_and_beginning_sentence(sentence)

        #If sentence is modified we can return it
        if stc != sentence:
            return stc

        #We find an action verb => it is an imperative sentence
        if sentence[0] in ThematicRolesDict().get_all_verbs():
            return sentence

        #If we find the word in the Beginning_sentence list
        for v in ResourcePool().sentence_starts:
            if sentence[0] == v[0]:
                return sentence

        #We find a number
        if other_functions.number(sentence[0]) == 1:
            return sentence

        #If there is plural
        sentence = analyse_nominal_group.find_plural(sentence)
        #If it still start with adjective
        if analyse_nominal_group.is_an_adj(sentence[0]) == 1:
            sentence = ['the'] + sentence

        #If there is a nominal group
        if analyse_nominal_group.find_sn_pos(sentence, 0):
            return sentence

        #Default case: we assume a proper name, we convert lowercase to uppercase
        sentence[0] = sentence[0][0].upper() + sentence[0][1:]

    #If the sentence begins with lower case
    else:
        #We make changes here because we need lower case and not upper case
        sentence = expand_contractions(sentence)
        sentence = adverbial_or_subsentence(sentence)
        sentence = process_and_beginning_sentence(sentence)

        #If we find the word in the Beginning_sentence list so we can return it
        for v in ResourcePool().sentence_starts:
            if sentence[0] == v[0]:
                return sentence

        #If there is plural
        sentence = analyse_nominal_group.find_plural(sentence)
        #If it still start with adjective
        if analyse_nominal_group.is_an_adj(sentence[0]) == 1:
            sentence = ['the'] + sentence

    return sentence
Exemplo n.º 44
0
def process_subsentence(phrase, vg):
    """
    process the subsentence                                             
    Input=sentence and verbal class         Output=sentence and verbal class         
    """

    #init
    begin_pos = -1

    #If phrase is empty
    if len(phrase) < 0:
        return phrase

    #We look down the list to see if there is a subsentence
    for w in ResourcePool().subsentences:
        if w in phrase:

            begin_pos = phrase.index(w)

            #We include the relative's proposal if there are relatives in the subsentence
            end_pos = other_functions.recover_end_pos_sub(
                phrase[begin_pos:],
                ResourcePool().subsentences + ResourcePool().relatives)

            #If it is 'where', it can be relative if before we have nominal group
            if w == 'where' or w == 'which':
                position = phrase.index(w) - 1

                gr = analyse_nominal_group.find_sn_pos(phrase, position)

                #We have to find the nominal group just before
                while position > 0 and gr == []:
                    position -= 1
                    gr = analyse_nominal_group.find_sn_pos(phrase, position)
                    #For exceptions, if the nominal group end with the proposal
                if gr != [] and gr[len(gr) - 1] == w:
                    gr = gr[:len(gr) - 1]

            #Else we return the sentence and we assume it as relative
            if (w != 'where' and w != 'which') or (
                    len(gr) + position != phrase.index(w) or
                (len(gr) == 1 and is_cmpl_pr(gr[0]) == 1)):
                #We have to remove the proposal
                subsentence = phrase[begin_pos + 1:begin_pos + end_pos]
                if len(subsentence) > 1:
                    subsentence = other_functions.recover_scd_verb_sub(
                        subsentence)

                    if w != 'which':
                        #We perform processing
                        vg.vrb_sub_sentence = vg.vrb_sub_sentence + analyse_sentence.dispatching(
                            subsentence)
                        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].data_type = SUBSENTENCE + '+' + \
                                                                                      vg.vrb_sub_sentence[len(
                                                                                          vg.vrb_sub_sentence) - 1].data_type
                        if w[0] == ':':
                            vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) -
                                                1].aim = w[1:]
                        else:
                            vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) -
                                                1].aim = w
                    else:
                        #Exception for which
                        vg.vrb_sub_sentence = vg.vrb_sub_sentence + [
                            analyse_sentence.w_quest_which(
                                W_QUESTION, 'choice', ['the'] + subsentence)
                        ]
                        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].data_type = SUBSENTENCE + '+' + \
                                                                                      vg.vrb_sub_sentence[len(
                                                                                          vg.vrb_sub_sentence) - 1].data_type
                        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) -
                                            1].aim = w

                    #If 'but' is between 2 nominal group and not before subsentence
                    if w == 'but':
                        #If the main verb is not a verb but a part of verbal structure => we have nominal groups
                        for k in ['.', '?', '!', ''
                                  ] + ResourcePool().proposals:
                            if not vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].sv \
                                or \
                                            vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].sv[0].vrb_main[0] == k:
                                #We make changes and return the sentence with but of nominal groups
                                phrase[phrase.index(w)] = ':but'
                                vg.vrb_sub_sentence = vg.vrb_sub_sentence[:len(
                                    vg.vrb_sub_sentence) - 1]
                                return phrase

                    #We delete the subsentence
                    phrase = phrase[:begin_pos] + phrase[begin_pos +
                                                         end_pos:] + ['.']
                    return phrase
    return phrase
Exemplo n.º 45
0
def y_n_ques(type, request, sentence):
    """
    process the yes or no question from of a sentence
    Input=type and requesting of sentence and the sentence                           
    Output=class Sentence                                                            
    """

    #init
    vg = VerbalGroup([], [], '', [], [], [], [], VerbalGroup.affirmative, [])
    analysis = Sentence(type, request, [], [])
    modal = []
    stc = sentence

    #We start with determination of probably second verb in subsentence
    sentence = other_functions.find_scd_verb_sub(sentence)

    #We have to add punctuation if there is not
    if sentence == [] or sentence[0] == '.' or sentence[0] == '?' or sentence[0] == '!':
        #We have probably the aim as an adverb
        analyse_verbal_structure.find_adv([request], vg)
        analysis.aim = 'thing'
        analysis.sv = [vg]
        return analysis

    #We recover the auxiliary 
    aux = sentence[0]

    #We have to know if there is a modal
    if aux in ResourcePool().modal:
        modal = aux

    #If we have a negative form
    if sentence[1] == 'not':
        vg.state = VerbalGroup.negative
        #We remove 'not'
        sentence = sentence[:1] + sentence[2:]

    #Wrong is a noun but not followed by the determinant
    if sentence[1] == 'wrong' and request == 'thing':
        analysis.sn = [NominalGroup([], [], ['wrong'], [], [])]
        sentence = [sentence[0]] + sentence[2:]

    #In this case we have an imperative sentence
    elif analyse_nominal_group.find_sn_pos(sentence, 1) == [] and type != W_QUESTION:
        #We have to reput the 'not'
        if vg.state == VerbalGroup.negative:
            sentence = sentence[:1] + ['not'] + sentence[1:]
        return other_sentence(type, request, sentence)

    #We delete the auxiliary
    sentence = sentence[1:]

    #We have to separate the case using these, this or there
    if sentence[0] in ResourcePool().demonstrative_det and analyse_verb.infinitive([aux], 'present simple') == ['be']:
        #If we have a verb or an adverb just after (if not, we have a noun)
        if sentence[0].endswith('ed') or sentence[0].endswith('ing') or sentence[0].endswith('ly') or sentence[
            0] in ResourcePool().adverbs:
            #We recover this information and remove it
            analysis.sn = [NominalGroup([sentence[0]], [], [], [], [])]
            if sentence[0] == 'there' and aux == 'are':
                analysis.sn[0]._quantifier = 'SOME'
            sentence = sentence[1:]

    if not analysis.sn:
        #We recover the subject
        sentence = analyse_nominal_structure.recover_ns(sentence, analysis, 0)

    if aux == 'do' and not analyse_verbal_structure.can_be_imperative(sentence):
        return other_sentence('', '', stc)

    #If there is one element => it is an auxiliary => verb 'be'
    if len(sentence) == 0:
        vg.vrb_tense = analyse_verb.find_tense_statement(aux)
        vg.vrb_main = ['be']
    else:
        sentence = analyse_verbal_structure.delete_unusable_word(sentence)
        sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
        vg.vrb_tense = analyse_verb.find_tense_question(sentence, aux)

        #We process the verb
        verb = analyse_verb.find_verb_question(sentence, aux, vg.vrb_tense)
        verb_main = analyse_verb.return_verb(sentence, verb, vg.vrb_tense)
        vg.vrb_main = [other_functions.convert_to_string(verb_main)]

        #We delete the verb if the aux is not the verb 'be'
        if vg.vrb_main != ['be']:
            sentence = sentence[sentence.index(verb[0]) + len(verb_main):]
        elif sentence[0] == 'be':
            sentence = sentence[1:]

        #Here we have special processing for different cases
        if sentence:
            #For 'what' descrition case
            if sentence[0] == 'like' and aux != 'would':
                vg.vrb_main = ['like']
                sentence = sentence[1:]

            #For 'how' questions with often
            elif sentence[0].endswith('ing') and not (sentence[0].endswith('thing')):
                vg.vrb_main[0] = vg.vrb_main[0] + '+' + sentence[0]
                sentence = sentence[1:]

        #We recover the conjunctive subsentence
        sentence = analyse_verbal_structure.process_conjunctive_sub(sentence, vg)

        #It verifies if there is a secondary verb
        sec_vrb = analyse_verbal_structure.find_scd_vrb(sentence)
        if sec_vrb:
            sentence = analyse_verbal_structure.process_scd_sentence(sentence, vg, sec_vrb)

        #We recover the subsentence
        sentence = analyse_verbal_structure.process_subsentence(sentence, vg)

        #Process relative changes
        sentence = analyse_verbal_structure.correct_i_compl(sentence, vg.vrb_main[0])

        sentence = analyse_verbal_structure.process_compare(sentence, vg)

        sentence = analyse_nominal_group.find_plural(sentence)
        #We recover the direct, indirect complement and the adverbial
        sentence = analyse_verbal_structure.recover_obj_iobj(sentence, vg)

        #We have to take off adverbs form the sentence
        sentence = analyse_verbal_structure.find_adv(sentence, vg)

    #We perform the processing with the modal
    if modal:
        vg.vrb_main = [modal + '+' + vg.vrb_main[0]]

    #If there is a forgotten
    sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

    #In case there is a state verb followed by an adjective
    sentence = analyse_verbal_structure.state_adjective(sentence, vg)

    #We have to correct the mistake of the subject
    for p in ResourcePool().demonstrative_det:
        if analysis.sn and analysis.sn[0].det == [p] and analysis.sn[0].noun == []:
            if sentence != [0] and sentence[0] == '.' and sentence[0] == '?' and sentence[0] == '!':
                if sentence[0] in ResourcePool().proposals:
                    pass
                else:
                    analysis.sn[0].noun = [sentence[0]]
                    sentence = sentence[1:]
                    sentence = analyse_verbal_structure.state_adjective(sentence, vg)

    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    while len(sentence) > 1:
        stc = analyse_verbal_structure.create_nom_gr(sentence, request)
        #We recover the direct, indirect complement and the adverbial
        stc = analyse_verbal_structure.recover_obj_iobj(stc, vg)
        if stc == sentence:
            #We leave the loop
            break
        else:
            sentence = stc

    vg = analyse_verbal_structure.refine_indirect_complement(vg)
    vg = analyse_verbal_structure.refine_subsentence(vg)
    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    analysis.sv = [vg]
    return analysis
Exemplo n.º 46
0
def process_subsentence(phrase, vg):
    """
    process the subsentence                                             
    Input=sentence and verbal class         Output=sentence and verbal class         
    """

    #init
    begin_pos = -1

    #If phrase is empty
    if len(phrase) < 0:
        return phrase

    #We look down the list to see if there is a subsentence
    for w in ResourcePool().subsentences:
        if w in phrase:

            begin_pos = phrase.index(w)

            #We include the relative's proposal if there are relatives in the subsentence
            end_pos = other_functions.recover_end_pos_sub(phrase[begin_pos:],
                                                          ResourcePool().subsentences + ResourcePool().relatives)

            #If it is 'where', it can be relative if before we have nominal group
            if w == 'where' or w == 'which':
                position = phrase.index(w) - 1

                gr = analyse_nominal_group.find_sn_pos(phrase, position)

                #We have to find the nominal group just before
                while position > 0 and gr == []:
                    position -= 1
                    gr = analyse_nominal_group.find_sn_pos(phrase, position)
                    #For exceptions, if the nominal group end with the proposal
                if gr != [] and gr[len(gr) - 1] == w:
                    gr = gr[:len(gr) - 1]

            #Else we return the sentence and we assume it as relative
            if (w != 'where' and w != 'which') or (
                        len(gr) + position != phrase.index(w) or (len(gr) == 1 and is_cmpl_pr(gr[0]) == 1)):
                #We have to remove the proposal
                subsentence = phrase[begin_pos + 1:begin_pos + end_pos]
                if len(subsentence) > 1:
                    subsentence = other_functions.recover_scd_verb_sub(subsentence)

                    if w != 'which':
                        #We perform processing
                        vg.vrb_sub_sentence = vg.vrb_sub_sentence + analyse_sentence.dispatching(subsentence)
                        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].data_type = SUBSENTENCE + '+' + \
                                                                                      vg.vrb_sub_sentence[len(
                                                                                          vg.vrb_sub_sentence) - 1].data_type
                        if w[0] == ':':
                            vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].aim = w[1:]
                        else:
                            vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].aim = w
                    else:
                        #Exception for which
                        vg.vrb_sub_sentence = vg.vrb_sub_sentence + [
                            analyse_sentence.w_quest_which(W_QUESTION, 'choice', ['the'] + subsentence)]
                        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].data_type = SUBSENTENCE + '+' + \
                                                                                      vg.vrb_sub_sentence[len(
                                                                                          vg.vrb_sub_sentence) - 1].data_type
                        vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].aim = w

                    #If 'but' is between 2 nominal group and not before subsentence
                    if w == 'but':
                        #If the main verb is not a verb but a part of verbal structure => we have nominal groups
                        for k in ['.', '?', '!', ''] + ResourcePool().proposals:
                            if not vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].sv \
                                or \
                                            vg.vrb_sub_sentence[len(vg.vrb_sub_sentence) - 1].sv[0].vrb_main[0] == k:
                                #We make changes and return the sentence with but of nominal groups
                                phrase[phrase.index(w)] = ':but'
                                vg.vrb_sub_sentence = vg.vrb_sub_sentence[:len(vg.vrb_sub_sentence) - 1]
                                return phrase

                    #We delete the subsentence
                    phrase = phrase[:begin_pos] + phrase[begin_pos + end_pos:] + ['.']
                    return phrase
    return phrase
Exemplo n.º 47
0
def other_sentence(type, request, sentence):
    """
    process the other from of a sentence                                
    Input=type and requesting of sentence and the sentence                               
    Output=class Sentence                                                            
    """

    #init
    vg = VerbalGroup([], [], '', [], [], [], [], VerbalGroup.affirmative, [])
    analysis = Sentence(type, request, [], [])
    modal = []

    if not sentence:
        return []

    #We have to add punctuation if there is not
    if sentence[len(sentence) - 1] not in ['.', '?', '!']:
        sentence = sentence + ['.']

    #We start with determination of probably second verb in subsentence
    sentence = other_functions.find_scd_verb_sub(sentence)

    #We search the subject
    sbj = analyse_nominal_group.find_sn_pos(sentence, 0)

    if sbj != [] or type == RELATIVE:
        #If we haven't a data type => it is a statement
        if type == '':
            analysis.data_type = STATEMENT


        #We have to separate the case using these, this or there
        if sentence[0] in ResourcePool().demonstrative_det and analyse_verb.infinitive([sentence[1]],
                                                                                       'present simple') == ['be']:
            #We recover this information and remove it
            analysis.sn = [NominalGroup([sentence[0]], [], [], [], [])]
            if sentence[0] == 'there' and sentence[1] == 'are':
                analysis.sn[0]._quantifier = 'SOME'
            sentence = sentence[1:]

        if not analysis.sn:
            #We recover the subject
            sentence = analyse_nominal_structure.recover_ns(sentence, analysis, 0)

        #End of the sentence? -> nominal sentence
        if sentence == [] or sentence[0] in ['.', '!', '?']:
            analysis.sv = []
            return analysis

        #We have to know if there is a modal
        if sentence[0] in ResourcePool().modal:
            modal = sentence[0]
            if modal == 'can' or modal == 'must' or modal == 'shall' or modal == 'may':
                sentence = sentence[1:]

        #We must take into account all possible cases to recover the sentence's tense
        if len(sentence) > 1 and sentence[1] == 'not':
            vg.state = VerbalGroup.negative

            #Before the negative form we have an auxiliary for the negation
            if sentence[0] == 'do' or sentence[0] == 'does' or sentence[0] == 'did':
                vg.vrb_tense = analyse_verb.find_tense_statement([sentence[0]])
                sentence = sentence[2:]
                sentence = analyse_verbal_structure.delete_unusable_word(sentence)
                sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

            #There is a modal
            elif modal:
                sentence = [sentence[0]] + sentence[2:]
                sentence = analyse_verbal_structure.delete_unusable_word(sentence)
                sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
                vg.vrb_tense = analyse_verb.find_tense_statement(sentence)

            else:
                #We remove 'not' and find the tense
                sentence = sentence[:1] + sentence[2:]
                sentence = analyse_verbal_structure.delete_unusable_word(sentence)
                sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
                vg.vrb_tense = analyse_verb.find_tense_statement(sentence)

        #For the affirmative processing
        else:
            if sentence[0] == 'not':
                vg.state = VerbalGroup.negative
                sentence = sentence[1:]

            sentence = analyse_verbal_structure.delete_unusable_word(sentence)
            sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
            vg.vrb_tense = analyse_verb.find_tense_statement(sentence)

        verb = analyse_verb.find_verb_statement(sentence, vg.vrb_tense)
        verb_main = analyse_verb.return_verb(sentence, verb, vg.vrb_tense)
        vg.vrb_main = [other_functions.convert_to_string(verb_main)]

        #We delete the verb
        sentence = sentence[sentence.index(verb[0]) + len(verb_main):]

        #We perform the processing with the modal
        if modal:
            vg.vrb_main = [modal + '+' + vg.vrb_main[0]]

    #This is a imperative form
    else:
        #re-init
        analysis.data_type = IMPERATIVE
        vg.vrb_tense = 'present simple'

        if sentence[0] in ResourcePool().proposals:
            sentence = ['.'] + sentence

        #Negative form
        if sentence[1] == 'not':
            sentence = sentence[sentence.index('not') + 1:]
            sentence = analyse_verbal_structure.delete_unusable_word(sentence)
            sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)
            vg.state = VerbalGroup.negative
        else:
            sentence = analyse_verbal_structure.delete_unusable_word(sentence)
            sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

        #We process the verb
        verb = [sentence[0]]
        verb_main = analyse_verb.return_verb(sentence, verb, vg.vrb_tense)
        vg.vrb_main = [other_functions.convert_to_string(verb_main)]

        #We delete the verb
        sentence = sentence[sentence.index(verb[0]) + len(verb_main):]

    if sentence and sentence[-1] == '?':
        analysis.data_type = YES_NO_QUESTION

    #We recover the conjunctive subsentence
    sentence = analyse_verbal_structure.process_conjunctive_sub(sentence, vg)

    #It verifies if there is a secondary verb
    sec_vrb = analyse_verbal_structure.find_scd_vrb(sentence)
    if sec_vrb:
        sentence = analyse_verbal_structure.process_scd_sentence(sentence, vg, sec_vrb)

    #We recover the subsentence
    sentence = analyse_verbal_structure.process_subsentence(sentence, vg)

    if sentence != [] and vg.vrb_main != []:
        #Process relative changes
        sentence = analyse_verbal_structure.correct_i_compl(sentence, vg.vrb_main[0])

    sentence = analyse_verbal_structure.process_compare(sentence, vg)

    sentence = analyse_nominal_group.find_plural(sentence)
    #We recover the direct, indirect complement and the adverbial
    sentence = analyse_verbal_structure.recover_obj_iobj(sentence, vg)

    #We have to take off abverbs form the sentence
    sentence = analyse_verbal_structure.find_adv(sentence, vg)

    #In case there is a state verb followed by an adjective
    sentence = analyse_verbal_structure.state_adjective(sentence, vg)

    #If there is a forgotten
    sentence = analyse_verbal_structure.find_vrb_adv(sentence, vg)

    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    while len(sentence) > 1:
        stc = analyse_verbal_structure.create_nom_gr(sentence, request)
        #We recover the direct, indirect complement and the adverbial
        stc = analyse_verbal_structure.recover_obj_iobj(stc, vg)
        if stc == sentence:
            #We leave the loop
            break
        else:
            sentence = stc

    vg = analyse_verbal_structure.refine_indirect_complement(vg)
    vg = analyse_verbal_structure.refine_subsentence(vg)
    vg = analyse_verbal_structure.DOC_to_IOC(vg)

    analysis.sv = [vg]
    return analysis
Exemplo n.º 48
0
def recover_obj_iobj(phrase, vg):
    """
    finds the direct, indirect object and the adverbial                
    We, also, put these information in the class                                     
    Input=sentence and verbal class              Output=sentence and verbal class    
    """

    #init
    conjunction = 'AND'

    object = analyse_nominal_group.find_sn(phrase)

    if phrase and \
            not object and \
                    phrase[0] in ResourcePool().adverbs_at_end:
        vg.advrb = [phrase[0]]

    while object:

        #If it is not a direct object => there is a proposal
        proposal = check_proposal(phrase, object)

        if proposal:

            gr_nom_list = []
            #This 'while' is for duplicate with 'and'
            while object:
                pos_object = phrase.index(object[0])

                #We refine the nominal group if there is an error like ending with question mark
                object = analyse_nominal_group.refine_nom_gr(object)

                #Recovering nominal group
                gr_nom_list = gr_nom_list + [
                    analyse_nominal_structure.fill_nom_gr(
                        phrase, object, pos_object, conjunction)
                ]

                #We take off the nominal group
                phrase = analyse_nominal_group.take_off_nom_gr(
                    phrase, object, pos_object)
                #We will take off the proposal
                phrase = phrase[:phrase.index(proposal[0])] + phrase[
                    phrase.index(proposal[0]) + 1:]
                conjunction = 'AND'

                #If there is a relative
                begin_pos_rel = analyse_nominal_group.find_relative(
                    object, phrase, pos_object,
                    ResourcePool().relatives)

                if begin_pos_rel != -1:
                    end_pos_rel = other_functions.recover_end_pos_sub(
                        phrase,
                        ResourcePool().relatives)
                    #We remove the relative part of the phrase
                    phrase = phrase[:begin_pos_rel] + phrase[end_pos_rel:]

                #If there is 'and', we need to duplicate the information with the proposal if there is
                if len(phrase) != 0 and (phrase[0] == 'and' or phrase[0]
                                         == 'or' or phrase[0] == ':but'):

                    phrase = [phrase[0]] + analyse_nominal_group.find_plural(
                        phrase[1:])

                    #We have not duplicate the proposal, it depends on the presence of the nominal group after
                    if analyse_nominal_group.find_sn_pos(phrase, 1):
                        phrase = [phrase[0]] + proposal + phrase[1:]
                    else:
                        phrase = [phrase[0]] + phrase[1:]

                    object = analyse_nominal_group.find_sn_pos(phrase[1:], 0)

                    #We process the 'or' like the 'and' and remove it
                    if phrase[0] == 'or':
                        conjunction = 'OR'
                    elif phrase[0] == ':but':
                        conjunction = 'BUT'
                    else:
                        conjunction = 'AND'
                    phrase = phrase[1:]

                else:
                    object = []

            vg.i_cmpl = vg.i_cmpl + [IndirectComplement(proposal, gr_nom_list)]

        else:
            #It is a direct complement
            gr_nom_list = []
            #It reproduces the same code as above
            while object:
                pos_object = phrase.index(object[0])

                #We refine the nominal group if there is an error like ending with question mark
                object = analyse_nominal_group.refine_nom_gr(object)

                #Recovering nominal group
                gr_nom_list = gr_nom_list + [
                    analyse_nominal_structure.fill_nom_gr(
                        phrase, object, pos_object, conjunction)
                ]

                #We take off the nominal group
                phrase = analyse_nominal_group.take_off_nom_gr(
                    phrase, object, pos_object)
                conjunction = 'AND'

                #If there is a relative
                begin_pos_rel = analyse_nominal_group.find_relative(
                    object, phrase, pos_object,
                    ResourcePool().relatives)

                if begin_pos_rel != -1:
                    end_pos_rel = other_functions.recover_end_pos_sub(
                        phrase,
                        ResourcePool().relatives)
                    #We remove the relative part of the phrase
                    phrase = phrase[:begin_pos_rel] + phrase[end_pos_rel:]

                if len(phrase) != 0 and (phrase[0] == 'and' or phrase[0]
                                         == 'or' or phrase[0] == ':but'):

                    phrase = [phrase[0]] + analyse_nominal_group.find_plural(
                        phrase[1:])
                    object = analyse_nominal_group.find_sn_pos(phrase[1:], 0)

                    #We process the 'or' like the 'and' and remove it
                    if phrase[0] == 'or':
                        conjunction = 'OR'
                    elif phrase[0] == ':but':
                        conjunction = 'BUT'
                    else:
                        conjunction = 'AND'
                    phrase = phrase[1:]

                else:
                    object = []

            #In a sentence there is just one direct complement if there is no second verb
            if not vg.d_obj:
                vg.d_obj = gr_nom_list
            else:
                #Else the first nominal group found is indirect and this one is direct complement
                vg.i_cmpl = vg.i_cmpl + [IndirectComplement([], vg.d_obj)]
                vg.d_obj = gr_nom_list

        #If the last nominal group is followed by another one in plural form
        phrase = analyse_nominal_group.find_plural(phrase)
        object = analyse_nominal_group.find_sn(phrase)

    return phrase