M1-Arborator-NaijaSUD/arborator/lib/database.py
def saveTree(self, sentenceid, userid, words, tokensChanged=False):
		""" 
		js to sqlite
		called from save.cgi
		gets a special format tree: words (ids are still strings etc)
		calls enterTree for entering
		returns the new tree id
		"""
		db,cursor=self.open()


		nodedic={}
		for i in words: # for each word
			nodedic[int(i)]={} # initialize the nodedic
			for k in words[i]:
				if k=="features": # features, except index and gov, are under the
					for a in words[i][k]:
						nodedic[int(i)][a]=words[i][k][a]
				else:
					nodedic[int(i)][k]=words[i][k]
		#open("logger.txt","a").write("saveTree "+str(nodedic)+"\ntokensChanged: "+str(tokensChanged)+"\n")

		wcounter, sent, treeid = self.enterTree(cursor, nodedic, sentenceid, userid,tokensChanged=True)
		
		#open("logger.txt","a").write("___return to saveTree. nodedic: "+str(nodedic)+"\ntokensChanged: "+str(tokensChanged)+"\n treeid: "+str(treeid)+"\n")
		if tokensChanged:
			for (nnr,ty) in tokensChanged:
				if ty==1:self.duplicateNode(nnr,sentenceid, cursor)
				elif ty==-1:self.eraseNode(nnr,sentenceid, cursor)

			sent=" ".join([a for a, in cursor.execute("select value from features where attr='t' and treeid in (select trees.rowid from trees, users where trees.sentenceid =? and users.user=? and users.rowid=trees.userid) ORDER BY nr ;",(sentenceid,self.importAnnotatorName,)).fetchall()])

			cursor.execute("UPDATE sentences SET sentence=? WHERE rowid=? ",(sent,sentenceid,))
			cursor.execute("UPDATE sentencesearch SET sentence=? WHERE rowid=? ",(sent,sentenceid,))
		db.commit()
		db.close()
		#open("logger.txt","a").write("checking back: gettree: "+str(self.gettree(sid=None,uid=None,treeid=treeid, username=None, indb=None, incursor=None))+"\n")
		
		if tokensChanged:
			return treeid,self.gettree(None,None,treeid), sent
		return treeid, None, None
 
		js to sqlite
		called from save.cgi
		gets a special format tree: words (ids are still strings etc)
		calls enterTree for entering
		returns the new tree id
		
js to sqlite
called from save.cgi
gets a special format tree: words (ids are still strings etc)
calls enterTree for entering
returns the new tree id
js to sqlite called from save . cgi gets a special format tree : words ( ids are still strings etc ) calls enterTree for entering returns the new tree id
def saveTree(self, sentenceid, userid, words, tokensChanged=False):
		db,cursor=self.open()
		nodedic={}
		for i in words: 
			nodedic[int(i)]={} 
			for k in words[i]:
				if k=="features": 
					for a in words[i][k]:
						nodedic[int(i)][a]=words[i][k][a]
				else:
					nodedic[int(i)][k]=words[i][k]
		wcounter, sent, treeid = self.enterTree(cursor, nodedic, sentenceid, userid,tokensChanged=True)
		if tokensChanged:
			for (nnr,ty) in tokensChanged:
				if ty==1:self.duplicateNode(nnr,sentenceid, cursor)
				elif ty==-1:self.eraseNode(nnr,sentenceid, cursor)
			sent=" ".join([a for a, in cursor.execute("select value from features where attr='t' and treeid in (select trees.rowid from trees, users where trees.sentenceid =? and users.user=? and users.rowid=trees.userid) ORDER BY nr ;",(sentenceid,self.importAnnotatorName,)).fetchall()])
			cursor.execute("UPDATE sentences SET sentence=? WHERE rowid=? ",(sent,sentenceid,))
			cursor.execute("UPDATE sentencesearch SET sentence=? WHERE rowid=? ",(sent,sentenceid,))
		db.commit()
		db.close()
		if tokensChanged:
			return treeid,self.gettree(None,None,treeid), sent
		return treeid, None, None
def saveTree ( self , sentenceid , userid , words , tokensChanged = False ) : db , cursor = self . open ( ) nodedic = { } for i in words : nodedic [ int ( i ) ] = { } for k in words [ i ] : if k == "features" : for a in words [ i ] [ k ] : nodedic [ int ( i ) ] [ a ] = words [ i ] [ k ] [ a ] else : nodedic [ int ( i ) ] [ k ] = words [ i ] [ k ] wcounter , sent , treeid = self . enterTree ( cursor , nodedic , sentenceid , userid , tokensChanged = True ) if tokensChanged : for ( nnr , ty ) in tokensChanged : if ty == 1 : self . duplicateNode ( nnr , sentenceid , cursor ) elif ty == - 1 : self . eraseNode ( nnr , sentenceid , cursor ) sent = " " . join ( [ a for a , in cursor . execute ( "select value from features where attr='t' and treeid in (select trees.rowid from trees, users where trees.sentenceid =? and users.user=? and users.rowid=trees.userid) ORDER BY nr ;" , ( sentenceid , self . importAnnotatorName , ) ) . fetchall ( ) ] ) cursor . execute ( "UPDATE sentences SET sentence=? WHERE rowid=? " , ( sent , sentenceid , ) ) cursor . execute ( "UPDATE sentencesearch SET sentence=? WHERE rowid=? " , ( sent , sentenceid , ) ) db . commit ( ) db . close ( ) if tokensChanged : return treeid , self . gettree ( None , None , treeid ) , sent return treeid , None , None
js to sqlite
called from save.cgi
gets a special format tree: words (ids are still strings etc)
calls enterTree for entering
returns the new tree id
js to sqlite called from save . cgi gets a special format tree : words ( ids are still strings etc ) calls enterTree for entering returns the new tree id
""" 
		js to sqlite
		called from save.cgi
		gets a special format tree: words (ids are still strings etc)
		calls enterTree for entering
		returns the new tree id
		""" # for each word # initialize the nodedic # features, except index and gov, are under the #open("logger.txt","a").write("saveTree "+str(nodedic)+"\ntokensChanged: "+str(tokensChanged)+"\n") #open("logger.txt","a").write("___return to saveTree. nodedic: "+str(nodedic)+"\ntokensChanged: "+str(tokensChanged)+"\n treeid: "+str(treeid)+"\n") #open("logger.txt","a").write("checking back: gettree: "+str(self.gettree(sid=None,uid=None,treeid=treeid, username=None, indb=None, incursor=None))+"\n")
self
sentenceid
userid
words
tokensChanged