// File: aleperno[P]Datos/main.cpp
// Function: main
int main( int argc, char* args[] ) {

	//Se le pasará como argumento el archivo labeledTrainData.tsv (preparseado).
	char* learningPath = args[1];

	// path de análisis
	char* testPath = args[2];

	//El valor con el que se inicializara los pesos del perceptron
	float init = atoi(args[3]);

	// Metodo Perceptron
	unsigned int hash_size = pow(2,25);
	float learning_rate = 0.1 * log(2);
	HashingPerceptron* perceptron = new HashingPerceptron(learningPath,3, learning_rate ,hash_size,init);

	//Levanto y parseo el archivo a analizar
	//Parser* parser = new Parser();

	//ifstream testfile;
	//testfile.open(testPath);

	/*
	vector<string> id_reviews;
	vector<float> scoresP;
	//Utilizo para normalizar los resultados del perceptron
	printf("Comienzo a evaluar el set de prueba\n");
	if(testfile.is_open())
	{
		string linea;
		while( getline(testfile,linea) )
		{
			vector<string> tokenized_columns = parser->tokenizeColumns(linea);
			vector<string> tokenized_words = parser->tokenizeReviews(tokenized_columns[1]); //TODO cero porque solo son strings

			id_reviews.push_back(tokenized_columns[0]);

			float score = perceptron->rate(tokenized_words);
			scoresP.push_back(score);
		}
	}
	*/
	//delete parser;
	vector<pair<string,float>> result = perceptron->rate(testPath);
	//Imprimo los resultados
	ofstream outfile("popcorn.csv");
	outfile << "\"id\",\"sentiment\"" << endl;

	for (unsigned int i=0; i < result.size(); i++)
	{
		outfile << result[i].first +"," << result[i].second <<endl;
	}
	outfile.close();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x44b0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x24(%rbp)
movl $0x2, %edi
movl %edi, -0x294(%rbp)
movl $0x19, %esi
callq 0x4ef0
movl -0x294(%rbp), %edi
cvttsd2si %xmm0, %rax
movl %eax, -0x28(%rbp)
callq 0x4f20
movsd 0x12441(%rip), %xmm1    # 0x17008
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
movl $0xa0, %edi
callq 0x42e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x290(%rbp)
movq -0x18(%rbp), %rsi
movss -0x2c(%rbp), %xmm0
movl -0x28(%rbp), %ecx
movss -0x24(%rbp), %xmm1
movl $0x3, %edx
callq 0xda90
jmp 0x4c08
movq -0x290(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0xedd0
leaq 0x123eb(%rip), %rsi     # 0x17016
leaq -0x260(%rbp), %rdi
movl $0x10, %edx
callq 0x4340
jmp 0x4c3e
leaq 0x123dd(%rip), %rsi     # 0x17022
leaq -0x260(%rbp), %rdi
callq 0x42d0
movq %rax, -0x2a0(%rbp)
jmp 0x4c5a
movq -0x2a0(%rbp), %rdi
movq 0x1e360(%rip), %rsi     # 0x22fc8
callq 0x4310
jmp 0x4c6f
movl $0x0, -0x264(%rbp)
movl -0x264(%rbp), %eax
movq %rax, -0x2a8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4f40
movq %rax, %rcx
movq -0x2a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x4d9a
movl -0x264(%rbp), %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x4ff0
movq %rax, %rsi
leaq 0x12353(%rip), %rdx     # 0x17010
leaq -0x288(%rbp), %rdi
callq 0x4f70
jmp 0x4ccb
leaq -0x260(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x42a0
movq %rax, -0x2b0(%rbp)
jmp 0x4ce7
movl -0x264(%rbp), %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x4ff0
movq -0x2b0(%rbp), %rdi
movss 0x20(%rax), %xmm0
callq 0x4220
movq %rax, -0x2b8(%rbp)
jmp 0x4d12
movq -0x2b8(%rbp), %rdi
movq 0x1e2a8(%rip), %rsi     # 0x22fc8
callq 0x4310
jmp 0x4d27
leaq -0x288(%rbp), %rdi
callq 0x41a0
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x4c79
movq -0x290(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x42b0
jmp 0x4de5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4ddc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4dd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x41a0
jmp 0x4dd0
leaq -0x260(%rbp), %rdi
callq 0x4460
jmp 0x4da8
movl $0x0, -0x4(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x4480
leaq -0x60(%rbp), %rdi
callq 0x5010
movl -0x4(%rbp), %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x4480
leaq -0x60(%rbp), %rdi
callq 0x5010
movq -0x40(%rbp), %rdi
callq 0x4550
nop