M1-Arborator-NaijaSUD/arborator/lib/yuchen_EntreOnlyModifiedTree_NaijaSUD.py
def simpleEnterSentences(sql, trees, dbtextname, annotatorName, sentencefeatures={}):
	"""
	takes a list of trees (nodedics)
	puts them into the database
	if preserveSampleWithSameName: add _ to names to create new name of sample
	"""
	ti = time()
	db,cursor=sql.open()

	###### 获取textid ######
	textid = sql.enter(cursor, "texts",["textname"],(dbtextname,))
	print "textid",textid, 

	###### 获取userid ######
	userid = sql.enter(cursor, "users",["user"],(annotatorName,))
	sql.realname(annotatorName, cursor)
	if not userid:
		print "the user is not in the database"
		return
	
	for i,tree in enumerate(trees): # for every sentence
		#sentence=" ".join([tree[j].get("t","") for j in sorted(tree)])
		print sentence
		#cursor.execute("select rowid from sentences,texts  where nr=? and sentence=?;",
		sentenceid = sql.getUniqueId(cursor, "sentences", ["nr","sentence","textid"], [scounter,sentence,textid])
		print "found sentenceid",sentenceid
		if not sentenceid:
			sentenceid = sql.enter(cursor, "sentences",["nr","sentence","textid"],(scounter,sentence,textid,))
			#print "made sentenceid",sentenceid
		sql.enter(cursor, "sentencesearch",["nr","sentence","textid"],(scounter,sentence,textid,))
		if sentencefeatures == True:
			for a,v in tree.sentencefeatures.iteritems():
				sql.enter(cursor, "sentencefeatures",["sentenceid","attr","value"],(sentenceid,a,v,))
		elif sentencefeatures:	
			for a,v in sentencefeatures[i].iteritems():
				sql.enter(cursor, "sentencefeatures",["sentenceid","attr","value"],(sentenceid,a,v,))
		#print tree
		ws, sent, treeid = sql.enterTree(cursor, tree, sentenceid, userid)
		#print "ws, sent, treeid",ws, sent, treeid	
	db.commit()
	db.close()	
	print "entered",sql.getNumberTokensPerText(textid, recompute=True),"tokens"
	return textid

	takes a list of trees (nodedics)
	puts them into the database
	if preserveSampleWithSameName: add _ to names to create new name of sample
	
takes a list of trees (nodedics)
puts them into the database
if preserveSampleWithSameName: add _ to names to create new name of sample
takes a list of trees ( nodedics ) puts them into the database if preserveSampleWithSameName : add _ to names to create new name of sample
def simpleEnterSentences(sql, trees, dbtextname, annotatorName, sentencefeatures={}):
	ti = time()
	db,cursor=sql.open()
	textid = sql.enter(cursor, "texts",["textname"],(dbtextname,))
	print "textid",textid, 
	userid = sql.enter(cursor, "users",["user"],(annotatorName,))
	sql.realname(annotatorName, cursor)
	if not userid:
		print "the user is not in the database"
		return
	for i,tree in enumerate(trees): 
		print sentence
		sentenceid = sql.getUniqueId(cursor, "sentences", ["nr","sentence","textid"], [scounter,sentence,textid])
		print "found sentenceid",sentenceid
		if not sentenceid:
			sentenceid = sql.enter(cursor, "sentences",["nr","sentence","textid"],(scounter,sentence,textid,))
		sql.enter(cursor, "sentencesearch",["nr","sentence","textid"],(scounter,sentence,textid,))
		if sentencefeatures == True:
			for a,v in tree.sentencefeatures.iteritems():
				sql.enter(cursor, "sentencefeatures",["sentenceid","attr","value"],(sentenceid,a,v,))
		elif sentencefeatures:	
			for a,v in sentencefeatures[i].iteritems():
				sql.enter(cursor, "sentencefeatures",["sentenceid","attr","value"],(sentenceid,a,v,))
		ws, sent, treeid = sql.enterTree(cursor, tree, sentenceid, userid)
	db.commit()
	db.close()	
	print "entered",sql.getNumberTokensPerText(textid, recompute=True),"tokens"
	return textid
def simpleEnterSentences ( sql , trees , dbtextname , annotatorName , sentencefeatures = { } ) : ti = time ( ) db , cursor = sql . open ( ) textid = sql . enter ( cursor , "texts" , [ "textname" ] , ( dbtextname , ) ) print "textid" , textid , userid = sql . enter ( cursor , "users" , [ "user" ] , ( annotatorName , ) ) sql . realname ( annotatorName , cursor ) if not userid : print "the user is not in the database" return for i , tree in enumerate ( trees ) : print sentence sentenceid = sql . getUniqueId ( cursor , "sentences" , [ "nr" , "sentence" , "textid" ] , [ scounter , sentence , textid ] ) print "found sentenceid" , sentenceid if not sentenceid : sentenceid = sql . enter ( cursor , "sentences" , [ "nr" , "sentence" , "textid" ] , ( scounter , sentence , textid , ) ) sql . enter ( cursor , "sentencesearch" , [ "nr" , "sentence" , "textid" ] , ( scounter , sentence , textid , ) ) if sentencefeatures == True : for a , v in tree . sentencefeatures . iteritems ( ) : sql . enter ( cursor , "sentencefeatures" , [ "sentenceid" , "attr" , "value" ] , ( sentenceid , a , v , ) ) elif sentencefeatures : for a , v in sentencefeatures [ i ] . iteritems ( ) : sql . enter ( cursor , "sentencefeatures" , [ "sentenceid" , "attr" , "value" ] , ( sentenceid , a , v , ) ) ws , sent , treeid = sql . enterTree ( cursor , tree , sentenceid , userid ) db . commit ( ) db . close ( ) print "entered" , sql . getNumberTokensPerText ( textid , recompute = True ) , "tokens" return textid
takes a list of trees (nodedics)
puts them into the database
if preserveSampleWithSameName: add _ to names to create new name of sample
takes a list of trees ( nodedics ) puts them into the database if preserveSampleWithSameName : add _ to names to create new name of sample
"""
	takes a list of trees (nodedics)
	puts them into the database
	if preserveSampleWithSameName: add _ to names to create new name of sample
	""" ###### 获取textid ######
 ###### 获取userid ######
 # for every sentence
 #sentence=" ".join([tree[j].get("t","") for j in sorted(tree)])
 #cursor.execute("select rowid from sentences,texts  where nr=? and sentence=?;",
 #print "made sentenceid",sentenceid
 #print tree
 #print "ws, sent, treeid",ws, sent, treeid	

sql
trees
dbtextname
annotatorName
sentencefeatures