示例#1
0
def find_sn_pos(phrase, begin_pos):
    """
    We will find the nominal group which is in a known position                      
    We have to use adjective_pos to return the end position of nominal group         
    Input=the sentence (list of strings) and the position of the nominal group       
    Output=the nominal group                                                         
    """

    if begin_pos >= len(phrase):
        return []

    end_pos = 1

    #If it is a pronoun
    if phrase[begin_pos] in ResourcePool().pronouns:
        return [phrase[begin_pos]]

    #If there is a nominal group with determinant
    if phrase[begin_pos] in ResourcePool().determinants:
        end_pos += adjective_pos(phrase, begin_pos + 1)
        return phrase[begin_pos:end_pos + begin_pos]

    #If we have 'something'
    for k in ResourcePool().composed_nouns:
        if phrase[begin_pos].startswith(k):
            if phrase[begin_pos] in ResourcePool().noun_not_composed:
                return []
            return [phrase[begin_pos]]

            #If there is a number, it will be the same with determinant
    if other_functions.number(phrase[begin_pos]) == 1:
        end_pos += adjective_pos(phrase, begin_pos + 1)
        return phrase[begin_pos:end_pos + begin_pos]

    #If it is a proper name
    counter = begin_pos
    while counter < len(phrase) and other_functions.find_cap_lettre(
            phrase[counter]) == 1:
        counter += 1

    #Default case return [] => ok if counter=begin_pos
    return phrase[begin_pos:counter]
示例#2
0
def find_sn_pos(phrase, begin_pos):
    """
    We will find the nominal group which is in a known position                      
    We have to use adjective_pos to return the end position of nominal group         
    Input=the sentence (list of strings) and the position of the nominal group       
    Output=the nominal group                                                         
    """

    if begin_pos >= len(phrase):
        return []

    end_pos = 1

    #If it is a pronoun
    if phrase[begin_pos] in ResourcePool().pronouns:
        return [phrase[begin_pos]]

    #If there is a nominal group with determinant
    if phrase[begin_pos] in ResourcePool().determinants:
        end_pos += adjective_pos(phrase, begin_pos + 1)
        return phrase[begin_pos: end_pos + begin_pos]

    #If we have 'something'
    for k in ResourcePool().composed_nouns:
        if phrase[begin_pos].startswith(k):
            if phrase[begin_pos] in ResourcePool().noun_not_composed:
                return []
            return [phrase[begin_pos]]

            #If there is a number, it will be the same with determinant
    if other_functions.number(phrase[begin_pos]) == 1:
        end_pos += adjective_pos(phrase, begin_pos + 1)
        return phrase[begin_pos: end_pos + begin_pos]

    #If it is a proper name
    counter = begin_pos
    while counter < len(phrase) and other_functions.find_cap_lettre(phrase[counter]) == 1:
        counter += 1

    #Default case return [] => ok if counter=begin_pos
    return phrase[begin_pos: counter]
示例#3
0
def adjective_pos(phrase, word_pos):
    """
    returns the position of the end of the nominal group                
    We have to use the list of irregular adjectives                                  
    Input=the sentence (list of strings) and the position of the first adjective    
    Output=the position of the last word of the nominal group                       
    """

    #If it is the end of the phrase
    if len(phrase) - 1 <= word_pos:
        return 1

    #The case of '2 of them'
    if phrase[word_pos] == 'of':
        return 0

    #It is a noun so we have to return 1
    if phrase[word_pos] in ResourcePool().special_nouns:
        return 1

    #For the regular adjectives
    for k in ResourcePool().adjective_rules:
        if phrase[word_pos].endswith(k):
            return 1 + adjective_pos(phrase, word_pos + 1)

    #For adjectives created from numbers
    if phrase[word_pos].endswith('th') and other_functions.number(
            phrase[word_pos]) == 2:
        return 1 + adjective_pos(phrase, word_pos + 1)

    #We use the irregular adjectives list to find it
    if phrase[word_pos] in list(ResourcePool().adjectives.keys(
    )) + ResourcePool().adjective_numbers + ResourcePool().adj_quantifiers:
        return 1 + adjective_pos(phrase, word_pos + 1)

    #Default case
    return 1
示例#4
0
def adjective_pos(phrase, word_pos):
    """
    returns the position of the end of the nominal group                
    We have to use the list of irregular adjectives                                  
    Input=the sentence (list of strings) and the position of the first adjective    
    Output=the position of the last word of the nominal group                       
    """

    #If it is the end of the phrase
    if len(phrase) - 1 <= word_pos:
        return 1

    #The case of '2 of them'
    if phrase[word_pos] == 'of':
        return 0

    #It is a noun so we have to return 1
    if phrase[word_pos] in ResourcePool().special_nouns:
        return 1

    #For the regular adjectives
    for k in ResourcePool().adjective_rules:
        if phrase[word_pos].endswith(k):
            return 1 + adjective_pos(phrase, word_pos + 1)

    #For adjectives created from numbers
    if phrase[word_pos].endswith('th') and other_functions.number(phrase[word_pos]) == 2:
        return 1 + adjective_pos(phrase, word_pos + 1)

    #We use the irregular adjectives list to find it
    if phrase[word_pos] in list(
            ResourcePool().adjectives.keys()) + ResourcePool().adjective_numbers + ResourcePool().adj_quantifiers:
        return 1 + adjective_pos(phrase, word_pos + 1)

    #Default case
    return 1