40
40
from os .path import exists
41
41
42
42
# import json
43
- from typing import Type
43
+ from typing import Tuple , Type
44
44
import yaml
45
45
# import urllib.request
46
46
# import requests
65
65
hxltm_index_praeparationi ,
66
66
qhxl_hxlhashtag_2_bcp47 ,
67
67
HXLTMAdRDFSimplicis ,
68
+ numerordinatio_neo_separatum ,
69
+ # numerordinatio_ordo,
70
+ # numerordinatio_progenitori,
68
71
XLSXSimplici
69
72
)
70
73
121
124
{0} --methodus='cod_ab_index' --cum-ordinibus-ex-columnis=\
122
125
'-9:#meta+id|-8:#country+code+v_iso3|-7:#country+code+v_iso2'
123
126
127
+ Work with local COD-AB index (levels) . . . . . . . . . . . . . . . . . . . . .
128
+ {0} --methodus='cod_ab_index_levels'
129
+
124
130
Process XLSXs from external sources . . . . . . . . . . . . . . . . . . . . . .
125
131
{0} --methodus=xlsx_metadata 999999/1603/45/16/xlsx/ago.xlsx
126
132
{0} --methodus=xlsx_ad_csv --ordines=2 999999/1603/45/16/xlsx/ago.xlsx
154
160
'#meta+v_iso3+alt=LOWER(#item+rem+i_qcc+is_zxxx+ix_iso3166p1a3)' \
155
161
156
162
Numerordinatio . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . .
157
- {0} --methodus=xlsx_ad_no1 --ordines=1 \
158
- --numerordinatio-praefixo=1603_45_16 --pcode-praefixo=AO --unm49=24 \
159
- 999999/1603/45/16/xlsx/ago.xlsx
163
+ {0} --methodus=xlsx_ad_no1 \
164
+ --numerordinatio-praefixo=1603_45_16 --unm49=24 --ordines=1 \
165
+ --pcode-praefixo=AO 999999/1603/45/16/xlsx/ago.xlsx
160
166
161
167
162
168
Index preparation (warn up cache) . . . . . . . . . . . . . . . . . . . . . . .
@@ -245,6 +251,7 @@ def make_args(self, hxl_output=True):
245
251
# 'pcode_ex_xlsx',
246
252
# 'pcode_ex_csv',
247
253
'cod_ab_index' ,
254
+ 'cod_ab_index_levels' ,
248
255
'cod_ab_ad_rdf_skos_ttl' ,
249
256
'de_hxltm_ad_hxltm' , # load main file directly
250
257
# load main file by number (example: 1603_45_49)
@@ -599,23 +606,23 @@ def execute_cli(self, pyargs, stdin=STDIN, _stdout=sys.stdout,
599
606
if pyargs .venandum_insectum or VENANDUM_INSECTUM :
600
607
self .venandum_insectum = True
601
608
602
- # if stdin.isatty():
603
- # _infile = pyargs.infile
604
- # _stdin = False
605
- # else:
606
- # if pyargs.methodus in ['xlsx_metadata', 'de_librario']:
607
- # # print(' oi pyargs.infile', pyargs.infile)
608
- # raise ValueError(
609
- # 'stdin not implemented for {0} input'.format(
610
- # pyargs.methodus))
611
- # _infile = None
612
- # _stdin = True
609
+ if stdin .isatty ():
610
+ _infile = pyargs .infile
611
+ _stdin = False
612
+ else :
613
+ # if pyargs.methodus in ['xlsx_metadata', 'de_librario']:
614
+ # # print(' oi pyargs.infile', pyargs.infile)
615
+ # raise ValueError(
616
+ # 'stdin not implemented for {0} input'.format(
617
+ # pyargs.methodus))
618
+ # _infile = None
619
+ _stdin = True
613
620
614
621
_infile = pyargs .infile
615
-
622
+ # raise NotImplementedError(pyargs.methodus)
616
623
if pyargs .methodus in [
617
624
'de_hxltm_ad_hxltm' , 'de_librario' ,
618
- 'index_praeparationi' , 'cod_ab_index' ]:
625
+ 'index_praeparationi' , 'cod_ab_index' , 'cod_ab_index_levels' ]:
619
626
# Decide which main file to load.
620
627
# if pyargs.methodus.startswith('de_librario'):
621
628
if pyargs .methodus .startswith (
@@ -632,6 +639,13 @@ def execute_cli(self, pyargs, stdin=STDIN, _stdout=sys.stdout,
632
639
elif pyargs .methodus .startswith ('cod_ab_index' ):
633
640
caput , data = hxltm_carricato (COD_AB_INDEX )
634
641
642
+ if pyargs .methodus == 'cod_ab_index_levels' :
643
+ # @TODO cod_ab_index_levels
644
+ # caput, data = hxltm_carricato(COD_AB_INDEX)
645
+ # raise NotImplementedError(pyargs.methodus)
646
+
647
+ caput , data = hxltm_carricato__cod_ab_levels (caput , data )
648
+
635
649
est_data_referentibus = hxltm__est_data_referentibus (
636
650
pyargs .adde_columnis ,
637
651
pyargs .ex_selectis ,
@@ -982,30 +996,43 @@ def actio(self):
982
996
# print('failed')
983
997
984
998
985
- def numerordinatio_neo_separatum (
986
- numerordinatio : str , separatum : str = "_" ) -> str :
987
- resultatum = ''
988
- resultatum = numerordinatio .replace ('_' , separatum )
989
- resultatum = resultatum .replace ('/' , separatum )
990
- resultatum = resultatum .replace (':' , separatum )
991
- # TODO: add more as need
992
- return resultatum
999
+ def hxltm_carricato__cod_ab_levels (
1000
+ caput : list , data : list , numerordinatio_praefixo : str = '1603_45_16'
1001
+ ) -> Tuple [list , list ]:
1002
+ """hxltm_carricato__cod_ab_levels filter cod_ab_index into a list of levels
993
1003
1004
+ Args:
1005
+ caput (list): _description_
1006
+ data (list): _description_
994
1007
995
- def numerordinatio_ordo (numerordinatio : str ) -> int :
996
- normale = numerordinatio_neo_separatum (numerordinatio , '_' )
997
- return (normale .count ('_' ) + 1 )
998
-
999
-
1000
- def numerordinatio_progenitori (
1001
- numerordinatio : str , separatum : str = "_" ) -> int :
1002
- # prōgenitōrī, s, m, dativus, https://en.wiktionary.org/wiki/progenitor
1003
- normale = numerordinatio_neo_separatum (numerordinatio , separatum )
1004
- _parts = normale .split (separatum )
1005
- _parts = _parts [:- 1 ]
1006
- if len (_parts ) == 0 :
1007
- return "0"
1008
- return separatum .join (_parts )
1008
+ Returns:
1009
+ Tuple[list, list]: _description_
1010
+ """
1011
+ columnae = [
1012
+ '#country+code+v_unm49' ,
1013
+ '#meta+source+cod_ab_level' ,
1014
+ ]
1015
+ # print(' ooi')
1016
+
1017
+ caput , data = hxltm_cum_aut_sine_columnis_simplicibus (
1018
+ caput , data , columnae )
1019
+ # _ordo_novo = []
1020
+ numerordinatio_praefixo = numerordinatio_neo_separatum (
1021
+ numerordinatio_praefixo , ':' )
1022
+ caput_novo = ['#item+conceptum+numerordinatio' ]
1023
+ caput_novo .extend (caput )
1024
+ data_novis = []
1025
+ for linea in data :
1026
+ linea_novae = []
1027
+ linea_novae .append ('{0}:{1}:{2}' .format (
1028
+ numerordinatio_praefixo , linea [0 ], linea [1 ]
1029
+ ))
1030
+ linea_novae .extend (linea )
1031
+ data_novis .append (linea_novae )
1032
+
1033
+ # raise NotImplementedError
1034
+ # return caput, data
1035
+ return caput_novo , data_novis
1009
1036
1010
1037
1011
1038
if __name__ == "__main__" :
0 commit comments