From 911e501ab3b47d0ef30839cf6d84a101d1164dd6 Mon Sep 17 00:00:00 2001 From: Emerson Rocha Date: Fri, 20 May 2022 23:12:30 -0300 Subject: [PATCH] 999999999_0.py (#42): cached index already able to be created at 999999/0/{1}.index.json --- officinam/999999999/0/999999999_7200235.py | 28 +++++++++-- officinam/999999999/0/L999999999_0.py | 58 +++++++++++++++++----- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/officinam/999999999/0/999999999_7200235.py b/officinam/999999999/0/999999999_7200235.py index 9119c0d..8cda29c 100755 --- a/officinam/999999999/0/999999999_7200235.py +++ b/officinam/999999999/0/999999999_7200235.py @@ -127,6 +127,7 @@ --ex-selectis='#item+conceptum+codicem==1' Index preparation (warn up cache) . . . . . . . . . . . . . . . . . . . . . . . +(this will pre-create a key-value index at 999999/0/i1603_45_49.index.json) {0} --methodus=index_praeparationi 1603_45_49 \ --index-nomini=i1603_45_49 \ --ex-columnis='#item+rem+i_zxx+is_zmth+ix_unm49,\ @@ -532,10 +533,29 @@ def execute_cli(self, pyargs, stdin=STDIN, _stdout=sys.stdout, if pyargs.methodus == 'index_praeparationi': - caput, data = hxltm_index_praeparationi(caput, data) - # ex_columnis = pyargs.ex_columnis.split(',') - # caput, data = hxltm_ex_columnis(caput, data, ex_columnis) - print('TODO') + if pyargs.index_nomini: + index_nomini = pyargs.index_nomini + else: + # In this case, _infile is just a string like 1603_45_49 + index_nomini = 'i{0}'.format(str(_infile)) + + data_json = hxltm_index_praeparationi( + caput, data, pyargs.index_ad_columnam) + + data_json_str = json.dumps( + data_json, indent=4, sort_keys=False, ensure_ascii=False) + + # print(data_json_str) + + _path = '{0}/999999/0/{1}.index.json'.format( + NUMERORDINATIO_BASIM, + index_nomini, + ) + + with open(_path, "w") as file1: + file1.write(data_json_str) + print('index: {0}'.format(_path)) + return self.EXIT_OK csv_imprimendo(caput, data) diff --git a/officinam/999999999/0/L999999999_0.py b/officinam/999999999/0/L999999999_0.py index 0b018e1..5b6cd32 100644 --- a/officinam/999999999/0/L999999999_0.py +++ b/officinam/999999999/0/L999999999_0.py @@ -1743,7 +1743,9 @@ def hxltm_ex_selectis( def hxltm_index_praeparationi( - caput: list, data: list, index_ad_columnam: str) -> dict: + caput: list, data: list, + index_ad_columnam: str = None, strictum: bool = False +) -> dict: """hxltm_index_praeparationi add new columns (variables) Trivia: @@ -1755,25 +1757,55 @@ def hxltm_index_praeparationi( caput (list): _description_ data (list): _description_ index_ad_columnam (str): _description_ + strictum (str): raise errors if same source keys can point to different + objective indexes. Returns: dict: _description_ """ - # https://en.wiktionary.org/wiki/columna#Latin - index_columnae = [] - _data = [] - raise NotImplementedError - # print(caput, columnae) - for item in columnae: - index_columnae.append(caput.index(item)) + + if strictum: + raise NotImplementedError('{0} strictum'.format( + 'hxltm_index_praeparationi')) + + if not index_ad_columnam: + index_ad_columnam = 0 + else: + index_ad_columnam = caput.index(index_ad_columnam) + + _data_json = {} + data_json = {} for linea in data: - _linea = [] - for index in index_columnae: - _linea.append(linea[index]) - _data.append(_linea) + _clavis_ad = linea[index_ad_columnam] + _clavis_ex = set() + for res in linea: + if res: + _clavis_ex.add(res) + for item in _clavis_ex: + _data_json[item] = _clavis_ad + + _claves_n = [] + _claves_l = [] + _clāvēs_nl = [] + + for item in _data_json.keys(): + if item.isnumeric(): + _claves_n.append(item) + else: + _claves_l.append(item) - # _caput = columnae + if len(_claves_n) > 0: + _clāvēs_nl.extend(sorted(_claves_n, key=lambda x: int(x))) + + if len(_claves_l) > 0: + _claves_l.sort(key=lambda item: (len(item), item)) + _clāvēs_nl.extend(_claves_l) + + for item in _clāvēs_nl: + data_json[item] = _data_json[item] + + return data_json def hxltm_per_columnas(