コード例 #1
0
def create_possession_claus(list):
    """
    This function create phrase with 's                                            
    Input=list of nominal group                 Output=phrase of nominal group       
    """

    #init
    i = 1
    #To take the first element
    phrase = list[i - 1]
    if list[i - 1][len(list[i - 1]) - 1].endswith('s'):
        phrase[len(phrase) - 1] += "'"
    else:
        phrase[len(phrase) - 1] += "'s"

    #We concatenate
    while i < len(list):

        if other_functions.find_cap_lettre(list[i][0]) == 1:
            phrase = phrase + list[i]
        else:
            phrase = phrase + list[i][1:]

        if list[i][len(list[i]) - 1].endswith('s'):
            phrase[len(phrase) - 1] += "'"
        else:
            phrase[len(phrase) - 1] += "'s"

        i += 1

    #To remove the 's of the last word in the sentence
    word = phrase[len(phrase) - 1]
    word = word[:len(word) - 2]
    phrase[len(phrase) - 1] = word
    return phrase
コード例 #2
0
ファイル: utterance_rebuilding.py プロジェクト: Kuew/dialogs
def create_possession_claus(list):
    """
    This function create phrase with 's                                            
    Input=list of nominal group                 Output=phrase of nominal group       
    """

    #init
    i = 1
    #To take the first element
    phrase = list[i - 1]
    if list[i - 1][len(list[i - 1]) - 1].endswith('s'):
        phrase[len(phrase) - 1] += "'"
    else:
        phrase[len(phrase) - 1] += "'s"

    #We concatenate
    while i < len(list):

        if other_functions.find_cap_lettre(list[i][0]) == 1:
            phrase = phrase + list[i]
        else:
            phrase = phrase + list[i][1:]

        if list[i][len(list[i]) - 1].endswith('s'):
            phrase[len(phrase) - 1] += "'"
        else:
            phrase[len(phrase) - 1] += "'s"

        i += 1

    #To remove the 's of the last word in the sentence
    word = phrase[len(phrase) - 1]
    word = word[:len(word) - 2]
    phrase[len(phrase) - 1] = word
    return phrase
コード例 #3
0
def possesion_form(sentence):
    """
    This function converts 'of' to possession form 's                                 
    Input=sentence                                     Output=sentence               
    """

    #init
    begin_pos = 0
    flag = 0

    while begin_pos < len(sentence):

        if sentence[begin_pos] == 'of' and sentence[begin_pos - 1] == 'kind':
            if sentence[begin_pos + 1] in ResourcePool().determinants:
                sentence = sentence[:begin_pos + 1] + sentence[begin_pos + 2:]
                begin_pos += 1

        if sentence[begin_pos] == 'of' and \
                        sentence[begin_pos - 1] != 'think' and \
                        find_sn_pos(sentence, begin_pos + 1) != [] and \
                        sentence[begin_pos + 1] != 'thing':
            #We have to find the first nominal group
            nom_gr = find_sn_pos(sentence, begin_pos)

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

                nom_gr = find_sn_pos(sentence, begin_pos)
                flag = 1

            #If flag=1 => there is a proper name so we haven't decrement the begin_pos
            if flag == 0:
                while not nom_gr:
                    begin_pos -= 1
                    nom_gr = find_sn_pos(sentence, begin_pos)
            else:
                #If there is a proper name, begin_pos is wrong, we have to increment
                begin_pos += 1
                flag = 0

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

        begin_pos += 1

    return sentence
コード例 #4
0
ファイル: utterance_rebuilding.py プロジェクト: Kuew/dialogs
def possesion_form(sentence):
    """
    This function converts 'of' to possession form 's                                 
    Input=sentence                                     Output=sentence               
    """

    #init
    begin_pos = 0
    flag = 0

    while begin_pos < len(sentence):

        if sentence[begin_pos] == 'of' and sentence[begin_pos - 1] == 'kind':
            if sentence[begin_pos + 1] in ResourcePool().determinants:
                sentence = sentence[:begin_pos + 1] + sentence[begin_pos + 2:]
                begin_pos += 1

        if sentence[begin_pos] == 'of' and \
                        sentence[begin_pos - 1] != 'think' and \
                        find_sn_pos(sentence, begin_pos + 1) != [] and \
                        sentence[begin_pos + 1] != 'thing':
            #We have to find the first nominal group
            nom_gr = find_sn_pos(sentence, begin_pos)

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

                nom_gr = find_sn_pos(sentence, begin_pos)
                flag = 1

            #If flag=1 => there is a proper name so we haven't decrement the begin_pos
            if flag == 0:
                while not nom_gr:
                    begin_pos -= 1
                    nom_gr = find_sn_pos(sentence, begin_pos)
            else:
                #If there is a proper name, begin_pos is wrong, we have to increment
                begin_pos += 1
                flag = 0

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

        begin_pos += 1

    return sentence
コード例 #5
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]
コード例 #6
0
ファイル: utterance_rebuilding.py プロジェクト: Kuew/dialogs
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]