-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtypes.py
38 lines (35 loc) · 811 Bytes
/
types.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
# gets all properties and their datatypes
# needs kb
import gzip
output = open('types.txt', 'w')
count = 0
linecount = 0
pcount = {}
ptype = {}
for line in gzip.open('kb.txt.gz') :
linecount += 1
if (linecount % 1000000) == 0 : print linecount / 1000000
if line.startswith('#') :
output.write(line)
continue
if line.startswith(' ') : continue
parts = line.split(' ')
if len(parts) != 4 : continue
s = parts[0]
p = parts[1]
o = parts[2]
if p.startswith('P') :
if p not in pcount :
pcount[p] = 0
pcount[p] += 1
if p == 'type' :
ptype[s] = o
if s not in pcount :
pcount[s] = 0
count += 1
for p in ptype :
output.write(p + ' ' + ptype[p] + ' ' + str(pcount[p]) + "\n")
output.write('# ' + str(count) + " results\n")
print linecount, 'lines'
print count, 'results'
output.close()