Example #1
0
def create_database():
	"""
	Uses BookParser to process the html book files into a data structure in memory
	then iterates through and stores in a sqlite file.
	"""
	conn = sqlite3.connect('test.db')
	cur = conn.cursor()
	create_table = """
	CREATE TABLE IF NOT EXISTS words
             (word TEXT PRIMARY KEY, serialized_context_list TEXT)
	"""
	cur.execute(create_table)
	insert_row = """
	INSERT OR REPLACE INTO words VALUES (?, ?)
	"""
	book_parser = BookParser()
	book_parser.initiate()
	for word, context_list in book_parser.get_full_dict().iteritems():
		cur.execute(insert_row, (word.decode('utf-8'), json.dumps(context_list)))
	conn.commit()
	conn.close()