def rate(review): review = SVM.asciify(review) inputData = [] # 1st element = bayes with unigram bayesClassifier.loadData("U") inputData.append(bayesClassifier.percentPositive(review)) # bayes with adjective bayesClassifier.loadData("A") inputData.append(bayesClassifier.percentPositive(review)) # bayes with POS bayesClassifier.loadData("P") bayesClassifier.partOfSpeech = True inputData.append(bayesClassifier.percentPositive(review)) # SVM with unigram review = review.split() SVM.loadModule("U") SVM.loadWords("U") X = SVM.intersection(SVM.wordList, review) # SVM with adjective inputData.append(SVM.movieReviewer.predict(X)[0]) SVM.loadModule("A") SVM.loadWords("A") X = SVM.intersection(SVM.wordList, review) inputData.append(SVM.movieReviewer.predict(X)[0]) return Tree.predict(inputData)[0]
from sys import argv os.system("echo -n 'loading keywords...\t\t'") SVM.loadModule(argv[1]) SVM.loadWords(argv[1]) os.system("echo -n '[done]\n'") os.system("echo -n 'testing files:\n[00%'") files = os.listdir('./test/pos')[:3000] total = float(len(files)) * 2 done = 0 progress = 0 correct = 0 for i in files: f = SVM.asciify(open('./test/pos/' + i, 'r').read()).split() result = SVM.movieReviewer.predict(SVM.intersection(SVM.wordList, f))[0] if result > 0: correct += 1 done += 1 if (done / total * 100 >= progress + 5): progress += 5 #os.system("echo -n '\b\b\b=%2d%%'" % progress) files = os.listdir('./test/neg')[:3000] for i in files: f = SVM.asciify(open('./test/neg/' + i, 'r').read()).split() result = SVM.movieReviewer.predict(SVM.intersection(SVM.wordList, f))[0] if result < 0: correct += 1