Exemplo n.º 1
def twss(sentence):
    x = processSentence(str(sentence), vocabList)
    old_stdout = sys.stdout
    sys.stdout = StringIO()
    p_label, p_acc, p_val = svm_predict([1], [x], model, '-b 1')
    sys.stdout = old_stdout
    return p_val[0][1]
Exemplo n.º 2
def generateFeatures(filename,label,vocabList,X,y,Xtest,ytest):
    input = open(filename);
    sentences = pickle.load(input)
    # leave last 100 for test set
    top = len(sentences)-100
    for i in range(top):
        wi = processSentence(sentences[i],vocabList)
        X = X+[wi]
        y = y+[label]
    bottom = top
    top = len(sentences)
    for i in range(bottom,top):
        wi = processSentence(sentences[i],vocabList)
        Xtest = Xtest + [wi]
        ytest = ytest + [label]
    return X,y,Xtest,ytest
Exemplo n.º 3
Arquivo: twss.py Projeto: KWMalik/twss
def twss(sentence,vocabList,model):
    #print "you said: '"+sentence+"'\n"
    # these should be moved to file
    responses = ['Whatever ...','Okay','Yawn','What makes you think I care?','Yada yada','Uhuh','Yeah, yeah','figures',"I'm hungry",'give me a break','so ...']
    x  = processSentence(sentence, vocabList)
    #print [x]
    p_label, p_acc, p_val = svm_predict([1], [x], model, '-b 1 -q')
    print p_label, p_acc, p_val
    if p_label[0] == 1:
        return "That's what she said!\n"
        return random.choice(responses) +'\n'   
Exemplo n.º 4
Arquivo: twss.py Projeto: slunk/twss
def twss_lite(sentence,vocabList,model):
    x = processSentence(sentence, vocabList)
    p_label, p_acc, p_val = svm_predict([1], [x], model, '-b 1 -q')
    return p_label[0]
Exemplo n.º 5
from processSentence import *

sent_brok = processSentence("The magician got so mad he pulled his hare out")

#print sent_brok

def sentFeat(sent):
    # Preprocessing the sentence
    sent_brok = processSentence(sent)
    # Looking whether sentence have homonym or not
    for word in sent_brok:
        for homWord in homonym:
            if homWord[1] == word:
            # search(ngram, word)
# how to get frequency

# searching ngram frequency for a word
def search(ngram_Corpus, searchFor):
    for key in ngram_Corpus:
        for value in ngram_Corpus[k]:
            if searchFor in value:
                return key
    return None