-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataMining.py
More file actions
48 lines (36 loc) · 1.58 KB
/
Copy pathdataMining.py
File metadata and controls
48 lines (36 loc) · 1.58 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
__author__ = 'pais'
def getDataMining(rc):
dataMining = {'commonWordsInSameLine': {'books': {}}}
cursor = rc["db"].cursor()
query = 'select b.id, b.title, w1.id, w1.word, w2.id, w2.word, dm.apperanceCount, dm.dateCreated ' \
'from sadnadb.dataMining dm, sadnadb.books b, sadnadb.words w1, sadnadb.words w2 ' \
'where b.id = dm.bookId and w1.id = dm.wordId1 and w2.id = dm.wordId2 ' \
'ORDER BY dm.apperanceCount DESC LIMIT 2000'
cursor.execute(query)
result = cursor.fetchall()
tempBooks = {}
for r in result:
if r[0] not in tempBooks:
tempBooks[r[0]] = []
tempBooks[r[0]] += [r]
# remove duplicates
for tempBook in tempBooks:
bookData = []
i = 0
while i < len(tempBooks[tempBook]):
bookData += [tempBooks[tempBook][i]]
i += 2
dataMining['commonWordsInSameLine']['books'][tempBook] = bookData
return dataMining
def runDataMining(rc, bookId):
cursor = rc["db"].cursor()
query = 'insert into sadnadb.dataMining (bookId, apperanceCount, wordId1, wordId2)' \
'select wb1.bookId, count(wb1.wordId), wb1.wordId, wb2.wordId ' \
'from ' \
'(select * from sadnadb.wordsInBooks twb1 where twb1.bookId = %s) wb1, ' \
'(select * from sadnadb.wordsInBooks twb2 where twb2.bookId = %s) wb2 ' \
'where wb1.lineNumber = wb2.lineNumber ' \
'and wb1.wordId != wb2.wordId ' \
'group by wb1.wordId, wb2.wordId'
cursor.execute(query, (bookId, bookId))
rc["db"].commit()