forked from amithalle/sadna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadFile.py
47 lines (37 loc) · 1.36 KB
/
LoadFile.py
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
from DBConnection import DBConn
class FileLoader:
def loadFile(self, path):
stanzas = []
with open(path, "r") as file:
lines = file.readlines()
while "\n" in lines:
stanzas.append(lines[:lines.index("\n")])
lines = lines[lines.index("\n") + 1:]
if len(lines) != 0:
stanzas.append(lines)
# print stanzas
# print self.createWordArr(stanzas)
#
conn = DBConn()
for word in self.createWordArr(stanzas):
conn.execStatement("insert into words (word, stanzaindex, lineGlobalindex, lineindex, wordindex) "
"values(?,?,?,?,?)", word)
def createWordArr(self, stanzas):
words = []
index_stanza = 0
index_global_line = 0
for stanza in stanzas:
index_line = 0
for line in stanza:
index_word = 0
for word in line.split():
words.append((word, index_stanza, index_global_line, index_line, index_word))
index_word += 1
index_line += 1
index_global_line += 1
index_stanza += 1
return words
a = FileLoader()
a.loadFile("testFile.txt")
for x in DBConn().select("select * from words",()):
print x