@@ -637,17 +637,36 @@ def edge_link(
637637 return edge
638638
639639
640+ def is_arangodb_id (key ):
641+ return "/" in key
642+
643+
644+ def get_node_type (key : str , default_node_type : str ) -> str :
645+ """Gets the node type."""
646+ return key .split ("/" )[0 ] if is_arangodb_id (key ) else default_node_type
647+
648+
640649def get_node_id (key : str , default_node_type : str ) -> str :
641650 """Gets the node ID."""
642- return key if "/" in key else f"{ default_node_type } /{ key } "
651+ return key if is_arangodb_id ( key ) else f"{ default_node_type } /{ key } "
643652
644653
645654def get_node_type_and_id (key : str , default_node_type : str ) -> tuple [str , str ]:
646655 """Gets the node type and ID."""
647- if "/" in key :
648- return key .split ("/" )[0 ], key
656+ return (
657+ (key .split ("/" )[0 ], key )
658+ if is_arangodb_id (key )
659+ else (default_node_type , f"{ default_node_type } /{ key } " )
660+ )
661+
662+
663+ def get_node_type_and_key (key : str , default_node_type : str ) -> tuple [str , str ]:
664+ """Gets the node type and key."""
665+ if is_arangodb_id (key ):
666+ col , key = key .split ("/" , 1 )
667+ return col , key
649668
650- return default_node_type , f" { default_node_type } / { key } "
669+ return default_node_type , key
651670
652671
653672def get_update_dict (
@@ -683,38 +702,9 @@ def check_list_for_errors(lst):
683702 return True
684703
685704
686- def is_arangodb_id (key ):
687- return "/" in key
688-
689-
690- def get_arangodb_collection_key_tuple (key ):
691- if not is_arangodb_id (key ):
692- raise ValueError (f"Invalid ArangoDB key: { key } " )
693- return key .split ("/" , 1 )
694-
695-
696- def extract_arangodb_collection_name (arangodb_id : str ) -> str :
697- if not is_arangodb_id (arangodb_id ):
698- raise ValueError (f"Invalid ArangoDB key: { arangodb_id } " )
699- return arangodb_id .split ("/" )[0 ]
700-
701-
702- def read_collection_name_from_local_id (
703- local_id : Optional [str ], default_collection : str
704- ) -> str :
705- if local_id is None :
706- print ("local_id is None, cannot read collection name." )
707- return ""
708-
709- if is_arangodb_id (local_id ):
710- return extract_arangodb_collection_name (local_id )
711-
712- assert default_collection is not None
713- assert default_collection != ""
714- return default_collection
715-
716-
717- def separate_nodes_by_collections (nodes : Any , default_collection : str ) -> Any :
705+ def separate_nodes_by_collections (
706+ nodes : dict [str , Any ], default_collection : str
707+ ) -> Any :
718708 """
719709 Separate the dictionary into collections based on whether keys contain '/'.
720710 :param nodes:
@@ -728,15 +718,12 @@ def separate_nodes_by_collections(nodes: Any, default_collection: str) -> Any:
728718 separated : Any = {}
729719
730720 for key , value in nodes .items ():
731- if is_arangodb_id (key ):
732- collection , doc_key = get_arangodb_collection_key_tuple (key )
733- if collection not in separated :
734- separated [collection ] = {}
735- separated [collection ][doc_key ] = value
736- else :
737- if default_collection not in separated :
738- separated [default_collection ] = {}
739- separated [default_collection ][key ] = value
721+ collection , doc_key = get_node_type_and_key (key , default_collection )
722+
723+ if collection not in separated :
724+ separated [collection ] = {}
725+
726+ separated [collection ][doc_key ] = value
740727
741728 return separated
742729
0 commit comments