34
34
have_kg_core = False
35
35
36
36
from .errors import AuthenticationError , AuthorizationError , ResourceExistsError
37
+ from .registry import lookup_type
37
38
38
39
if TYPE_CHECKING :
39
40
from .kgobject import KGObject
@@ -583,7 +584,10 @@ def configure_space(self, space_name: Optional[str] = None, types: Optional[List
583
584
space_name = f"collab-{ collab_id } "
584
585
result = self ._kg_admin_client .create_space_definition (space = space_name )
585
586
if result : # error
586
- raise Exception (f"Unable to configure KG space for space '{ space_name } ': { result } " )
587
+ err_msg = f"Unable to configure KG space for space '{ space_name } ': { result } "
588
+ if not space_name .startswith ("collab=" ):
589
+ err_msg += f". If you are trying to configure a collab space, ensure the space name starts with 'collab-'"
590
+ raise Exception (err_msg )
587
591
for cls in types :
588
592
result = self ._kg_admin_client .assign_type_to_space (space = space_name , target_type = cls .type_ )
589
593
if result : # error
@@ -601,6 +605,29 @@ def move_to_space(self, uri: str, destination_space: str):
601
605
if response .error :
602
606
raise Exception (response .error )
603
607
608
+ def space_info (self , space_name : str , scope : str = "released" ):
609
+ """
610
+ Return information about the types and number of instances in a space.
611
+
612
+ The return format is a dictionary whose keys are classes and the values are the
613
+ number of instances of each class in the given spaces.
614
+ """
615
+ result = self ._kg_client .types .list (space = space_name , stage = STAGE_MAP [scope ])
616
+ if result .error :
617
+ raise Exception (result .error )
618
+ response = {}
619
+ for item in result .data :
620
+ try :
621
+ cls = lookup_type (item .identifier )
622
+ except KeyError as err :
623
+ if "vocab/meta/type/Query" in str (err ):
624
+ pass
625
+ else :
626
+ raise
627
+ else :
628
+ response [cls ] = item .occurrences
629
+ return response
630
+
604
631
def is_released (self , uri : str , with_children : bool = False ) -> bool :
605
632
"""
606
633
Release status of a KG instance identified by its URI.
0 commit comments