예제 #1
0
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]
예제 #2
0
def generateFeatures(filename, label, vocabList, X, y, Xtest, ytest):
    input = open(filename)
    sentences = pickle.load(input)
    input.close()
    # 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
예제 #3
0
def generateFeatures(filename,label,vocabList,X,y,Xtest,ytest):
    input = open(filename);
    sentences = pickle.load(input)
    input.close()
    # 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
예제 #4
0
파일: twss.py 프로젝트: 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"
    else:
        return random.choice(responses) +'\n'   
예제 #5
0
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"
    else:
        return random.choice(responses) + '\n'
예제 #6
0
파일: twss.py 프로젝트: 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]
예제 #7
0
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]
예제 #8
0
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


"""