-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummarize_rebuild.py
More file actions
74 lines (56 loc) · 1.61 KB
/
Copy pathsummarize_rebuild.py
File metadata and controls
74 lines (56 loc) · 1.61 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
# This script parses each document in the rebuilt articles collection, counting
# the number of times that any given field appears. It then dumps the output
# into an extremely inelegant text file that needs to be processed in
# imports
import json
import bson
from bson.json_util import dumps
import pymongo
def main():
# Log file
log = open('logs/summarize_rebuild.txt','w')
log.write('Begin\n')
# Connect to database
client = pymongo.MongoClient('mongodb://localhost:27017')
db = client.openaccess
collection = db.rebuild
log.write('Connection to database\n')
# output
output = open('rebuild/summarize_rebuild.csv','w')
# initialize entities
articles = []
fields = []
fieldCounts = []
i = 0
j = 0
# Iterate over each record in the collection
for record in collection.find():
# articles.append(record)
log.write(str(i) + " " + str(record["dc-identifier-uri"]) + "\n")
print str(i)
# Loop over every key in this document
for thing in record.keys():
log.write( str(thing) + "\n")
j = 0
exists = False
for found in fields:
# Loop over what we've already found
# compare
if found == thing:
fieldCounts[j] = fieldCounts[j] + 1
exists = True
j = j + 1
if exists == False:
fields.append(thing)
fieldCounts.append(1)
log.write("\n")
i = i + 1
# Output results into a quick CSV file.
# This is a mess.
i = 0
for item in fields:
output.write(str(fields[i]) + "," + str(fieldCounts[i]) + "\n")
i = i + 1
print('Finished!')
if __name__ == "__main__":
main()