def binary_list(word):  # This function converts a word segmentation into 1,0 list. A + and the succeeding letter is substituted as 1 and otherwise a letter as 0.
	bin_list=[]
	flag=0
	for i in range(len(word)):
		if(word[i]==' '):
			bin_list.append(1);     
			flag=1;			
		else:
			if(flag==1):
				flag=0;
			else:
				bin_list.append(0);
	return bin_list

f="mergeresult"
list_code=[]
list_true=[]
main_list=[]
prec = 0;
rec = 0;
fscore = 0;
i=0
with open(f,'r') as f:
	for line in f:
		[word1,word2]=line.split(';');
		word2=word2[:-1]
		list1 = binary_list(word1);
		list2 = binary_list(word2);		#remove the newline character
		if(len(list1)!=len(list2)):
			continue
		else:
			i = i+1
			list_code.extend(list1);
			list_true.extend(list2);
	if len(list_code)!=len(list_true): 	# The length of of both 1-0 lists should be same. Otherwise it suggests addition or deletion of a letter in either the
		print "Error! Sizes dont match"		# manual segmentation or the segmentation by Undivided++ which is not correct
		
	else:
		for i in xrange(len(list_code)):
			if (list_code[i]==1 and list_code[i]==list_true[i]):
				main_list.append(1);
			else:
					main_list.append(0);
					
		prec = float(sum(main_list))/sum(list_code)	
		rec = float(sum(main_list))/sum(list_true)
		if (prec+rec!=0):
			fscore = 2*prec*rec/(prec+rec)
		else:
			fscore = 0
		
	print "Precision=",prec,"Recall=",rec,"F-Score=",fscore;
