11from  collections  import  Counter 
2+ import  asyncio 
3+ from  tqdm .asyncio  import  tqdm  as  tqdm_async 
4+ 
25from  utils .format  import  split_string_by_multi_markers 
6+ from  utils  import  logger , detect_main_language 
37from  models  import  TopkTokenModel , Tokenizer 
48from  models .storage .base_storage  import  BaseGraphStorage 
59from  templates  import  KG_SUMMARIZATION_PROMPT , KG_EXTRACTION_PROMPT 
6- from  utils  import  logger , detect_main_language 
7- from  tqdm .asyncio  import  tqdm  as  tqdm_async 
8- import  asyncio 
910
1011async  def  _handle_kg_summary (
1112    entity_or_relation_name : str ,
@@ -100,11 +101,11 @@ async def process_single_node(entity_name: str, node_data: list[dict]):
100101                set ([dp ["source_id" ] for  dp  in  node_data ] +  source_ids )
101102            )
102103
103-             node_data  =  dict ( 
104-                 entity_type = entity_type ,
105-                 description = description ,
106-                 source_id = source_id 
107-             ) 
104+             node_data  =  { 
105+                 " entity_type" :  entity_type ,
106+                 " description" :  description ,
107+                 " source_id" :  source_id 
108+             } 
108109            await  kg_instance .upsert_node (
109110                entity_name ,
110111                node_data = node_data 
@@ -124,7 +125,7 @@ async def process_single_node(entity_name: str, node_data: list[dict]):
124125    ):
125126        try :
126127            entities_data .append (await  result )
127-         except  Exception  as  e :
128+         except  Exception  as  e :  # pylint: disable=broad-except 
128129            logger .error ("Error occurred while inserting entities into storage: %s" , e )
129130
130131
@@ -168,7 +169,7 @@ async def process_single_edge(src_id: str, tgt_id: str, edge_data: list[dict]):
168169            )
169170
170171            for  insert_id  in  [src_id , tgt_id ]:
171-                 if  not  ( await  kg_instance .has_node (insert_id ) ):
172+                 if  not  await  kg_instance .has_node (insert_id ):
172173                    await  kg_instance .upsert_node (
173174                        insert_id ,
174175                        node_data = {
@@ -185,17 +186,17 @@ async def process_single_edge(src_id: str, tgt_id: str, edge_data: list[dict]):
185186            await  kg_instance .upsert_edge (
186187                src_id ,
187188                tgt_id ,
188-                 edge_data = dict ( 
189-                     description = description ,
190-                     source_id = source_id 
191-                 ) 
189+                 edge_data = { 
190+                     "source_id" :  source_id ,
191+                     "description" :  description 
192+                 } 
192193            )
193194
194-             edge_data  =  dict ( 
195-                 src_id = src_id ,
196-                 tgt_id = tgt_id ,
197-                 description = description , 
198-             ) 
195+             edge_data  =  { 
196+                 " src_id" :  src_id ,
197+                 " tgt_id" :  tgt_id ,
198+                 " description" :  description 
199+             } 
199200            return  edge_data 
200201
201202    logger .info ("Inserting relationships into storage..." )
@@ -210,5 +211,5 @@ async def process_single_edge(src_id: str, tgt_id: str, edge_data: list[dict]):
210211    ):
211212        try :
212213            relationships_data .append (await  result )
213-         except  Exception  as  e :
214+         except  Exception  as  e :  # pylint: disable=broad-except 
214215            logger .error ("Error occurred while inserting relationships into storage: %s" , e )
0 commit comments