|
41 | 41 | module look at their ``to_dict`` methods which write Python dictionaries in the |
42 | 42 | same format as the Khiops JSON reports. |
43 | 43 | """ |
| 44 | +import functools |
44 | 45 | import io |
45 | 46 | import warnings |
46 | 47 |
|
@@ -447,6 +448,7 @@ def __init__(self, json_data=None): |
447 | 448 | # Initialize cell |
448 | 449 | cell = CoclusteringCell() |
449 | 450 | cell.frequency = json_cell_frequencies[i] |
| 451 | + cell.part_indexes = part_indexes |
450 | 452 |
|
451 | 453 | # Initialize cell parts: |
452 | 454 | # Retrieve part from its index in the partition, per dimension |
@@ -490,19 +492,6 @@ def get_dimension(self, dimension_name): |
490 | 492 |
|
491 | 493 | def to_dict(self): |
492 | 494 | """Transforms this instance to a dict with the Khiops JSON file structure""" |
493 | | - # Compute cellPartIndexes |
494 | | - cell_parts_indexes = [] |
495 | | - for cell in self.cells: |
496 | | - cell_part_indexes = [] |
497 | | - for cell_part in cell.parts: |
498 | | - for dimension in self.dimensions: |
499 | | - for dimension_part_index, dimension_part in enumerate( |
500 | | - dimension.parts |
501 | | - ): |
502 | | - if cell_part == dimension_part: |
503 | | - cell_part_indexes.append(dimension_part_index) |
504 | | - break |
505 | | - cell_parts_indexes.append(cell_part_indexes) |
506 | 495 | report_summary = { |
507 | 496 | "instances": self.instance_number, |
508 | 497 | "cells": self.cell_number, |
@@ -532,7 +521,11 @@ def to_dict(self): |
532 | 521 | dimension.to_dict(report_type="hierarchy") |
533 | 522 | for dimension in self.dimensions |
534 | 523 | ], |
535 | | - "cellPartIndexes": cell_parts_indexes, |
| 524 | + "cellPartIndexes": functools.reduce( |
| 525 | + lambda part_indexes, cell: part_indexes + [cell.part_indexes], |
| 526 | + self.cells, |
| 527 | + [], |
| 528 | + ), |
536 | 529 | "cellFrequencies": [cell.frequency for cell in self.cells], |
537 | 530 | } |
538 | 531 | return report |
@@ -1853,13 +1846,16 @@ class CoclusteringCell: |
1853 | 1846 | ---------- |
1854 | 1847 | parts : list of `CoclusteringDimensionPart` |
1855 | 1848 | Parts for each coclustering dimension. |
| 1849 | + part_indexes : list of int |
| 1850 | + Part indexes for each coclustering dimension. |
1856 | 1851 | frequency : int |
1857 | 1852 | Frequency of this cell. |
1858 | 1853 | """ |
1859 | 1854 |
|
1860 | 1855 | def __init__(self): |
1861 | 1856 | """Constructs an instance with default attribute values""" |
1862 | 1857 | self.parts = [] |
| 1858 | + self.part_indexes = [] |
1863 | 1859 | self.frequency = 0 |
1864 | 1860 |
|
1865 | 1861 | def write_line(self, writer): # pragma: no cover |
|
0 commit comments