forked from MOZI-AI/knowledge-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertHumanView.py
686 lines (631 loc) · 43.1 KB
/
convertHumanView.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
import argparse
import xml.etree.ElementTree as ET
from atomwrappers import *
import requests
def parse_args():
parser = argparse.ArgumentParser(description='convert human view db to atomese')
parser.add_argument('--dbowl', type=str, default='',
help='owl file with ontology')
parser.add_argument('--output', type=str, default='',
help='output schema file with atomspace (result.scm for example)')
return parser.parse_args()
def parseProperties(filename, property):
props = {}
with open(filename, 'rb') as file:
for line in file:
if line[:17].decode("utf-8") == property:
line = line.decode("utf-8")
splitted = line.split(":")[2].split("(")
props[splitted[0].split(" ")[0]] = splitted[1].split(")")[0]
return props
def transform_todots(id):
id = id.split("_")
id = id[0] + ":" + id[1]
return id
def checkIfInProps(id, props1, props2):
if id in props1:
id = props1[id]
elif id in props2:
id = props2[id]
else:
id = transform_todots(id)
return id
def makeSatisfLink(variable, restr, list_member):
tmp_eval_link = CEvaluationLink(CPredicateNode(restr), CListLink(CVariable(variable), list_member))
return CSatisfyingSetScopeLink(CVariable(variable), tmp_eval_link)
def makeRestrictionParentLink(id, parent, restriction_label, restriction_svf):
tmp_eval_link = CEvaluationLink(CPredicateNode(restriction_label), CConceptNode(restriction_svf))
tmp_simil_link = CSimilarityLink(CConceptNode(id), CConceptNode(parent))
return CContextLink(tmp_eval_link, tmp_simil_link)
def makeRestrictionParentLink2(id, parent, restriction_svf):
tmp_satisf_link = makeSatisfLink("$X", restriction_svf, CConceptNode(parent))
return CSubsetLink(CConceptNode(id), tmp_satisf_link)
def makeTwoRestrictionParentLink(id, parent, restriction_svf, restriction_svf2):
tmp_satisf_link = makeSatisfLink("$X", restriction_svf2, CConceptNode(parent))
tmp_satisf_link2 = makeSatisfLink("$Y", restriction_svf, tmp_satisf_link)
return CSubsetLink(CConceptNode(id), tmp_satisf_link2)
def makeDifficultCase(class_id_1, class_id_2, class_id_3, svf_prop_1, svf_prop_2):
tmp_satisf_link = makeSatisfLink("$X", svf_prop_1, CConceptNode(class_id_2))
part_1 = CAndLink(CConceptNode(class_id_1), tmp_satisf_link)
part_2 = makeSatisfLink("$Y", svf_prop_2, CConceptNode(class_id_3))
return CSubsetLink(part_1, part_2)
def makeRareCase(class_id_1, class_id_2, class_id_3, restriction_svf):
tmp_satisf_link = makeSatisfLink("$X", restriction_svf, CConceptNode(class_id_3))
tmp_and_link = CAndLink(CConceptNode(class_id_2), tmp_satisf_link)
return CSubsetLink(CConceptNode(class_id_1), tmp_and_link)
def makeRareCase2(classes, restrictions):
tmp_satisf_link = makeSatisfLink("$X", restrictions[-1], CConceptNode(classes[-1]))
tmp_and_link = CAndLink(CConceptNode(classes[-2]), tmp_satisf_link)
tmp_satisf_link_2 = makeSatisfLink("$Y", restrictions[-2], tmp_and_link)
tmp_and_link_2 = CAndLink(CConceptNode(classes[-3]), tmp_satisf_link_2)
tmp_satisf_link_3 = makeSatisfLink("$Z", restrictions[-3], tmp_and_link_2)
return CSubsetLink(CConceptNode(classes[-4]), tmp_satisf_link_3)
def makeDifficultCase2(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
part2 = makeSatisfLink("$Y", restrs[-2], tmp_satisf_link)
tmp_satisf_link_2 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-2]))
part1 = CAndLink(CConceptNode(classes[0]), tmp_satisf_link_2)
return CSubsetLink(part1, part2)
def makeDifficultCaseCore(classes, restrs):
part2 = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
part1 = CAndLink(CConceptNode(classes[0]), tmp_satisf_link)
return CSubsetLink(part1, part2)
def findAllInLine(line, toFind):
founded_ids = []
res = 0
prev_res = 0
while not (res == -1):
res = line[res:].find(toFind)
if (not (res == -1)):
res = res + len(toFind) + prev_res
prev_res = res
founded_ids.append(res)
return founded_ids
def parseSubclassLine(line, props1, props2):
obo_ids = findAllInLine(line, "obo:")
core_ids = findAllInLine(line, "core:")
svf_ids = findAllInLine(line, "ObjectSomeValuesFrom(")
intersection_ids = findAllInLine(line, "ObjectIntersectionOf(")
min_cardinality_id = findAllInLine(line, "ObjectMinCardinality(")
max_cardinality_id = findAllInLine(line, "ObjectMaxCardinality(")
classes = []
restrs = []
if(len(min_cardinality_id) > 0) or (len(max_cardinality_id) > 0):
return None #currently dont know how to deal with cardinalities
if ((len(obo_ids) == 2) & (len(core_ids) == 0) & (len(svf_ids) == 0)):
class_id = transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0])
parent_id = transform_todots(line[obo_ids[1]:].split(")")[0])
return CSubsetLink(CConceptNode(class_id), CConceptNode(parent_id))
elif ((len(obo_ids) == 3) & (len(core_ids) == 0) & (len(svf_ids) == 1)):
class_id = transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0])
svf_prop = checkIfInProps(line[obo_ids[1]:obo_ids[2]].split(" ")[0], props1, props2)
parent_id = transform_todots(line[obo_ids[2]:].split(")")[0])
return makeRestrictionParentLink2(class_id, parent_id, svf_prop)
elif ((len(obo_ids) == 2) & (len(core_ids) == 1) & (len(svf_ids) == 1)):
class_id = transform_todots(line[obo_ids[0]:core_ids[0]].split(" ")[0])
core = line[core_ids[0]:obo_ids[1]].split(" ")[0]
parent_id = transform_todots(line[obo_ids[1]:].split(")")[0])
return makeRestrictionParentLink2(class_id, parent_id, core)
elif ((len(obo_ids) == 4) & (len(core_ids) == 0) & (len(svf_ids) == 2) & (len(intersection_ids) == 0)):
if((svf_ids[0] > obo_ids[0]) & (svf_ids[0] < obo_ids[1]) & (svf_ids[1] > obo_ids[1]) & (svf_ids[1] < obo_ids[2]) & (svf_ids[1] < obo_ids[3])):
class_id = transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0])
svf_prop_1 = checkIfInProps(line[obo_ids[1]:obo_ids[2]].split(" ")[0], props1, props2)
svf_prop_2 = checkIfInProps(line[obo_ids[2]:obo_ids[3]].split(" ")[0], props1, props2)
parent_id = transform_todots(line[obo_ids[3]:].split(")")[0])
return makeTwoRestrictionParentLink(class_id, parent_id, svf_prop_1, svf_prop_2)
elif((len(obo_ids) == 5) & (len(svf_ids) == 2) & (len(intersection_ids) == 1)):
if ((obo_ids[0] > intersection_ids[0]) & (svf_ids[0] > obo_ids[0]) & (obo_ids[1] > svf_ids[0]) &
(obo_ids[2] < svf_ids[1])):
class_id_1 = transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0])
svf_prop_1 = checkIfInProps(line[obo_ids[1]:obo_ids[2]].split(" ")[0], props1, props2)
class_id_2 = transform_todots(line[obo_ids[2]:obo_ids[3]].split(")")[0])
svf_prop_2 = checkIfInProps(line[obo_ids[3]:obo_ids[4]].split(" ")[0], props1, props2)
class_id_3 = transform_todots(line[obo_ids[4]:].split(")")[0])
return makeDifficultCase(class_id_1, class_id_2, class_id_3, svf_prop_1, svf_prop_2)
elif((len(obo_ids) == 4) & (len(intersection_ids) == 1) & (len(svf_ids) == 1)):
if((obo_ids[0] < intersection_ids[0]) & (obo_ids[1] > intersection_ids[0]) & (obo_ids[2] > svf_ids[0])):
class_id_1 = transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0])
class_id_2 = transform_todots(line[obo_ids[1]:obo_ids[2]].split(" ")[0])
class_id_3 = transform_todots(line[obo_ids[3]:].split(")")[0])
restr_svf = checkIfInProps(line[obo_ids[2]:obo_ids[3]].split(" ")[0], props1, props2)
return makeRareCase(class_id_1, class_id_2, class_id_3, restr_svf)
elif((len(obo_ids) == 7) & (len(intersection_ids) == 2) & (len(svf_ids) == 3)):
classes.append(transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[1]:obo_ids[2]].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[2]:obo_ids[3]].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[3]:obo_ids[4]].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[4]:obo_ids[5]].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[5]:obo_ids[6]].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[6]:].split(")")[0]))
return makeRareCase2(classes, restrs)
elif((len(intersection_ids) == 1) & (len(svf_ids) == 3) & (len(obo_ids) == 6)):
classes.append(transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[1]:obo_ids[2]].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[3]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
return makeDifficultCase2(classes, restrs)
elif ((len(intersection_ids) == 1) & (len(svf_ids) == 2) & (len(obo_ids) == 4) & (len(core_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:obo_ids[1]].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[1]:obo_ids[2]].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(line[obo_ids[-1]:].split(")")[0])
return makeDifficultCaseCore(classes, restrs)
return None
def makeEquivClasses(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_and_link = CAndLink(CConceptNode(classes[-2]), tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivClassesUnion(classes):
return CSimilarityLink(CConceptNode(classes[0]), COrLink(CConceptNode(classes[1]), CConceptNode(classes[2])))
def makeEquivClasses2svfs1inter(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
part2 = CAndLink(CConceptNode(classes[-3]), tmp_satisf_link, tmp_satisf_link_2)
return CSimilarityLink(CConceptNode(classes[0]), part2)
def makeEquivRareCase(classes):
return CSimilarityLink(CConceptNode(classes[0]), CAndLink(CConceptNode(classes[1]), CConceptNode(classes[2])))
def makeEquivRareCase2(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_and_link = CAndLink(CConceptNode(classes[-2]), tmp_satisf_link)
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], tmp_and_link)
tmp_and_link_2 = CAndLink(CConceptNode(classes[-3]), tmp_satisf_link_2)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link_2)
def makeEquivSVFCore(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[0], CConceptNode(classes[-1]))
tmp_and_link = CAndLink(CConceptNode(classes[-2]), tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase3(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[0], CConceptNode(classes[-1]))
tmp_and_link = CAndLink(CConceptNode(classes[-2]), CConceptNode(classes[-3]), tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquiv2Core2Svf1Inters(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_and_link = CAndLink(CConceptNode(classes[-3]), tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquiv3Svf1Intersect(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_and_link = CAndLink(CConceptNode(classes[-4]), tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquiv1Intersect2Svf1Core(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_and_link = CAndLink(CConceptNode(classes[-3]), tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquiv3Union(classes):
tmp_or_link = COrLink(CConceptNode(classes[-1]), CConceptNode(classes[-2]), CConceptNode(classes[-3]))
return CSimilarityLink(CConceptNode(classes[0]), tmp_or_link)
def makeEquiv4Svf1Inters(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
tmp_and_link = CAndLink(CConceptNode(classes[-5]), tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[-6]), tmp_and_link)
def makeEquiv4Svf1Inters2(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
and_part_3 = makeSatisfLink("$Y", restrs[-2], tmp_satisf_link)
tmp_satisf_link_2 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-2]))
and_part_2 = makeSatisfLink("$U", restrs[-4], tmp_satisf_link_2)
tmp_and_link = CAndLink(CConceptNode(classes[-3]), and_part_2, and_part_3)
return CSimilarityLink(CConceptNode(classes[-4]), tmp_and_link)
def makeEquiv2Svf1Intersect(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], tmp_satisf_link)
tmp_and_link = CAndLink(CConceptNode(classes[-2]), tmp_satisf_link_2)
return CSimilarityLink(CConceptNode(classes[-3]), tmp_and_link)
def makeEquiv3Svf1Union(classes, restrs):
part_2 = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_2 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
part_1 = CAndLink(tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(part_1, part_2)
def makeEquivRareCase4(classes, restrs):
part_2 = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_2 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_3 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
part_1 = COrLink(tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(part_1, part_2)
def makeEquiv4Svf1Inter1Core(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
tmp_and_link = CAndLink(CConceptNode(classes[-5]), tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase5(classes):
tmp_or_link = COrLink(CConceptNode(classes[-1]), CConceptNode(classes[-2]), CConceptNode(classes[-3]), CConceptNode(classes[-4]))
return CSimilarityLink(CConceptNode(classes[0]), tmp_or_link)
def makeEquiv3Svf1Intersect1Core(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_and_link = CAndLink(CConceptNode(classes[-4]), tmp_satisf_link, tmp_satisf_link_2, tmp_satisf_link_3)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquiv3svf1Intersect2(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], tmp_satisf_link)
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-2]))
tmp_and_link = CAndLink(CConceptNode(classes[-3]), tmp_satisf_link_3, tmp_satisf_link_2)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase6(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_and_link = CAndLink(CConceptNode(classes[-4]), tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquiv5Svf1Intersect(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
tmp_satisf_link_5 = makeSatisfLink("$V", restrs[-5], CConceptNode(classes[-5]))
tmp_and_link = CAndLink(CConceptNode(classes[-6]), tmp_satisf_link_5, tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase7(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], tmp_satisf_link)
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-2]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-3]))
tmp_and_link = CAndLink(CConceptNode(classes[-4]), tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase8(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
tmp_satisf_link_5 = makeSatisfLink("$U", restrs[-5], CConceptNode(classes[-5]))
tmp_and_link = CAndLink(CConceptNode(classes[-6]), tmp_satisf_link_5, tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase9(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
tmp_and_link = CAndLink(CConceptNode(classes[-5]), tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase10(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_and_link = CAndLink(CConceptNode(classes[-4]), tmp_satisf_link_3, tmp_satisf_link_2, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase11(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], tmp_satisf_link_2)
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-3]))
tmp_satisf_link_5 = makeSatisfLink("$V", restrs[-5], tmp_satisf_link_4)
tmp_satisf_link_6 = makeSatisfLink("$W", restrs[-6], CConceptNode(classes[-4]))
tmp_and_link = CAndLink(CConceptNode(classes[-5]), tmp_satisf_link_6, tmp_satisf_link_5, tmp_satisf_link_3, tmp_satisf_link)
return CSimilarityLink(CConceptNode(classes[0]), tmp_and_link)
def makeEquivRareCase12(classes, restrs):
tmp_satisf_link = makeSatisfLink("$X", restrs[-1], CConceptNode(classes[-1]))
tmp_satisf_link_2 = makeSatisfLink("$Y", restrs[-2], CConceptNode(classes[-2]))
tmp_satisf_link_3 = makeSatisfLink("$Z", restrs[-3], CConceptNode(classes[-3]))
tmp_satisf_link_4 = makeSatisfLink("$U", restrs[-4], CConceptNode(classes[-4]))
tmp_satisf_link_5 = makeSatisfLink("$V", restrs[-5], CConceptNode(classes[-5]))
tmp_or_link = COrLink(tmp_satisf_link_5, tmp_satisf_link_4, tmp_satisf_link_3, tmp_satisf_link_2)
return CSimilarityLink(tmp_or_link, tmp_satisf_link)
def parseEquvalentLine(line, props1, props2):
obo_ids = findAllInLine(line, "obo:")
core_ids = findAllInLine(line, "core:")
svf_ids = findAllInLine(line, "ObjectSomeValuesFrom(")
intersection_ids = findAllInLine(line, "ObjectIntersectionOf(")
union_ids = findAllInLine(line, "ObjectUnionOf(")
min_cardinality_id = findAllInLine(line, "ObjectMinCardinality(")
max_cardinality_id = findAllInLine(line, "ObjectMaxCardinality(")
classes = []
restrs = []
if ((len(min_cardinality_id) > 0) or (len(max_cardinality_id) > 0)):
return None # currently dont know how to deal with cardinalities
elif((len(obo_ids) == 4) & (len(svf_ids) == 1) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
return makeEquivClasses(classes, restrs)
elif ((len(obo_ids) == 3) & (len(union_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
return makeEquivClassesUnion(classes)
elif ((len(obo_ids) == 6) & (len(intersection_ids) == 1) & (len(svf_ids) == 2)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
return makeEquivClasses2svfs1inter(classes, restrs)
elif((len(obo_ids) == 3) & (len(intersection_ids) == 1) & (len(svf_ids) == 0)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
return makeEquivRareCase(classes)
elif((len(obo_ids) == 6) & (len(svf_ids) == 2) & (len(intersection_ids) == 2)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
return makeEquivRareCase2(classes, restrs)
elif((len(obo_ids) == 3) & (len(core_ids) == 1) & (len(intersection_ids) == 1) & (len(svf_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
return makeEquivSVFCore(classes, restrs)
elif((len(obo_ids) == 5) & (len(svf_ids) == 1) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[2]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[3]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
return makeEquivRareCase3(classes, restrs)
elif((len(obo_ids) == 4) & (len(core_ids) == 2) & (len(svf_ids) == 2) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
restrs.append(line[core_ids[1]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
return makeEquiv2Core2Svf1Inters(classes, restrs)
elif ((len(obo_ids) == 8) & (len(intersection_ids) == 1) & (len(svf_ids) == 3)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
return makeEquiv3Svf1Intersect(classes, restrs)
elif((len(obo_ids) == 5) & (len(svf_ids) == 2) & (len(intersection_ids) == 1) & (len(core_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
return makeEquiv1Intersect2Svf1Core(classes, restrs)
elif((len(obo_ids) == 4) & (len(union_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[2]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
return makeEquiv3Union(classes)
elif((len(svf_ids) == 4) & (len(obo_ids) == 10) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[8]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[9]:].split(")")[0]))
return makeEquiv4Svf1Inters(classes, restrs)
elif((len(obo_ids) == 8) & (len(svf_ids) == 4) & (len(intersection_ids) == 1) & (len(core_ids) == 0)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[3]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[5]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
return makeEquiv4Svf1Inters2(classes, restrs)
elif((len(obo_ids) == 5) & (len(svf_ids) == 2) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[3]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
return makeEquiv2Svf1Intersect(classes, restrs)
elif((len(svf_ids) == 3) & (len(obo_ids) == 6) & (len(union_ids) == 1)):
restrs.append(checkIfInProps(line[obo_ids[0]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[1]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
return makeEquiv3Svf1Union(classes, restrs)
elif((len(svf_ids) == 4) & (len(union_ids) == 1) & (len(obo_ids) == 8)):
restrs.append(checkIfInProps(line[obo_ids[0]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[1]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
return makeEquivRareCase4(classes, restrs)
elif((len(obo_ids) == 9) & (len(core_ids) == 1) & (len(svf_ids) == 4) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[8]:].split(")")[0]))
return makeEquiv4Svf1Inter1Core(classes, restrs)
elif((len(obo_ids) == 5) & (len(union_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[2]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[3]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
return makeEquivRareCase5(classes)
elif((len(obo_ids) == 7) & (len(core_ids) == 1) & (len(svf_ids) == 3) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[6]:].split(")")[0]))
return makeEquiv3Svf1Intersect1Core(classes, restrs)
elif((len(obo_ids) == 7) & (len(svf_ids) == 3) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[5]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[6]:].split(")")[0]))
return makeEquiv3svf1Intersect2(classes, restrs)
elif((len(obo_ids) == 6) & (len(core_ids) == 2) & (len(svf_ids) == 3) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
restrs.append(line[core_ids[1]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
return makeEquivRareCase6(classes, restrs)
elif((len(obo_ids) == 12) & (len(svf_ids) == 5) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[8]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[9]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[10]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[11]:].split(")")[0]))
return makeEquiv5Svf1Intersect(classes, restrs)
elif((len(obo_ids) == 9) & (len(svf_ids) == 4) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[7]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[8]:].split(")")[0]))
return makeEquivRareCase7(classes, restrs)
elif((len(obo_ids) == 10) & (len(core_ids) == 2) & (len(svf_ids) == 5) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[8]:].split(")")[0]))
restrs.append(line[core_ids[1]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[9]:].split(")")[0]))
return makeEquivRareCase8(classes, restrs)
elif((len(obo_ids) == 8) & (len(core_ids) == 2) & (len(svf_ids) == 4) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[6]:].split(")")[0]))
restrs.append(line[core_ids[1]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
return makeEquivRareCase9(classes, restrs)
elif ((len(core_ids) == 3) & (len(obo_ids) == 5) & (len(svf_ids) == 3) & (len(intersection_ids) == 1)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(line[core_ids[0]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[2]:].split(")")[0]))
restrs.append(line[core_ids[1]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(line[core_ids[2]:].split(" ")[0])
classes.append(transform_todots(line[obo_ids[4]:].split(")")[0]))
return makeEquivRareCase10(classes, restrs)
elif((len(obo_ids) == 12) & (len(intersection_ids) == 1) & (len(svf_ids) == 6)):
classes.append(transform_todots(line[obo_ids[0]:].split(" ")[0]))
classes.append(transform_todots(line[obo_ids[1]:].split(" ")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[5]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[6]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[7]:].split(" ")[0], props1, props2))
restrs.append(checkIfInProps(line[obo_ids[8]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[9]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[10]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[11]:].split(")")[0]))
return makeEquivRareCase11(classes, restrs)
elif((len(obo_ids) == 10) & (len(union_ids) == 1) & (len(svf_ids) == 5)):
restrs.append(checkIfInProps(line[obo_ids[0]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[1]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[2]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[3]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[4]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[5]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[6]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[7]:].split(")")[0]))
restrs.append(checkIfInProps(line[obo_ids[8]:].split(" ")[0], props1, props2))
classes.append(transform_todots(line[obo_ids[9]:].split(")")[0]))
return makeEquivRareCase12(classes, restrs)
return None
def ParseOntology(filename):
tmp = []
annotation_props = parseProperties(filename, "# Annotation Property")
object_props = parseProperties(filename, "# Object Property")
with open (filename, 'rb') as file:
for line in file:
line = line.decode("utf-8")
if line[:7] == "# Class":
splitted = line.split(":")[2].split("(")
try:
class_id = transform_todots(splitted[0]).split(" ")[0]
class_name = splitted[1].split(")")[0]
tmp.append(CEvaluationLink(CPredicateNode("has_name"),
CListLink(CConceptNode(class_id), CConceptNode(class_name))))
except Exception:
continue
elif line[:10] == "SubClassOf":
parsed_subclass_line = parseSubclassLine(line, annotation_props, object_props)
if(parsed_subclass_line):
tmp.append(parsed_subclass_line)
elif line[:17] == "EquivalentClasses":
parsed_equivalent_line = parseEquvalentLine(line, annotation_props, object_props)
if (parsed_equivalent_line):
tmp.append(parsed_equivalent_line)
return tmp
def main():
args = parse_args()
if (not (args.dbowl)):
resp = requests.get("http://ontologies.berkeleybop.org/uberon/subsets/human-view.owl")
human_view_file = "/home/daddywesker/human-view.owl"
open(human_view_file, 'wb').write(resp.content)
else:
human_view_file = args.dbowl
db_dict = ParseOntology(human_view_file)
if (not (args.output)):
output = open("result.scm", 'wt')
else:
output = open(args.output, 'wt')
classes_to_print = '\n'.join([x.recursive_print() for x in db_dict])
output.write(classes_to_print)
output.close()
if __name__ == '__main__':
main()