-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
37 lines (33 loc) · 875 Bytes
/
helper.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
"""
helper functions
"""
import os
import json
import sys
##count number of entities in candidate files
def count_entities(file_name,count_only=False):
data = json.load(open(file_name) )
if not count_only:
c = {}
for i in data:
for e in data[i]:
if e not in c:
c[e] = 0
c[e] += 1
sorted_c = sorted(c.items(),key=lambda x:x[1], reverse =True)
print sorted_c
else:
c= 0
for i in data:
c += len(data[i])
print "the number is %d" %c
if __name__ == "__main__":
if(len(sys.argv)==2):
count_entities(sys.argv[1])
elif(len(sys.argv)==3):
if sys.argv[2]=='y':
count_entities(sys.argv[1],True)
else:
count_entities(sys.argv[1],False)
else:
print "Too many arguments"