import ipdb
import data_clean
import request
import re
import numpy as np

'''
Model for determining whether a given piece of input text is sarcastic or not.
'''

def main():
	'''
		# for just the first two examples, this applies
		# # quotes_value = request.make_request(reduced_quotes)
		# # response_value = request.make_request(reduced_response)
		# quotes_value = b'{"documents":[{"score":0.8677991,"id":"0"},{"score":0.9363753,"id":"1"}],"errors":[]}'
		# response_value = b'{"documents":[{"score":0.9520152,"id":"0"},{"score":0.4560984,"id":"1"}],"errors":[]}'
		# print(quotes_value)
		# print(response_value)
	'''
	data = data_clean.clean_data()
	# print(data.shape) # should be (4692, 5)
	# ipdb.set_trace()  ######### Break Point ###########
	reduced_data = data[0:2, :] # take the first 20 examples
	reduced_quotes = reduced_data[:, 3]
	reduced_response = reduced_data[:, 4]
	save_training_data(reduced_data[:, 1], reduced_quotes, reduced_response)

def save_training_data(labels, quotes_vector, response_vector):
	'''creates a csv with some number of rows with 3 columns--the first being the label for the training example, the second as the sentiment value for the quote, and the third being the sentiment value for the response. Saves the csv file.
	'''
	num_examples = labels.size # should be same as quotes or response vector length
	quote_sentiment_vector = request.make_request(quotes_vector).decode('utf-8')
	response_sentiment_vector = request.make_request(response_vector).decode('utf-8')
	quote_sentiment_vector = np.array(re.findall('0\.[0-9]+', quote_sentiment_vector))
	response_sentiment_vector = np.array(re.findall('0\.[0-9]+', response_sentiment_vector))
	quote_sentiment_vector = np.array([float(x) for x in quote_sentiment_vector])
	response_sentiment_vector = np.array([float(x) for x in response_sentiment_vector]) # change strings to numbers
	data = np.concatenate((labels.reshape(num_examples, 1), quote_sentiment_vector.reshape(num_examples, 1), response_sentiment_vector.reshape(num_examples, 1)), axis=1)
	data = data.reshape(data.size / 3, 3)
	np.savetxt('training_data.csv', data, delimiter=',')
	return data

if __name__ == "__main__":
	main()

@@ -66,16 +66,50 @@
 py as np
+%0Afrom sklearn import SGDClassifier
 %0A%0A'''%0AMo
@@ -916,33 +916,24 @@
 :, 4%5D%0A%09save_
-training_
 data(reduced
@@ -981,28 +981,344 @@
 onse
-)%0A%0Adef save_training
+, 'training_data')%0A%09classifier = train()%0A%0A%09clf = SGDClassifier(loss=%22hinge%22, penalty=%22l2%22)%0A%09%0A%0Adef train():%0A%09file_name = 'training_data.csv'%0A%09data = pandas.read_csv('sarcasm_v2.csv').as_matrix()%0A%09labels = data%5B:, 0%5D%0A%09features = data%5B:, 1:%5D%0A%09clf = SGDClassifier(loss=%22hinge%22, penalty=%22l2%22)%0A%09clf.fit(features, labels)%0A%09return clf%0A%0Adef save
 _dat
@@ -1357,16 +1357,27 @@
 e_vector
+, file_name
 ):%0A%09'''c
@@ -2227,31 +2227,17 @@
 rs%0A%09
-data = np.concatenate((
+labels = 
 labe
@@ -2263,17 +2263,42 @@
 ples, 1)
-,
+%0A%09quote_sentiment_vector =
  quote_s
@@ -2337,17 +2337,45 @@
 ples, 1)
-,
+%0A%09response_sentiment_vector =
  respons
@@ -2417,16 +2417,446 @@
 ples, 1)
+%0A%0A%09# TODO: fix this%0A%09# # now adding polynomial features of up to degree 5.%0A%09# features = np.zeros((num_examples, 10))%0A%09# for i in range(5):%0A%09# %09features%5Bi%5D = quote_sentiment_vector ** i%0A%09# %09features%5B10 - i - 1%5D = response_sentiment_vector ** i%0A%09# data = np.concatenate((labels, quote_sentiment_vector, response_sentiment_vector, features), axis=1)%0A%0A%09data = np.concatenate((labels, quote_sentiment_vector, response_sentiment_vector
 ), axis=
@@ -2902,33 +2902,45 @@
 3)%0A%09
-np.savetxt('training_data
+print(data)%0A%09np.savetxt(file_name + '
 .csv
@@ -2967,20 +2967,8 @@
 ,')%0A
-%09return data
 %0A%0Aif

Create classifier