4444 PictureTabularChartData ,
4545 ProvenanceItem ,
4646 SectionHeaderItem ,
47+ TableData ,
4748 TableItem ,
4849 TextItem ,
4950)
@@ -233,13 +234,22 @@ def serialize(
233234 ysize = params .ysize ,
234235 )
235236
236- classifications = [
237- ann
238- for ann in item .annotations
239- if isinstance (ann , PictureClassificationData )
240- ]
241- if len (classifications ) > 0 :
237+ # handle classification data
238+ predicted_class : Optional [str ] = None
239+ if item .meta and item .meta .classification :
240+ predicted_class = (
241+ item .meta .classification .get_main_prediction ().class_name
242+ )
243+ elif (
244+ classifications := [
245+ ann
246+ for ann in item .annotations
247+ if isinstance (ann , PictureClassificationData )
248+ ]
249+ ) and classifications [0 ].predicted_classes :
242250 predicted_class = classifications [0 ].predicted_classes [0 ].class_name
251+ if predicted_class :
252+ body += DocumentToken .get_picture_classification_token (predicted_class )
243253 if predicted_class in [
244254 PictureClassificationLabel .PIE_CHART ,
245255 PictureClassificationLabel .BAR_CHART ,
@@ -250,26 +260,31 @@ def serialize(
250260 PictureClassificationLabel .HEATMAP ,
251261 ]:
252262 is_chart = True
253- body += DocumentToken .get_picture_classification_token (predicted_class )
254263
255- smiles_annotations = [
264+ # handle molecule data
265+ smi : Optional [str ] = None
266+ if item .meta and item .meta .molecule :
267+ smi = item .meta .molecule .smi
268+ elif smiles_annotations := [
256269 ann for ann in item .annotations if isinstance (ann , PictureMoleculeData )
257- ]
258- if len (smiles_annotations ) > 0 :
259- body += _wrap (
260- text = smiles_annotations [0 ].smi , wrap_tag = DocumentToken .SMILES .value
261- )
262-
263- tabular_chart_annotations = [
270+ ]:
271+ smi = smiles_annotations [0 ].smi
272+ if smi :
273+ body += _wrap (text = smi , wrap_tag = DocumentToken .SMILES .value )
274+
275+ # handle tabular chart data
276+ chart_data : Optional [TableData ] = None
277+ if item .meta and item .meta .tabular_chart :
278+ chart_data = item .meta .tabular_chart .chart_data
279+ elif tabular_chart_annotations := [
264280 ann
265281 for ann in item .annotations
266282 if isinstance (ann , PictureTabularChartData )
267- ]
268- if len (tabular_chart_annotations ) > 0 :
283+ ]:
284+ chart_data = tabular_chart_annotations [0 ].chart_data
285+ if chart_data and chart_data .table_cells :
269286 temp_doc = DoclingDocument (name = "temp" )
270- temp_table = temp_doc .add_table (
271- data = tabular_chart_annotations [0 ].chart_data
272- )
287+ temp_table = temp_doc .add_table (data = chart_data )
273288 otsl_content = temp_table .export_to_otsl (
274289 temp_doc , add_cell_location = False
275290 )
0 commit comments