Пример #1
0
import pickle
from Iteration import iterate
from Iteration import init_normalize
from sentenceparsing import makelist
from collapse import collapse
from Return_max import return_max
from wikiscraping import wikiscraping
import random

all_POS = pickle.load(open("pos.p", "r"))
POS_basefreqs = init_normalize(all_POS)


word_POS_freqs = pickle.load(open("words.p", "r"))
transition_probs = pickle.load(open("combos.p", "r"))

# This should be added to the basic transition_probs dictionary source
# transition_probs.update({('', '') : 1})
# transition_probs.update({('', pos) : 1 for pos in all_POS})
# transition_probs.update({(pos, '') : 1 for pos in all_POS})


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)):
Пример #2
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]))