#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import unicodedata
g=open('output.txt','r')
h=open('hindi2.txt','r')
p=0.0
extra=0.0
remove=0.0
accurate=0.0
for line in h:
	o_word=line.split(":")[0]
	s_word=line.split(":")[1]
	matched_line=""
	f=0
	f1=0
	for line2 in f:
		segment_word=line2.split(":")[0]
		#if (word0.decode(encoding='UTF-8')==check_line.decode(encoding='UTF-8')) :
		if ((o_word)==(segment_word)) :
			f=2
		
		if f>1:
			matched_words=line2
			break
		else:
			continue
	if f==0:
		continue
	hand_annotated=s_word.split("+")
	matched_words2=matched_words.split(":")[1]
	segmented=matched_words2.split("+")
	if len(segmented)==len(hand_annotated):
		for i in range(0,len(segmented)):
			if len(segmented[i])==len(hand_annotated[i]):
				p=p+1
				f1=f1+1
			elif len(segmented[i])<len(hand_annotated[i]):
				extra=extra+1
			elif len(segmented[i])>len(hand_annotated[i]):
					remove=remove+1
			if f1==len(segmented):
				accurate=accurate+1
	else:
			#remove=(len(segmented)-len(hand_annotated))+remove
			if len(segmented)<len(hand_annotated):
				for i in range(0,len(segmented)):
					if len(segmented[i])==len(hand_annotated[i]):
						p=p+1
						f1=f1+1
					elif len(segmented[i])<len(hand_annotated[i]):
						extra=extra+1
					elif len(segmented[i])>len(hand_annotated[i]):
						remove=remove+1
			#extra=(len(hand_annotated)-len(segmented))+extra
			elif len(segmented)>len(hand_annotated):
				for i in range(0,len(hand_annotated)):
					if len(segmented[i])==len(hand_annotated[i]):
						p=p+1
						f1=f1+1
					elif len(segmented[i])<len(hand_annotated[i]):
						extra=extra+1
					elif len(segmented[i])>len(hand_annotated[i]):
						remove=remove+1
			else:
				print line
Precision =float((p)/(p+extra))
Recall = float((p) / (p+remove) )
Fscore = float((2*p) / (2*p+extra+remove))

print Precision
print Recall
print Fscore
