M1-Arborator-NaijaSUD/arborator/lib/treebankfiles.py
def checkSentence(iii,s,corrlist,rec=0):
	"""
	iii: index of sentence in the sentence list
	s: sentence in nodedic format
	rec: recursion level
	"""
	#print "_____________________________________________"
	#if rec>10:
		#print s,rec
		#1/0
	if debug: print "checking sentence",iii,"rec",rec,"len(s)",len(s)
	
	
	# TODO: kick out:
	if rec<1:
		#print "____________________________"
		#for i in s:	print i,s[i][tokenname], s[i]
		#print "____________________________"
		
		
		for i in s:
			#print s
			if "gov" in s[i]:
				for g in s[i]["gov"]:
					if s[i]["gov"][g].endswith("_invisible"):
						s[i]["gov"][g]=s[i]["gov"][g].replace("_invisible","_inherited")
	
	
	if rec<3:
				
		
		for i in sorted(s):
			
			if debug>1:
				try:
					print "checking:",i,s[i][tokenname]
					
					#s[i]
					#print s[i]["lemma"],s[i]["lemma"] in corrdic,i in s
					#print corrdic
				except:
					print "index",i,"is gone"
				#if s[i]['cat']=="unknown" and s[i][tokenname]=="d'":
				#if s[i][tokenname]==u"écrivant":
					#print "********************************************************"
					#for i in sorted(s):
						#print s[i]
					##print s
					#1/0
			#print i,s[i]		
			
			
			if i in s:
				for matchdic,insdic in corrlist:
					if unify(s[i],matchdic):
						
						
						#( s[i]["lemma"] in corrdic or s[i][tokenname] in corrdic):
						if debug>1:
							print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè"
							#if s[i]["lemma"] in corrdic : print corrdic[s[i]["lemma"]]
							#else:print corrdic[s[i][tokenname]]
							print s[i]
							print "matched oooooooooooooooooooooooooooooooo"
							print matchdic
							print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè"
						#if s[i]["lemma"] in corrdic : insdic=corrdic[s[i]["lemma"]]
						#else:insdic=corrdic[s[i][tokenname]]
						if isinstance(insdic,int):# glueing. in this case insdic contains the direction of the token glueing
							s = glue(copy.deepcopy(s),i,insdic)
							s = checkSentence(iii,copy.deepcopy(s),corrlist,rec+1)
						else:
							s = integrate(copy.deepcopy(s),i,insdic)
							if len(insdic)>1:
								s=checkSentence(iii,copy.deepcopy(s),corrlist,rec+1)
			#elif i in s and  ( s[i]["lemma"] in gluedic or s[i][tokenname] in gluedic) :
				#if debug>1:
					#print "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"
					#if s[i]["lemma"] in gluedic :print gluedic[s[i]["lemma"]]
					#else:print gluedic[s[i][tokenname]]
					#print "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg"
				#if s[i]["lemma"] in gluedic : insdic=gluedic[s[i]["lemma"]]
				#else:insdic=gluedic[s[i][tokenname]]
				#news = glue(s,i,insdic)
				#s=checkSentence(iii,news,corrlist,rec+1)
			
			
	return s

	iii: index of sentence in the sentence list
	s: sentence in nodedic format
	rec: recursion level
	
