18
18
19
19
from bmt .utils import format_element , parse_name
20
20
21
-
22
21
Url = str
23
22
Path = str
24
23
30
29
ASSOCIATION_SLOT = "association slot"
31
30
RELATED_TO = "related to"
32
31
33
-
34
32
CACHE_SIZE = 1024
35
33
36
34
logger = logging .getLogger (__name__ )
@@ -48,7 +46,7 @@ class Toolkit(object):
48
46
"""
49
47
50
48
def __init__ (
51
- self , schema : Union [Url , Path , TextIO , SchemaDefinition ] = REMOTE_PATH ,
49
+ self , schema : Union [Url , Path , TextIO , SchemaDefinition ] = REMOTE_PATH ,
52
50
predicate_map : Url = PREDICATE_MAP ,
53
51
infores_map : Url = INFORES_MAP
54
52
) -> None :
@@ -292,7 +290,8 @@ def _filter_secondary(self, elements: List[str]) -> List[str]:
292
290
return filtered_elements
293
291
294
292
@lru_cache (CACHE_SIZE )
295
- def get_permissible_value_ancestors (self , permissible_value : str , enum_name : str , formatted : bool = False ) -> List [str ]:
293
+ def get_permissible_value_ancestors (self , permissible_value : str , enum_name : str , formatted : bool = False ) -> List [
294
+ str ]:
296
295
"""
297
296
Get ancestors of a permissible value.
298
297
@@ -394,11 +393,11 @@ def get_permissible_value_parent(self, permissible_value: str, enum_name: str) -
394
393
395
394
@lru_cache (CACHE_SIZE )
396
395
def get_ancestors (
397
- self ,
398
- name : str ,
399
- reflexive : bool = True ,
400
- formatted : bool = False ,
401
- mixin : bool = True ,
396
+ self ,
397
+ name : str ,
398
+ reflexive : bool = True ,
399
+ formatted : bool = False ,
400
+ mixin : bool = True ,
402
401
) -> List [str ]:
403
402
"""
404
403
Gets a list of names of ancestors.
@@ -444,11 +443,11 @@ def _get_mixin_descendants(self, ancestors: List[ElementName]) -> List[ElementNa
444
443
445
444
@lru_cache (CACHE_SIZE )
446
445
def get_descendants (
447
- self ,
448
- name : str ,
449
- reflexive : bool = True ,
450
- formatted : bool = False ,
451
- mixin : bool = True ,
446
+ self ,
447
+ name : str ,
448
+ reflexive : bool = True ,
449
+ formatted : bool = False ,
450
+ mixin : bool = True ,
452
451
) -> List [str ]:
453
452
"""
454
453
Gets a list of names of descendants.
@@ -487,9 +486,27 @@ def get_descendants(
487
486
488
487
return self ._format_all_elements (filtered_desc , formatted )
489
488
489
+ @lru_cache (CACHE_SIZE )
490
+ def get_all_multivalued_slots (self ) -> List [str ]:
491
+ """
492
+ Gets a list of names of all multivalued slots.
493
+
494
+ Returns
495
+ -------
496
+ List[str]
497
+ The names of all multivalued slots
498
+
499
+ """
500
+ multivalued_slots = []
501
+ slots = self .view .all_slots ()
502
+ for slot_name , slot_def in slots .items ():
503
+ if self .view .is_multivalued (slot_name ):
504
+ multivalued_slots .append (slot_name )
505
+ return multivalued_slots
506
+
490
507
@lru_cache (CACHE_SIZE )
491
508
def get_children (
492
- self , name : str , formatted : bool = False , mixin : bool = True
509
+ self , name : str , formatted : bool = False , mixin : bool = True
493
510
) -> List [str ]:
494
511
"""
495
512
Gets a list of names of children.
@@ -568,7 +585,6 @@ def get_element(self, name: str) -> Optional[Element]:
568
585
if name in self .view .all_aliases ()[e ]:
569
586
element = self .view .get_element (e )
570
587
if element is None and "_" in name :
571
- print ("has a _" )
572
588
element = self .get_element (name .replace ("_" , " " ))
573
589
if element is None :
574
590
for e , el in self .view .all_elements ().items ():
@@ -577,11 +593,11 @@ def get_element(self, name: str) -> Optional[Element]:
577
593
return element
578
594
579
595
def get_slot_domain (
580
- self ,
581
- slot_name ,
582
- include_ancestors : bool = False ,
583
- formatted : bool = False ,
584
- mixin : bool = True ,
596
+ self ,
597
+ slot_name ,
598
+ include_ancestors : bool = False ,
599
+ formatted : bool = False ,
600
+ mixin : bool = True ,
585
601
) -> List [str ]:
586
602
"""
587
603
Get the domain for a given slot.
@@ -625,11 +641,11 @@ def get_slot_domain(
625
641
return self ._format_all_elements (slot_domain , formatted )
626
642
627
643
def get_slot_range (
628
- self ,
629
- slot_name ,
630
- include_ancestors : bool = False ,
631
- formatted : bool = False ,
632
- mixin : bool = True ,
644
+ self ,
645
+ slot_name ,
646
+ include_ancestors : bool = False ,
647
+ formatted : bool = False ,
648
+ mixin : bool = True ,
633
649
) -> List [str ]:
634
650
"""
635
651
Get the range for a given slot.
@@ -662,11 +678,11 @@ def get_slot_range(
662
678
return self ._format_all_elements (slot_range , formatted )
663
679
664
680
def get_all_slots_with_class_domain (
665
- self ,
666
- class_name ,
667
- check_ancestors : bool = False ,
668
- formatted : bool = False ,
669
- mixin : bool = True ,
681
+ self ,
682
+ class_name ,
683
+ check_ancestors : bool = False ,
684
+ formatted : bool = False ,
685
+ mixin : bool = True ,
670
686
) -> List [str ]:
671
687
"""
672
688
Given a class, get all the slots where the class is the domain.
@@ -694,11 +710,11 @@ def get_all_slots_with_class_domain(
694
710
return self ._format_all_elements (slot_names , formatted )
695
711
696
712
def get_all_slots_with_class_range (
697
- self ,
698
- class_name ,
699
- check_ancestors : bool = False ,
700
- formatted : bool = False ,
701
- mixin : bool = True ,
713
+ self ,
714
+ class_name ,
715
+ check_ancestors : bool = False ,
716
+ formatted : bool = False ,
717
+ mixin : bool = True ,
702
718
) -> List [str ]:
703
719
"""
704
720
Given a class, get all the slots where the class is the range.
@@ -726,11 +742,11 @@ def get_all_slots_with_class_range(
726
742
return self ._format_all_elements (slot_names , formatted )
727
743
728
744
def get_all_predicates_with_class_domain (
729
- self ,
730
- class_name ,
731
- check_ancestors : bool = False ,
732
- formatted : bool = False ,
733
- mixin : bool = True ,
745
+ self ,
746
+ class_name ,
747
+ check_ancestors : bool = False ,
748
+ formatted : bool = False ,
749
+ mixin : bool = True ,
734
750
) -> List [str ]:
735
751
"""
736
752
Given a class, get all Biolink predicates where the class is the domain.
@@ -764,11 +780,11 @@ def get_all_predicates_with_class_domain(
764
780
return self ._format_all_elements (filtered_slots , formatted )
765
781
766
782
def get_all_predicates_with_class_range (
767
- self ,
768
- class_name ,
769
- check_ancestors : bool = False ,
770
- formatted : bool = False ,
771
- mixin : bool = True ,
783
+ self ,
784
+ class_name ,
785
+ check_ancestors : bool = False ,
786
+ formatted : bool = False ,
787
+ mixin : bool = True ,
772
788
):
773
789
"""
774
790
Given a class, get all Biolink predicates where the class is the range.
@@ -802,11 +818,11 @@ def get_all_predicates_with_class_range(
802
818
return self ._format_all_elements (filtered_slots , formatted )
803
819
804
820
def get_all_properties_with_class_domain (
805
- self ,
806
- class_name ,
807
- check_ancestors : bool = False ,
808
- formatted : bool = False ,
809
- mixin : bool = True ,
821
+ self ,
822
+ class_name ,
823
+ check_ancestors : bool = False ,
824
+ formatted : bool = False ,
825
+ mixin : bool = True ,
810
826
) -> List [str ]:
811
827
"""
812
828
Given a class, get all Biolink properties where the class is the domain.
@@ -840,11 +856,11 @@ def get_all_properties_with_class_domain(
840
856
return self ._format_all_elements (filtered_slots , formatted )
841
857
842
858
def get_all_properties_with_class_range (
843
- self ,
844
- class_name ,
845
- check_ancestors : bool = False ,
846
- formatted : bool = False ,
847
- mixin : bool = True ,
859
+ self ,
860
+ class_name ,
861
+ check_ancestors : bool = False ,
862
+ formatted : bool = False ,
863
+ mixin : bool = True ,
848
864
) -> List [str ]:
849
865
"""
850
866
Given a class, get all Biolink properties where the class is the range.
@@ -911,7 +927,7 @@ def get_value_type_for_slot(self, slot_name, formatted: bool = False) -> str:
911
927
return element_type
912
928
913
929
def _get_all_slots_with_class_domain (
914
- self , element : Element , check_ancestors : bool , mixin : bool = True
930
+ self , element : Element , check_ancestors : bool , mixin : bool = True
915
931
) -> List [Element ]:
916
932
"""
917
933
Given a class, get all the slots where the class is the domain.
@@ -944,7 +960,7 @@ def _get_all_slots_with_class_domain(
944
960
return slots
945
961
946
962
def _get_all_slots_with_class_range (
947
- self , element : Element , check_ancestors : bool , mixin : bool = True
963
+ self , element : Element , check_ancestors : bool , mixin : bool = True
948
964
) -> List [Element ]:
949
965
"""
950
966
Given a class, get all the slots where the class is the range.
@@ -968,7 +984,7 @@ def _get_all_slots_with_class_range(
968
984
for k , v in self .view .schema .slots .items ():
969
985
if check_ancestors :
970
986
if v .range == element .name or v .range in self .get_ancestors (
971
- element .name , mixin
987
+ element .name , mixin
972
988
):
973
989
slots .append (v )
974
990
else :
@@ -1200,11 +1216,11 @@ def get_element_by_prefix(
1200
1216
1201
1217
@lru_cache (CACHE_SIZE )
1202
1218
def get_element_by_mapping (
1203
- self ,
1204
- identifier : str ,
1205
- most_specific : bool = False ,
1206
- formatted : bool = False ,
1207
- mixin : bool = True ,
1219
+ self ,
1220
+ identifier : str ,
1221
+ most_specific : bool = False ,
1222
+ formatted : bool = False ,
1223
+ mixin : bool = True ,
1208
1224
) -> Optional [str ]:
1209
1225
"""
1210
1226
Get a Biolink Model element by mapping.
@@ -1297,7 +1313,7 @@ def _get_element_by_mapping(self, identifier: str) -> List[str]:
1297
1313
1298
1314
@lru_cache (CACHE_SIZE )
1299
1315
def get_element_by_exact_mapping (
1300
- self , identifier : str , formatted : bool = False
1316
+ self , identifier : str , formatted : bool = False
1301
1317
) -> List [str ]:
1302
1318
"""
1303
1319
Given an identifier as IRI/CURIE, find a Biolink element that corresponds
@@ -1324,7 +1340,7 @@ def get_element_by_exact_mapping(
1324
1340
1325
1341
@lru_cache (CACHE_SIZE )
1326
1342
def get_element_by_close_mapping (
1327
- self , identifier : str , formatted : bool = False
1343
+ self , identifier : str , formatted : bool = False
1328
1344
) -> List [str ]:
1329
1345
"""
1330
1346
Given an identifier as IRI/CURIE, find a Biolink element that corresponds
@@ -1350,7 +1366,7 @@ def get_element_by_close_mapping(
1350
1366
1351
1367
@lru_cache (CACHE_SIZE )
1352
1368
def get_element_by_related_mapping (
1353
- self , identifier : str , formatted : bool = False
1369
+ self , identifier : str , formatted : bool = False
1354
1370
) -> List [str ]:
1355
1371
"""
1356
1372
Given an identifier as IRI/CURIE, find a Biolink element that corresponds
@@ -1376,7 +1392,7 @@ def get_element_by_related_mapping(
1376
1392
1377
1393
@lru_cache (CACHE_SIZE )
1378
1394
def get_element_by_narrow_mapping (
1379
- self , identifier : str , formatted : bool = False
1395
+ self , identifier : str , formatted : bool = False
1380
1396
) -> List [str ]:
1381
1397
"""
1382
1398
Given an identifier as IRI/CURIE, find a Biolink element that corresponds
@@ -1402,7 +1418,7 @@ def get_element_by_narrow_mapping(
1402
1418
1403
1419
@lru_cache (CACHE_SIZE )
1404
1420
def get_element_by_broad_mapping (
1405
- self , identifier : str , formatted : bool = False
1421
+ self , identifier : str , formatted : bool = False
1406
1422
) -> List [str ]:
1407
1423
"""
1408
1424
Given an identifier as IRI/CURIE, find a Biolink element that corresponds
@@ -1428,7 +1444,7 @@ def get_element_by_broad_mapping(
1428
1444
1429
1445
@lru_cache (CACHE_SIZE )
1430
1446
def get_all_elements_by_mapping (
1431
- self , identifier : str , formatted : bool = False
1447
+ self , identifier : str , formatted : bool = False
1432
1448
) -> List [str ]:
1433
1449
"""
1434
1450
Given an identifier as IRI/CURIE, find all Biolink elements that correspond
@@ -1451,7 +1467,7 @@ def get_all_elements_by_mapping(
1451
1467
return self ._format_all_elements (mappings , formatted )
1452
1468
1453
1469
def _format_all_elements (
1454
- self , elements : List [str ], formatted : bool = False
1470
+ self , elements : List [str ], formatted : bool = False
1455
1471
) -> List [str ]:
1456
1472
"""
1457
1473
Format all the elements in a given list.
0 commit comments