Beispiel #1
0
def doge_response(sentence, word_POS_freqs, transition_probs):
    sen_list = makelist(sentence)
    c = return_max(collapse, sentence, word_POS_freqs, transition_probs)
    # for e in c: print(e)
    important = set(["nn", "nn$", "nnS", "nns$", "np", "np$", "nps", "nps$", "nr"])
    others = set(["jj", "jjr", "jjs", "jjt"])
    stockphrases = [" Such ", " Very ", " Many ", " Wow ", " OMG ", " how to "]
    say = []
    for i in range(len(c)):
        # print (i in important)
        if c[i] in others:
            say.append(sen_list[i])
            # print("checking")
        if c[i] in important:
            for j in wikiscraping(sen_list[i]):
                say.append(j)
            # print("checking")

    def pickrand(list):
        return list[random.randint(0, len(list))]

    return c

    def generate(n, stock, say):
        response = ""
        for i in range(n):
            response += stock[random.randint(0, len(stock) - 1)] + say[random.randint(0, len(say) - 1)] + "."
        response += " Amaze!"
        return response

    if len(say) == 0:
        return "Wow, Amaze! Many brilliant"
    else:
        return generate(min(3, len(say)), stockphrases, say)
Beispiel #2
0
def collapse (sentence, word_POS_freqs, transition_probs):
    sen_list = makelist(sentence)
    print (sen_list)
    POS_combinations = list(iterate(sentence, word_POS_freqs, POS_basefreqs))
    numbers = [(calc_transition_prob(POS_combo, transition_probs)
                        * calc_base_prob(sen_list, POS_combo, word_POS_freqs))
               for POS_combo in POS_combinations]
    for i in range(min(len(list(POS_combinations)) -1, 100)): print(numbers[i])
    return dict(zip(POS_combinations, numbers))
Beispiel #3
0
def iterate(sentence, dictionary, partset):
    return itertoolsproduct(*(dictionary.get(word, partset).keys() for word in makelist(sentence)))
Beispiel #4
0
def greedy (sentence, word_POS_freqs, transition_probs, all_POS):
    POS_basefreqs = init_normalize(all_POS)
    sen_list = makelist(sentence)
    POS_combinations = iterate(sentence, word_POS_freqs, POS_basefreqs)
    return dict(zip(POS_combinations, [calc_base_prob(sen_list, POS_combo, word_POS_freqs)
               for POS_combo in POS_combinations]))