-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_and_index.py
More file actions
64 lines (53 loc) · 1.52 KB
/
db_and_index.py
File metadata and controls
64 lines (53 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/python
# -*- coding: utf-8 -*-
'''
Main function of the program
'''
import os
import libGeneral
import sqlite3
#import bayes_classifier
######################
DATABASE_NAME = "ex4.db"
TRAIN_PATH = "u4_train/"
TEST_PATH = "u4_test/"
GLOBAL_INDEX = "globalIndex";
RELPROB_PATH = "bayes_model/";
######################
'''
Gibt ein Dictionary Verzeichnis -> Dateiliste zurueck vom uebergebenen Pfad zurueck
'''
def getFileDict(path):
trainingFiles = {}
dirList = os.listdir(path)
for d in dirList:
fileList = os.listdir(path + d)
trainingFiles[d] = fileList
return trainingFiles
def readAllFilesToDB(connection):
trainingFiles = getFileDict(TRAIN_PATH)
for className in trainingFiles:
fileList = trainingFiles[className]
forTesting = 0
for fileName in fileList:
if forTesting == 0:
forTesting = 1
else:
forTesting = 0
libGeneral.readFileToDB(fileName, TRAIN_PATH + "/" + className + "/", connection, className, forTesting)
connection.commit()
def createGlobalIndex(connection):
globalIndex = libGeneral.createGlobalIndexDictionary(connection)
libGeneral.writeDictionaryToDisk(globalIndex, "globalIndex")
##########################
libGeneral.createSQLiteDB(DATABASE_NAME)
print "Created database."
connection = sqlite3.connect(DATABASE_NAME)
print "Connected to database."
#######################
readAllFilesToDB(connection)
print "Read all files to database."
createGlobalIndex(connection)
print "Created global index."
#bayes_classifier.calculateModel(True)
#print "Calculated bayes model"