-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.py
More file actions
81 lines (57 loc) · 1.55 KB
/
Query.py
File metadata and controls
81 lines (57 loc) · 1.55 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def total(positions):
f = open("log.txt", 'r')
lines = f.readlines()
f.close()
relevantDicts = []
for position in positions:
relevantDicts.append(lines[position - 1])
# Parse relevantDicts and add up the word/frequencies
keys = []
values = []
for dictionary in relevantDicts:
dictionary = dictionary.split("=")[1]
entries = dictionary.split(",")
for entry in entries:
key = entry.split(":")[0]
value = int(entry.split(":")[1])
if key in keys:
index = keys.index(key)
values[index] += value
else:
keys.append(key)
values.append(value)
totalWords = 0
for i in range(len(keys)):
print(str(keys[i]) + " " + str(values[i]))
totalWords += values[i]
#PRINT TOTAL
print("Total: " + str(totalWords))
def printFileNames():
f = open("log.txt", 'r')
lines = f.readlines()
f.close()
for line in lines:
print(line.split("=")[0])
def merge(pos1, pos2):
f = open("log.txt", 'r')
lines = f.readlines()
f.close()
relevantDicts = []
relevantDicts.append(lines[pos1 - 1])
relevantDicts.append(lines[pos2 - 1])
keys = []
values = []
for dictionary in relevantDicts:
dictionary = dictionary.split("=")[1]
entries = dictionary.split(",")
for entry in entries:
key = entry.split(":")[0]
value = int(entry.split(":")[1])
if key in keys:
index = keys.index(key)
values[index] += value
else:
keys.append(key)
values.append(value)
for i in range(len(keys)):
print(str(keys[i]) + " " + str(values[i]))