-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_aircraft_ontology.py
executable file
·191 lines (178 loc) · 6.25 KB
/
create_aircraft_ontology.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import json
import os
from owlready2 import get_ontology, OrderedDict, Thing
'''Python 3 code'''
json_data = open('airplane_before_ontology.json').read()
data = json.loads(json_data)
owl_path = os.path.join('/var','www', 'html', 'owl')
'''
dictionary form
name, synset, lemma, numVertices,
size,
bodysize, wingsize, tailsize, enginesize,
bodylocation, leftwinglocation, rightwinglocation, taillocation, leftenginelocation, rightenginelocation
'''
onto = get_ontology('airplane_1.owl')
onto.load()
#For python 3.5, make dictionary key list
data=OrderedDict(sorted(data.items()))
model_list=list(data.keys())
c1=0; c2=0; c3=0; c4=0; c5=0; c6=0; c7=0; c8=0; c9=0
state_null=0
for i in range(len(data)):
model_id=model_list[i]
sample=data[model_id]
print(model_id,i+1)
print(sample)
onto.save(file=os.path.join(owl_path, f'{model_id}.owl'), format="rdfxml")
onto = get_ontology(f'http://localhost:8080/owl/{model_id}.owl')
ontology_state=''
with onto:
class Aircraft(Thing):
pass
class Name(Aircraft):
range=[str]
class Synset(Aircraft):
range = [str]
class Lemma(Synset):
range = [str]
class numVertices(Aircraft):
range = [int]
class Parts(Aircraft):
pass
class Body(Parts):
pass
class Size(Aircraft):
pass
class Height(Size):
range=[float]
class Width(Size):
range=[float]
class Length(Size):
range=[float]
class Location(Aircraft):
pass
class X_Location(Location):
pass
class Y_Location(Location):
pass
class Z_Location(Location):
pass
class Body(Location):
pass
class Body(Size):
pass
'''1 : tail exist, 2: tail & body are one'''
if sample['taillocation']!=[]:
class Tail(Body):
pass
if sample['leftwinglocation'] == [] and sample['leftenginelocation'] == []:
ontology_state = 'body contains all_1'
c1+=1
pass
if sample['leftwinglocation'] == [] and sample['leftenginelocation'] != []:
c2 += 1
ontology_state = 'body contains wing_1'
class Engine(Body):
pass
class LeftEngine(Engine):
pass
class RightEngine(Engine):
pass
if sample['leftwinglocation'] != [] and sample['leftenginelocation'] == []:
c3 += 1
ontology_state = 'body contains engine_1'
class Wing(Body):
pass
class LeftWing(Wing):
pass
class RightWing(Wing):
pass
if sample['leftenginelocation']!=[] and sample['leftwinglocation']!=[]:
if abs(sample['leftwinglocation'][0]-sample['leftenginelocation'][0]) <= abs(sample['taillocation'][0]-sample['leftenginelocation'][0]):
ontology_state='engine at wing_1'
c4+=1
class Wing(Body):
pass
class LeftWing(Wing):
pass
class RightWing(Wing):
pass
class Engine(Wing):
pass
class LeftEngine(Engine):
pass
class RightEngine(Engine):
pass
class Tail(Location):
pass
class Tail(Size):
pass
class Wing(Location):
pass
class Wing(Size):
pass
class Engine(Location):
pass
class Engine(Size):
pass
else:
ontology_state='engine at body_1'
c5+=1
class Wing(Body):
pass
class Wing(Body):
pass
class LeftWing(Wing):
pass
class RightWing(Wing):
pass
class Engine(Body):
pass
class LeftEngine(Engine):
pass
class RightEngine(Engine):
pass
else:
if sample['leftwinglocation'] == [] and sample['leftenginelocation'] == []:
ontology_state = 'body contains all_2'
c6+=1
pass
if sample['leftwinglocation'] == [] and sample['leftenginelocation'] != []:
c7 += 1
ontology_state = 'body contains wing_2'
class Engine(Body):
pass
class LeftEngine(Engine):
pass
class RightEngine(Engine):
pass
if sample['leftwinglocation'] != [] and sample['leftenginelocation'] == []:
c8 += 1
ontology_state = 'body contains engine_2'
class Wing(Body):
pass
class LeftWing(Wing):
pass
class RightWing(Wing):
pass
if sample['leftenginelocation']!=[] and sample['leftwinglocation']!=[]:
ontology_state='engine at wing_2'
c9+=1
class Wing(Body):
pass
class LeftWing(Wing):
pass
class RightWing(Wing):
pass
class Engine(Wing):
pass
class LeftEngine(Engine):
pass
class RightEngine(Engine):
pass
if ontology_state=='':
state_null+=1
onto.save(file=os.path.join(owl_path, f'{model_id}.owl'), format="rdfxml")
print(c1,c2,c3,c4,c5,c6,c7,c8,c9)
print(state_null)