Omkar008 commited on
Commit
0249415
·
verified ·
1 Parent(s): 2abbb8c

Update extract_and_store_supabase.py

Browse files
Files changed (1) hide show
  1. extract_and_store_supabase.py +23 -2
extract_and_store_supabase.py CHANGED
@@ -83,19 +83,40 @@ def extract_structure_store_message(user_id:str,message_id:str , attachment_id:s
83
  for ent in entities:
84
  if ent.get('type') is not None:
85
  entity_type = ent.get('type')
 
 
86
  if entity_type in allowed_entities:
87
  mention_text = ent.get('mentionText')
88
  normalized_values = ent.get('normalizedValue') if 'normalizedValue' in ent else None
89
-
90
  # Initialize a list for the entity type if not already present
91
  if entity_type not in document_entities:
92
  document_entities[entity_type] = []
93
-
94
  # Append the entity data to the list
95
  document_entities[entity_type].append({
96
  "mention_text": mention_text,
97
  "normalizedValue": normalized_values
98
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  document_entities['email'] = email
100
  document_entities['message_id'] = message_id
101
  print(document_entities)
 
83
  for ent in entities:
84
  if ent.get('type') is not None:
85
  entity_type = ent.get('type')
86
+
87
+ # Check if the entity type is in the allowed list
88
  if entity_type in allowed_entities:
89
  mention_text = ent.get('mentionText')
90
  normalized_values = ent.get('normalizedValue') if 'normalizedValue' in ent else None
91
+
92
  # Initialize a list for the entity type if not already present
93
  if entity_type not in document_entities:
94
  document_entities[entity_type] = []
95
+
96
  # Append the entity data to the list
97
  document_entities[entity_type].append({
98
  "mention_text": mention_text,
99
  "normalizedValue": normalized_values
100
  })
101
+
102
+ # Handling 'line_item' and its properties (line_item/description, line_item/quantity, etc.)
103
+ if entity_type == 'line_item' and 'properties' in ent:
104
+ for prop in ent['properties']:
105
+ prop_type = prop.get('type')
106
+ if prop_type in allowed_entities:
107
+ mention_text = prop.get('mentionText')
108
+ normalized_values = prop.get('normalizedValue') if 'normalizedValue' in prop else None
109
+
110
+ # Initialize a list for the property type if not already present
111
+ if prop_type not in document_entities:
112
+ document_entities[prop_type] = []
113
+
114
+ # Append the property data to the list
115
+ document_entities[prop_type].append({
116
+ "mention_text": mention_text,
117
+ "normalizedValue": normalized_values
118
+ })
119
+
120
  document_entities['email'] = email
121
  document_entities['message_id'] = message_id
122
  print(document_entities)