import codecs
import re
originalsegmentation=codecs.open('finalSegmentation.txt', 'r', encoding='utf-8')
f1=originalsegmentation.read()
lines1=f1.split('\n')
handsegmentation=codecs.open('arpit_ground_truth.txt', 'r', encoding='utf-8')
f2=handsegmentation.read()
handsegmentation.close()
originalsegmentation.close()
lines2=f2.split('\n')
fi=codecs.open('new.txt', 'w', encoding='utf-8')
a,b,c=0,0,0
for line2 in lines2:
	flag=0
	word2=line2.split(':')[0]
	for line1 in lines1:
		word1=line1.split(':')[0]
		if(word2==word1):
			fi.write(line1+'\n')
			flag=1
			break
	if flag==0:
		fi.write(word2+':\n')
def compare(str1, str2, wordlength):
		a_1,a_2,tp,b_1,b_2=0,0,0,0,0
		global a
		global b
		global c
		for i in range(0,wordlength):
			if str1[i+b_1]=='+'and str2[i+b_2]=='+':
				b_1=b_1+1
				b_2=b_2+1
				tp=tp+1
			elif (str1[i+b_1]=='+'and str2[i+b_2]!='+'):
				b_1=b_1+1
				a_1=a_1+1
			elif (str1[i+b_1]!='+'and str2[i+b_2]=='+'):
				b_2=b_2+1
				a_2=a_2+1
		a=a+tp
		b=b+a_1
		c=c+a_2
a_11=codecs.open('new.txt', 'r', encoding='utf-8')
f1=a_11.read()
lines1=f1.split('\n')
a_12=codecs.open('arpit_ground_truth.txt', 'r', encoding='utf-8')
f2=a_12.read()
lines2=f2.split('\n')
for i in enumerate(lines1):
	temp1=lines1[i[0]]
	temp2=lines2[i[0]]
	word1=temp1.split(':')[-1]
	word2=temp2.split(':')[-1]
	wordlength=min(len(lines1[i[0]].split(':')[0]),len(lines2[i[0]].split('\t')[0]))
	if word1 =='':	
		continue
	compare(word1, word2, wordlength)
print(a)
print(b)
print(c)
a_11.close()
a_12.close()
