From bf8e08883a3b9afc5eadbcde533c4b0adf864074 Mon Sep 17 00:00:00 2001 From: Emerson Rocha Date: Wed, 25 May 2022 03:12:40 -0300 Subject: [PATCH] 999999999_7200235.py (#39): hxltm_carricato__cod_ab_levels_ttl() improved --- officina/999999999/0/999999999_7200235.py | 41 +++++++++++++++---- officina/999999999/0/L999999999_0.py | 48 ++++++++++++++++++++--- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/officina/999999999/0/999999999_7200235.py b/officina/999999999/0/999999999_7200235.py index 87e0488..62a1722 100755 --- a/officina/999999999/0/999999999_7200235.py +++ b/officina/999999999/0/999999999_7200235.py @@ -63,6 +63,7 @@ # hxltm_sine_columnis, hxltm_ex_selectis, hxltm_index_praeparationi, + numerordinatio_descendentibus, numerordinatio_progenitori, qhxl_hxlhashtag_2_bcp47, HXLTMAdRDFSimplicis, @@ -1086,7 +1087,7 @@ def hxltm_carricato__cod_ab_levels( def hxltm_carricato__cod_ab_levels_ttl( - caput: list, data: list, numerordinatio_praefixo: str = '1603_45_16' + caput: list, data: list, numerordinatio_praefixo: str = '1603:45:16' ) -> list: """hxltm_carricato__cod_ab_levels filter cod_ab_index into a list of levels @@ -1100,17 +1101,43 @@ def hxltm_carricato__cod_ab_levels_ttl( """ paginae = [] - print('caput', caput) + # note, on this case, we get an list already with only the root + # items, so we have to deal with # https://www.wikidata.org/wiki/EntitySchema:E49 - # paginae.append('# [{0}]'.format( - # numerordinatio_progenitori(numerordinatio_praefixo, ':'))) - # paginae.append('@prefix skos: .') + basi = numerordinatio_neo_separatum(numerordinatio_praefixo, ':') + + +# a skos:ConceptScheme ; +# skos:prefLabel "1603:63:101"@mul-Zyyy-x-n1603 . - # for linea in data: - # paginae.append(''.format(linea[0])) + collectio = map(lambda x: x[0], data) + collectio_sine_ordo = set(map( + lambda x: numerordinatio_progenitori(x, ':'), collectio)) + # print(collectio_sine_ordo) + + paginae.append('# [{0}]'.format(basi)) + paginae.append('@prefix skos: .') + paginae.append('') + paginae.append(" a skos:ConceptScheme ; \n" + " skos:prefLabel \"{0}\"@mul-Zyyy-x-n1603 .".format( + basi)) + paginae.append(" skos:hasTopConcept\n {0} .".format( + " ,\n ".join(map(lambda x: f'', collectio_sine_ordo )) + )) + for linea in data: + progenitori = numerordinatio_progenitori(linea[0], ':') + descendentibus = numerordinatio_descendentibus( + progenitori, collectio, 1) + # paginae.append(''.format(linea[0])) # paginae.append(' # {0}'.format(str(linea))) + # + # # ['1603:45:16:76:0', '76', 0, 'BRA', 'BR'] + # + # # ['1603:45:16:76:1', '76', 1, 'BRA', 'BR'] + # + # # ['1603:45:16:76:2', '76', 2, 'BRA', 'BR'] return paginae diff --git a/officina/999999999/0/L999999999_0.py b/officina/999999999/0/L999999999_0.py index 5dd54f2..241cea1 100644 --- a/officina/999999999/0/L999999999_0.py +++ b/officina/999999999/0/L999999999_0.py @@ -670,9 +670,9 @@ def praeparatio_identitas_locali(self): if pcode_index is None: raise SyntaxError( '{0} not in (hxltm)<{1}>/(hxl)<{2}>(csv){3}'.format( - pcode_hashtag, self.caput_hxltm, - self.caput_hxl, self.caput_originali - )) + pcode_hashtag, self.caput_hxltm, + self.caput_hxl, self.caput_originali + )) # pcode_index = self.caput_hxltm.index(pcode_hashtag) self.caput_hxltm.insert(0, '#item+conceptum+codicem') @@ -688,8 +688,8 @@ def praeparatio_identitas_locali(self): # Ex. 31 ad BR31 pcode_numeri = pcode_completo.replace(self.pcode_praefixo, '') - ## Ex: Haiti admin3Pcode HT0111-01, HT0111-02, HT0111-03 - pcode_numeri = re.sub('[^0-9]','', pcode_numeri) + # Ex: Haiti admin3Pcode HT0111-01, HT0111-02, HT0111-03 + pcode_numeri = re.sub('[^0-9]', '', pcode_numeri) try: linea_novae.append(int(pcode_numeri)) @@ -2832,6 +2832,44 @@ def qhxl_hxlhashtag_2_bcp47( return bcp47_simplici +def numerordinatio_descendentibus( + numerordinatio: str, collectio: list, ordo_maximo: int = None) -> list: + """numerordinatio_descendentibus _summary_ + + Trivia: + - collēctiō, s, f, , nominativus + - dēscendentibus, pl, m/f/n, , dativus, + https://en.wiktionary.org/wiki/descendens#Latin + - ōrdō, s, m, nominativus, https://en.wiktionary.org/wiki/ordo#Latin + - ōrdinī, s, m, dativus, + - maximō, s, m/n, dativus, https://en.wiktionary.org/wiki/maximus#Latin + + Args: + numerordinatio (str): _description_ + collectio (list): _description_ + ordo_maximo (int, optional): _description_. Defaults to None. + + Returns: + list: _description_ + """ + + resultatum = [] + + if ordo_maximo is not None: + ordo_maximo = ordo_maximo + numerordinatio_ordo(numerordinatio) + + for item in collectio: + if item.startswith(numerordinatio) and item != numerordinatio: + if ordo_maximo is None: + resultatum.append(item) + else: + item_ordini = numerordinatio_ordo(item) + if item_ordini <= ordo_maximo: + resultatum.append(item) + + return resultatum + + def numerordinatio_neo_separatum( numerordinatio: str, separatum: str = "_") -> str: resultatum = ''