index of sentence in the sentence list
s: sentence in nodedic format
rec: recursion level
index of sentence in the sentence list s : sentence in nodedic format rec : recursion level
def checkSentence(iii,s,corrlist,rec=0):
	if debug: print "checking sentence",iii,"rec",rec,"len(s)",len(s)
	if rec<1:
		for i in s:
			if "gov" in s[i]:
				for g in s[i]["gov"]:
					if s[i]["gov"][g].endswith("_invisible"):
						s[i]["gov"][g]=s[i]["gov"][g].replace("_invisible","_inherited")
	if rec<3:
		for i in sorted(s):
			if debug>1:
				try:
					print "checking:",i,s[i][tokenname]
					[i]["lemma"],s[i]["lemma"] in corrdic,i in s
				except:
					print "index",i,"is gone"
						[i]
					#
			if i in s:
				for matchdic,insdic in corrlist:
					if unify(s[i],matchdic):
						if debug>1:
							print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè"
							print s[i]
							print "matched oooooooooooooooooooooooooooooooo"
							print matchdic
							print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè"
						if isinstance(insdic,int):
							s = glue(copy.deepcopy(s),i,insdic)
							s = checkSentence(iii,copy.deepcopy(s),corrlist,rec+1)
						else:
							s = integrate(copy.deepcopy(s),i,insdic)
							if len(insdic)>1:
								s=checkSentence(iii,copy.deepcopy(s),corrlist,rec+1)
	return s
def checkSentence ( iii , s , corrlist , rec = 0 ) : if debug : print "checking sentence" , iii , "rec" , rec , "len(s)" , len ( s ) if rec < 1 : for i in s : if "gov" in s [ i ] : for g in s [ i ] [ "gov" ] : if s [ i ] [ "gov" ] [ g ] . endswith ( "_invisible" ) : s [ i ] [ "gov" ] [ g ] = s [ i ] [ "gov" ] [ g ] . replace ( "_invisible" , "_inherited" ) if rec < 3 : for i in sorted ( s ) : if debug > 1 : try : print "checking:" , i , s [ i ] [ tokenname ] except : print "index" , i , "is gone" if i in s : for matchdic , insdic in corrlist : if unify ( s [ i ] , matchdic ) : if debug > 1 : print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè" print s [ i ] print "matched oooooooooooooooooooooooooooooooo" print matchdic print "èèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèèè" if isinstance ( insdic , int ) : s = glue ( copy . deepcopy ( s ) , i , insdic ) s = checkSentence ( iii , copy . deepcopy ( s ) , corrlist , rec + 1 ) else : s = integrate ( copy . deepcopy ( s ) , i , insdic ) if len ( insdic ) > 1 : s = checkSentence ( iii , copy . deepcopy ( s ) , corrlist , rec + 1 ) return s
iii: index of sentence in the sentence list
s: sentence in nodedic format
rec: recursion level
iii : index of sentence in the sentence list s : sentence in nodedic format rec : recursion level
"""
	iii: index of sentence in the sentence list
	s: sentence in nodedic format
	rec: recursion level
	""" #print "_____________________________________________" #if rec>10: #print s,rec #1/0 # TODO: kick out: #print "____________________________" #for i in s:	print i,s[i][tokenname], s[i] #print "____________________________" #print s #s[i] #print s[i]["lemma"],s[i]["lemma"] in corrdic,i in s #print corrdic #if s[i]['cat']=="unknown" and s[i][tokenname]=="d'": #if s[i][tokenname]==u"écrivant": #print "********************************************************" #for i in sorted(s): #print s[i] ##print s #1/0 #print i,s[i]		 #( s[i]["lemma"] in corrdic or s[i][tokenname] in corrdic): #if s[i]["lemma"] in corrdic : print corrdic[s[i]["lemma"]] #else:print corrdic[s[i][tokenname]] #if s[i]["lemma"] in corrdic : insdic=corrdic[s[i]["lemma"]] #else:insdic=corrdic[s[i][tokenname]] # glueing. in this case insdic contains the direction of the token glueing #elif i in s and  ( s[i]["lemma"] in gluedic or s[i][tokenname] in gluedic) : #if debug>1: #print "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg" #if s[i]["lemma"] in gluedic :print gluedic[s[i]["lemma"]] #else:print gluedic[s[i][tokenname]] #print "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg" #if s[i]["lemma"] in gluedic : insdic=gluedic[s[i]["lemma"]] #else:insdic=gluedic[s[i][tokenname]] #news = glue(s,i,insdic) #s=checkSentence(iii,news,corrlist,rec+1)
iii
s
corrlist
rec