Esempio n. 1
0
def classify_and_write_results(posts):
	formatter = Format()
	classifier = PostClassifier()
	output_file = raw_input("Output file (empty defaults to stdout): ")
	try:
		f = open(output_file, 'w')
	except IOError:
		print 'Invalid filename entered. Printing dumped content ... '
		f = None
	for entry in posts:
		entry.sentences = formatter.split_sentences(entry.body)
		entry.sentences = zip(
			entry.sentences, classifier.classify_sentiment(entry.sentences))
		entry.label = classifier.classify_topic_unsupervised(entry.body)
		output = '---POST---' + '\nauthor id: ' + str(entry.user_int_id) + \
			'\nclass: ' + entry.label + '\nsentences and sentiments:\n' + \
				'\n'.join(' : '.join(pair) for pair in entry.sentences)
		if (f is not None):
			f.write(output)
		else:
			print output
Esempio n. 2
0
from classify import PostClassifier

train_path = raw_input("Path to training data: ")
lower_threshold = int(raw_input("Lower threshold: "))
negative_bucket  = raw_input("Use negative bucket feature? (True/False): ") == "True"

classifier = PostClassifier()
classifier.sentiment_train(train_path, lower_threshold, negative_bucket)
while True:
	sentence = raw_input("Sentence to classify: ")
	print "Guess: " + classifier.classify_sentiment(sentence)