M1-Arborator-NaijaSUD/arborator/lib/database.py
def correctSentenceLength(self,gooduserid=1, modifyDatabase=False):
		"""
		probably no longer needed
		before: correction in case of bad nb of tokens
		TODO: remove function
		"""
		db,cursor=self.open() 
		for textid,tname,nbt in self.getall(cursor, "texts",[], []):
			print "__________",textid,tname
			#textid=self.getUniqueId(cursor, "texts", ["textname"],["Amelie_PreudHomme"])
			#print textid
			for sid,snr,sentence,_ in self.getall(cursor, "sentences",["textid"], [textid]):
				
				goodnrtoks=0
				tidToToknr,tidToUid={},{}
				for tid,sidd,uid,aty,sta,com,tim in self.getall(cursor, "trees",["sentenceid"], [sid]):
					
					nt = self.getnumber(cursor, "features", ["treeid","attr"], [tid,"t"])
					#print tid,uid,nt
					if uid==gooduserid:	goodnrtoks=nt
					tidToToknr[tid]=nt
					tidToUid[tid]=uid
					
				
				for tid in tidToToknr:
					if tidToToknr[tid]!=goodnrtoks:
						print "__sentence",snr,"good nb of tokens",goodnrtoks
						print "problem",tid,uid,"nr tokens:",tidToToknr[tid]
						for _,user,real in self.getall(cursor, "users",["rowid"], [tidToUid[tid]]):
							print user,real
						if modifyDatabase:
							if tidToToknr[tid] > goodnrtoks:
								rc=cursor.execute("delete from features where treeid=? and nr>?;",(tid,goodnrtoks)).rowcount
								print "deleted",rc,"features"
								rc=cursor.execute("delete from links where treeid=? and (depid>? or govid>?);",(tid,goodnrtoks,goodnrtoks)).rowcount
								print "deleted",rc,"links"
		
		if modifyDatabase: db.commit()	
		db.close()

		probably no longer needed
		before: correction in case of bad nb of tokens
		TODO: remove function
		
probably no longer needed
before: correction in case of bad nb of tokens
TODO: remove function
probably no longer needed before : correction in case of bad nb of tokens TODO : remove function
def correctSentenceLength(self,gooduserid=1, modifyDatabase=False):
		db,cursor=self.open() 
		for textid,tname,nbt in self.getall(cursor, "texts",[], []):
			print "__________",textid,tname
			for sid,snr,sentence,_ in self.getall(cursor, "sentences",["textid"], [textid]):
				goodnrtoks=0
				tidToToknr,tidToUid={},{}
				for tid,sidd,uid,aty,sta,com,tim in self.getall(cursor, "trees",["sentenceid"], [sid]):
					nt = self.getnumber(cursor, "features", ["treeid","attr"], [tid,"t"])
					if uid==gooduserid:	goodnrtoks=nt
					tidToToknr[tid]=nt
					tidToUid[tid]=uid
				for tid in tidToToknr:
					if tidToToknr[tid]!=goodnrtoks:
						print "__sentence",snr,"good nb of tokens",goodnrtoks
						print "problem",tid,uid,"nr tokens:",tidToToknr[tid]
						for _,user,real in self.getall(cursor, "users",["rowid"], [tidToUid[tid]]):
							print user,real
						if modifyDatabase:
							if tidToToknr[tid] > goodnrtoks:
								rc=cursor.execute("delete from features where treeid=? and nr>?;",(tid,goodnrtoks)).rowcount
								print "deleted",rc,"features"
								rc=cursor.execute("delete from links where treeid=? and (depid>? or govid>?);",(tid,goodnrtoks,goodnrtoks)).rowcount
								print "deleted",rc,"links"
		if modifyDatabase: db.commit()	
		db.close()
def correctSentenceLength ( self , gooduserid = 1 , modifyDatabase = False ) : db , cursor = self . open ( ) for textid , tname , nbt in self . getall ( cursor , "texts" , [ ] , [ ] ) : print "__________" , textid , tname for sid , snr , sentence , _ in self . getall ( cursor , "sentences" , [ "textid" ] , [ textid ] ) : goodnrtoks = 0 tidToToknr , tidToUid = { } , { } for tid , sidd , uid , aty , sta , com , tim in self . getall ( cursor , "trees" , [ "sentenceid" ] , [ sid ] ) : nt = self . getnumber ( cursor , "features" , [ "treeid" , "attr" ] , [ tid , "t" ] ) if uid == gooduserid : goodnrtoks = nt tidToToknr [ tid ] = nt tidToUid [ tid ] = uid for tid in tidToToknr : if tidToToknr [ tid ] != goodnrtoks : print "__sentence" , snr , "good nb of tokens" , goodnrtoks print "problem" , tid , uid , "nr tokens:" , tidToToknr [ tid ] for _ , user , real in self . getall ( cursor , "users" , [ "rowid" ] , [ tidToUid [ tid ] ] ) : print user , real if modifyDatabase : if tidToToknr [ tid ] > goodnrtoks : rc = cursor . execute ( "delete from features where treeid=? and nr>?;" , ( tid , goodnrtoks ) ) . rowcount print "deleted" , rc , "features" rc = cursor . execute ( "delete from links where treeid=? and (depid>? or govid>?);" , ( tid , goodnrtoks , goodnrtoks ) ) . rowcount print "deleted" , rc , "links" if modifyDatabase : db . commit ( ) db . close ( )
probably no longer needed
before: correction in case of bad nb of tokens
TODO: remove function
probably no longer needed before : correction in case of bad nb of tokens TODO : remove function
"""
		probably no longer needed
		before: correction in case of bad nb of tokens
		TODO: remove function
		""" #textid=self.getUniqueId(cursor, "texts", ["textname"],["Amelie_PreudHomme"]) #print textid #print tid,uid,nt
self
gooduserid
modifyDatabase