10
10
# typically, in some DH web/templates/[schema folder]/, which reads by default
11
11
# a file called oca_bundle.json
12
12
#
13
- # > python3 ../../../script/oca_to_linkml.py [-i oca_bundle_file_name]
13
+ # > python3 ../../../script/oca_to_linkml.py [-i [ oca_bundle_file_name.json] ]
14
14
#
15
15
# Output:
16
16
#
254
254
"title" ,
255
255
"range" ,
256
256
"range_2" ,
257
+ "unit" ,
257
258
"identifier" ,
258
259
"multivalued" ,
259
260
"minimum_cardinality" ,
@@ -397,6 +398,8 @@ def writeSchemaCore():
397
398
398
399
return SCHEMA ;
399
400
401
+
402
+ ################################ SLOT OUTPUT ################################
400
403
def writeSlots ():
401
404
# Ensure SCHEMA_SLOTS has language variation
402
405
addLocaleHeaders (SCHEMA_SLOTS , ["slot_group" ,"title" ,"description" ,"comments" ,"examples" ]);
@@ -410,9 +413,11 @@ def writeSlots():
410
413
slot ['class_name' ] = SCHEMA ["name" ];
411
414
slot ['name' ] = slot_name ;
412
415
slot ['title' ] = oca_labels [slot_name ];
413
- slot ['range' ] = oca_attributes [slot_name ]; # Yeilds Type
414
- slot ['pattern' ] = oca_formats [slot_name ];
415
- slot ['description' ] = oca_informations [slot_name ];
416
+ slot ['range' ] = oca_attributes [slot_name ]; # Type is a required field?
417
+ if slot_name in oca_formats :
418
+ slot ['pattern' ] = oca_formats [slot_name ];
419
+ if slot_name in oca_informations :
420
+ slot ['description' ] = oca_informations [slot_name ];
416
421
417
422
# Minnum and maximum number of values in array of a multivalued field.
418
423
# See https://oca.colossi.network/specification/#cardinality-overlay
@@ -490,6 +495,16 @@ def writeSlots():
490
495
case "Boolean" :
491
496
pass
492
497
498
+ # OCA mentions a oca_overlays["unit"]["metric_system"] (usually = "SI"),
499
+ # So here is a place to do unit conversion to UCUM if possible.
500
+ # https://ucum.nlm.nih.gov/ucum-lhc/demo.html
501
+ if slot_name in oca_units :
502
+ # slot unit: / ucum_code: cm
503
+ if "metric_system" in oca_overlays ["unit" ]:
504
+ slot ['unit' ] = oca_overlays ["unit" ]["metric_system" ] + ":" + oca_units [slot_name ];
505
+ else :
506
+ slot ['unit' ] = oca_units [slot_name ];
507
+
493
508
# Now convert any slot datatypes where pattern matches OCA-specific data type
494
509
for type_name in SCHEMA ["types" ]:
495
510
if "pattern" in SCHEMA ["types" ][type_name ]:
@@ -509,11 +524,10 @@ def writeSlots():
509
524
#slot['comments_'+locale] # No OCA equivalent
510
525
#slot['examples_'+locale] # No OCA equivalent
511
526
512
-
513
-
514
527
save_tsv ("schema_slots.tsv" , SCHEMA_SLOTS , slots );
515
528
516
529
530
+ ################################ ENUM OUTPUT ################################
517
531
def writeEnums ():
518
532
addLocaleHeaders (SCHEMA_ENUMS , ["title" , "menu_1" ]);
519
533
enums = [];
@@ -545,8 +559,8 @@ def writeEnums():
545
559
546
560
# Load OCA schema bundle specification
547
561
if options .input_oca_file and os .path .isfile (options .input_oca_file ):
548
- with open (options .input_oca_file , "r" ) as f :
549
- oca_obj = json .load (f );
562
+ with open (options .input_oca_file , "r" ) as file_handle :
563
+ oca_obj = json .load (file_handle );
550
564
else :
551
565
os .exit ("- [Input OCA bundle file is required]" )
552
566
@@ -599,6 +613,12 @@ def writeEnums():
599
613
# attribute_entries is dictionary of [enumeration name]: {code, label}
600
614
oca_entry_labels = oca_overlays ["entry" ][0 ]["attribute_entries" ];
601
615
616
+ # Also has "metric_system": "SI",
617
+ if "unit" in oca_overlays :
618
+ oca_units = oca_overlays ["unit" ]["attribute_units" ];
619
+ else :
620
+ oca_units = {}
621
+
602
622
SCHEMA = writeSchemaCore ();
603
623
writeSlots ();
604
624
writeEnums ();
0 commit comments