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
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
def fill_nom_gr(phrase, nom_gr, pos_nom_gr, conjunction):
    """Fills a structure Nominal_Group with given information

    param: list phrase: the raw sentence
    param: nom_gr: the nominal group
    param: pos_nom_gr: its position
    param: conjunction: 'and', 'or' or 'but'

    :return: the nominal group class
    """

    #init
    relative = []

    #We start by recovering all information we need
    nom_gr_compl = analyse_nominal_group.find_nom_gr_compl(nom_gr, phrase, pos_nom_gr)
    det = analyse_nominal_group.return_det(nom_gr)
    adj = analyse_nominal_group.return_adj(nom_gr)
    adj = analyse_nominal_group.convert_adj_to_digit(adj)
    noun = analyse_nominal_group.return_noun(nom_gr, adj, det)
    adj = analyse_nominal_group.process_adj_quantifier(adj)

    #We process the relative
    begin_pos_rel = analyse_nominal_group.find_relative(nom_gr, phrase, pos_nom_gr, ResourcePool().relatives)
    end_pos_rel = other_functions.recover_end_pos_sub(phrase[begin_pos_rel:], ResourcePool().relatives)

    #There is a relative
    if begin_pos_rel != -1:
        relative_phrase = phrase[begin_pos_rel + 1:begin_pos_rel + end_pos_rel - 1]
        relative_phrase = other_functions.recover_scd_verb_sub(relative_phrase)

        #If it is a place, we have not to duplicate the nominal group
        if phrase[begin_pos_rel] != 'where':
            relative_phrase = analyse_nominal_group.complete_relative(relative_phrase, nom_gr)

        relative = relative + [analyse_sentence.other_sentence(RELATIVE, phrase[begin_pos_rel], relative_phrase)]

    #If there is a nom_gr_compl, we must make a recursive process for embedded complement
    if nom_gr_compl:
        gn = Nominal_Group(det, noun, adj, [fill_nom_gr(phrase, nom_gr_compl, pos_nom_gr + len(nom_gr) + 1, 'AND')],
                           relative)

    else:
        gn = Nominal_Group(det, noun, adj, [], relative)

    #We recover the conjunction
    gn._conjunction = conjunction

    #We recover the quantifier
    recover_quantifier(gn)

    gn = put_rela_from_nncompl_noun(gn)
    return gn
def fill_nom_gr(phrase, nom_gr, pos_nom_gr, conjunction):
    """Fills a structure NominalGroup with given information

    param: list phrase: the raw sentence
    param: nom_gr: the nominal group
    param: pos_nom_gr: its position
    param: conjunction: 'and', 'or' or 'but'

    :return: the nominal group class
    """

    #init
    relative = []

    #We start by recovering all information we need
    nom_gr_compl = analyse_nominal_group.find_nom_gr_compl(nom_gr, phrase, pos_nom_gr)
    det = analyse_nominal_group.return_det(nom_gr)
    adj = analyse_nominal_group.return_adj(nom_gr)
    adj = analyse_nominal_group.convert_adj_to_digit(adj)
    noun = analyse_nominal_group.return_noun(nom_gr, adj, det)
    adj = analyse_nominal_group.process_adj_quantifier(adj)

    #We process the relative
    begin_pos_rel = analyse_nominal_group.find_relative(nom_gr, phrase, pos_nom_gr, ResourcePool().relatives)
    end_pos_rel = other_functions.recover_end_pos_sub(phrase[begin_pos_rel:], ResourcePool().relatives)

    #There is a relative
    if begin_pos_rel != -1:
        relative_phrase = phrase[begin_pos_rel + 1:begin_pos_rel + end_pos_rel - 1]
        relative_phrase = other_functions.recover_scd_verb_sub(relative_phrase)

        #If it is a place, we have not to duplicate the nominal group
        if phrase[begin_pos_rel] != 'where':
            relative_phrase = analyse_nominal_group.complete_relative(relative_phrase, nom_gr)

        relative = relative + [analyse_sentence.other_sentence(RELATIVE, phrase[begin_pos_rel], relative_phrase)]

    #If there is a nom_gr_compl, we must make a recursive process for embedded complement
    if nom_gr_compl:
        gn = NominalGroup(det, noun, adj, [fill_nom_gr(phrase, nom_gr_compl, pos_nom_gr + len(nom_gr) + 1, 'AND')],
                           relative)

    else:
        gn = NominalGroup(det, noun, adj, [], relative)

    #We recover the conjunction
    gn._conjunction = conjunction

    #We recover the quantifier
    recover_quantifier(gn)

    gn = put_rela_from_nncompl_noun(gn)
    return gn
Example #5
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
Example #6
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
Example #7
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
Example #8
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
Example #9
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
Example #10
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
Example #11
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
Example #12
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