@@ -32,6 +32,7 @@ async def import_data(
3232 # First pass - collect all relations by source entity
3333 entity_relations : Dict [str , List [Relation ]] = {}
3434 entities : Dict [str , Dict [str , Any ]] = {}
35+ skipped_entities : int = 0
3536
3637 # Ensure the base path exists
3738 base_path = config .home # pragma: no cover
@@ -42,7 +43,13 @@ async def import_data(
4243 for line in source_data :
4344 data = line
4445 if data ["type" ] == "entity" :
45- entities [data ["name" ]] = data
46+ # Handle different possible name keys
47+ entity_name = data .get ("name" ) or data .get ("entityName" ) or data .get ("id" )
48+ if not entity_name :
49+ logger .warning (f"Entity missing name field: { data } " )
50+ skipped_entities += 1
51+ continue
52+ entities [entity_name ] = data
4653 elif data ["type" ] == "relation" :
4754 # Store relation with its source entity
4855 source = data .get ("from" ) or data .get ("from_id" )
@@ -58,25 +65,31 @@ async def import_data(
5865 # Second pass - create and write entities
5966 entities_created = 0
6067 for name , entity_data in entities .items ():
68+ # Get entity type with fallback
69+ entity_type = entity_data .get ("entityType" ) or entity_data .get ("type" ) or "entity"
70+
6171 # Ensure entity type directory exists
62- entity_type_dir = base_path / entity_data [ "entityType" ]
72+ entity_type_dir = base_path / entity_type
6373 entity_type_dir .mkdir (parents = True , exist_ok = True )
6474
75+ # Get observations with fallback to empty list
76+ observations = entity_data .get ("observations" , [])
77+
6578 entity = EntityMarkdown (
6679 frontmatter = EntityFrontmatter (
6780 metadata = {
68- "type" : entity_data [ "entityType" ] ,
81+ "type" : entity_type ,
6982 "title" : name ,
70- "permalink" : f"{ entity_data [ 'entityType' ] } /{ name } " ,
83+ "permalink" : f"{ entity_type } /{ name } " ,
7184 }
7285 ),
7386 content = f"# { name } \n " ,
74- observations = [Observation (content = obs ) for obs in entity_data [ " observations" ] ],
87+ observations = [Observation (content = obs ) for obs in observations ],
7588 relations = entity_relations .get (name , []),
7689 )
7790
7891 # Write entity file
79- file_path = base_path / f"{ entity_data [ 'entityType' ] } /{ name } .md"
92+ file_path = base_path / f"{ entity_type } /{ name } .md"
8093 await self .write_entity (entity , file_path )
8194 entities_created += 1
8295
@@ -87,6 +100,7 @@ async def import_data(
87100 success = True ,
88101 entities = entities_created ,
89102 relations = relations_count ,
103+ skipped_entities = skipped_entities ,
90104 )
91105
92106 except Exception as e : # pragma: no cover
0 commit comments