M1-Arborator-NaijaSUD/arborator/lib/database.py
def cleanDatabase(self,filename=None):
		"""
		called from treebankfiles
		
		allows to remove a text from the database for a given text name
		deletes all possible remaining non-related data
		TODO: replace this by a version of removeText
		"""
		text="cleanDatabase <br/>\n"
		db,cursor=self.open()
		
		if filename:
			rc=cursor.execute("DELETE FROM texts WHERE textname = ?;",(filename,)).rowcount
			if rc:text+= "deleted " + str( rc)+ " texts, <br/>"
		
		rc=cursor.execute("DELETE FROM sentences WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = sentences.textid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " sentences, <br/>"
		rc=cursor.execute("DELETE FROM sentencefeatures WHERE NOT EXISTS (SELECT NULL FROM sentences WHERE sentences.rowid = sentencefeatures.sentenceid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " sentences, <br/>"
		rc=cursor.execute("DELETE FROM sentencesearch WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = sentencesearch.textid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " sentencesearch, <br/>"
		rc=cursor.execute("DELETE FROM todos WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = todos.textid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " todos, <br/>"
		rc=cursor.execute("DELETE FROM todos WHERE NOT EXISTS (SELECT NULL FROM users WHERE users.rowid = todos.userid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " todos, <br/>"
		
		rc=cursor.execute("DELETE FROM trees WHERE NOT EXISTS (SELECT NULL FROM sentences WHERE sentences.rowid = trees.sentenceid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " trees, <br/>"
		rc=cursor.execute("DELETE FROM trees WHERE NOT EXISTS (SELECT NULL FROM users WHERE users.rowid = trees.userid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " trees, <br/>"
		
		rc=cursor.execute("DELETE FROM features WHERE NOT EXISTS (SELECT NULL FROM trees WHERE trees.rowid = features.treeid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " features, <br/>"
		rc=cursor.execute("DELETE FROM links WHERE NOT EXISTS (SELECT NULL FROM trees WHERE trees.rowid = links.treeid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " features, <br/>"
		
		db.commit()
		db.close()
		return text

		called from treebankfiles
		
		allows to remove a text from the database for a given text name
		deletes all possible remaining non-related data
		TODO: replace this by a version of removeText
		
called from treebankfiles
allows to remove a text from the database for a given text name
deletes all possible remaining non-related data
TODO: replace this by a version of removeText
called from treebankfiles allows to remove a text from the database for a given text name deletes all possible remaining non - related data TODO : replace this by a version of removeText
def cleanDatabase(self,filename=None):
		text="cleanDatabase <br/>\n"
		db,cursor=self.open()
		if filename:
			rc=cursor.execute("DELETE FROM texts WHERE textname = ?;",(filename,)).rowcount
			if rc:text+= "deleted " + str( rc)+ " texts, <br/>"
		rc=cursor.execute("DELETE FROM sentences WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = sentences.textid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " sentences, <br/>"
		rc=cursor.execute("DELETE FROM sentencefeatures WHERE NOT EXISTS (SELECT NULL FROM sentences WHERE sentences.rowid = sentencefeatures.sentenceid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " sentences, <br/>"
		rc=cursor.execute("DELETE FROM sentencesearch WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = sentencesearch.textid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " sentencesearch, <br/>"
		rc=cursor.execute("DELETE FROM todos WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = todos.textid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " todos, <br/>"
		rc=cursor.execute("DELETE FROM todos WHERE NOT EXISTS (SELECT NULL FROM users WHERE users.rowid = todos.userid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " todos, <br/>"
		rc=cursor.execute("DELETE FROM trees WHERE NOT EXISTS (SELECT NULL FROM sentences WHERE sentences.rowid = trees.sentenceid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " trees, <br/>"
		rc=cursor.execute("DELETE FROM trees WHERE NOT EXISTS (SELECT NULL FROM users WHERE users.rowid = trees.userid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " trees, <br/>"
		rc=cursor.execute("DELETE FROM features WHERE NOT EXISTS (SELECT NULL FROM trees WHERE trees.rowid = features.treeid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " features, <br/>"
		rc=cursor.execute("DELETE FROM links WHERE NOT EXISTS (SELECT NULL FROM trees WHERE trees.rowid = links.treeid)").rowcount
		if rc:text+= "deleted " + str( rc)+ " features, <br/>"
		db.commit()
		db.close()
		return text
def cleanDatabase ( self , filename = None ) : text = "cleanDatabase <br/>\n" db , cursor = self . open ( ) if filename : rc = cursor . execute ( "DELETE FROM texts WHERE textname = ?;" , ( filename , ) ) . rowcount if rc : text += "deleted " + str ( rc ) + " texts, <br/>" rc = cursor . execute ( "DELETE FROM sentences WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = sentences.textid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " sentences, <br/>" rc = cursor . execute ( "DELETE FROM sentencefeatures WHERE NOT EXISTS (SELECT NULL FROM sentences WHERE sentences.rowid = sentencefeatures.sentenceid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " sentences, <br/>" rc = cursor . execute ( "DELETE FROM sentencesearch WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = sentencesearch.textid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " sentencesearch, <br/>" rc = cursor . execute ( "DELETE FROM todos WHERE NOT EXISTS (SELECT NULL FROM texts WHERE texts.rowid = todos.textid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " todos, <br/>" rc = cursor . execute ( "DELETE FROM todos WHERE NOT EXISTS (SELECT NULL FROM users WHERE users.rowid = todos.userid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " todos, <br/>" rc = cursor . execute ( "DELETE FROM trees WHERE NOT EXISTS (SELECT NULL FROM sentences WHERE sentences.rowid = trees.sentenceid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " trees, <br/>" rc = cursor . execute ( "DELETE FROM trees WHERE NOT EXISTS (SELECT NULL FROM users WHERE users.rowid = trees.userid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " trees, <br/>" rc = cursor . execute ( "DELETE FROM features WHERE NOT EXISTS (SELECT NULL FROM trees WHERE trees.rowid = features.treeid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " features, <br/>" rc = cursor . execute ( "DELETE FROM links WHERE NOT EXISTS (SELECT NULL FROM trees WHERE trees.rowid = links.treeid)" ) . rowcount if rc : text += "deleted " + str ( rc ) + " features, <br/>" db . commit ( ) db . close ( ) return text
called from treebankfiles
allows to remove a text from the database for a given text name
deletes all possible remaining non-related data
TODO: replace this by a version of removeText
called from treebankfiles allows to remove a text from the database for a given text name deletes all possible remaining non - related data TODO : replace this by a version of removeText
"""
		called from treebankfiles
		
		allows to remove a text from the database for a given text name
		deletes all possible remaining non-related data
		TODO: replace this by a version of removeText
		"""
self
filename