-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount.py
81 lines (68 loc) · 2.29 KB
/
count.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
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
import os
from rdflib import Graph
import csv
import pprint
from funowl.converters.functional_converter import to_python
f1=open('/home/rohit19268/test/didntwork.csv', 'w')
dir_path='/home/rohit19268/test/files'
files=os.listdir(dir_path)
total=0
axioms_dict={}
for file_name in files:
file_path=os.path.join(dir_path,file_name)
try:
if os.path.isfile(file_path):
internal_file=to_python(file_path)
g=Graph()
internal_file.to_rdf(g)
s1=file_path.rsplit('_')[-1]
s2=s1.split('.')
print(s2)
s='/home/rohit19268/test/files'+ 'ore'+s2[0]+ '.owl'
g.serialize(destination=s, format='xml')
for stmt in g:
# pprint.pprint(stmt[0])
# pprint.pprint(stmt[1])
# pprint.pprint(stmt[2])
# print()
s=stmt[1]
if '#' in s:
index=s.index('#')
s1=s[index+1:]
if s1!='type':
axioms_dict[s1]=axioms_dict.get(s1,0)+1
total+=1
# s1=file_path.rsplit('_')[-1]
# s2=s1.split('.')
# print(s2)
# s='C:/Users/Rohit Bhatia/Desktop/btp/pool_sample/'+ 'ore'+s2[0]+ '.csv'
except Exception as e:
writer = csv.writer(f1, lineterminator='\n')
writer.writerow(s2[0]+'.owl')
writer.writerow("")
fields = ['Axiom', 'Count']
s='/home/rohit19268/test/count_ontology_new.csv'
f= open(s, 'w')
writer = csv.writer(f, lineterminator='\n')
row=["Total axioms for ontologies", total]
writer.writerow(row)
writer.writerow("")
writer.writerow(fields)
for key, value in axioms_dict.items():
percent= (value/total)*100
row=[key, value, percent]
writer.writerow(row)
fields = ['Axiom', 'Count']
s='/home/rohit19268/test/count_ontology.csv'
f= open(s, 'w')
writer = csv.writer(f, lineterminator='\n')
row=["Total axioms for ontologies", total]
writer.writerow(row)
writer.writerow("")
writer.writerow(fields)
for key, value in axioms_dict.items():
percent= (value/total)*100
row=[key, value, percent]
writer.writerow(row)
f1.close()
f.close()