Skip to content

Commit

Permalink
999999999_521850.py (#43): improved way to generate HXLTM from HXL
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Jul 30, 2022
1 parent 1c7eb32 commit 8ea96f2
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 19 deletions.
74 changes: 64 additions & 10 deletions officina/999999999/0/999999999_521850.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
{0} --methodus-fonti=unwpf
(Total population)
{0} --methodus-fonti=worldbank --methodus=SP.POP.TOTL
{0} --methodus-fonti=worldbank --methodus=SP.POP.TOTL \
Expand All @@ -118,7 +119,10 @@
{0} --methodus-fonti=worldbank --methodus=SP.POP.TOTL \
--objectivum-formato=hxltm
{0} --methodus-fonti=sdmx-tests
(Rural population)
{0} --methodus-fonti=worldbank --methodus=SP.RUR.TOTL \
--objectivum-formato=hxltm
(Individual humans) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
See https://interpol.api.bund.dev/
Expand All @@ -135,6 +139,10 @@
{0} --methodus-fonti=interpol --methodus=un --objectivum-formato=hxltm \
--archivum-objetivum=999999/0/interpol-un.tm.hxl.csv
(Etc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
{0} --methodus-fonti=sdmx-tests
------------------------------------------------------------------------------
EXEMPLŌRUM GRATIĀ
------------------------------------------------------------------------------
Expand Down Expand Up @@ -186,6 +194,33 @@
'_links.self': '#item+url', # INTERPOL
}

DATA_HXLTM_DE_HXL_GENERIC = {
'#meta+rem+i_eng+is_latn+name': '#country+name',

# Population statistics, with year -----------------------------------------
# population (P1082)
'#item+rem+i_qcc+is_zxxx+ix_iso8601v{v1}+ix_xywdatap1082': r"^#population\+t\+year(?P<v1>[0-9]{4})$",
# female population (P1539)
'#item+rem+i_qcc+is_zxxx+ix_iso8601v{v1}+ix_xywdatap1539': r"^#population\+f\+year(?P<v1>[0-9]{4})$",
# male population (P1540)
'#item+rem+i_qcc+is_zxxx+ix_iso8601v{v1}+ix_xywdatap1540': r"^#population\+m\+year(?P<v1>[0-9]{4})$",
# rural population (P6344)
'#item+rem+i_qcc+is_zxxx+ix_iso8601v{v1}+ix_xywdatap6344': r"^#population\+rural\+year(?P<v1>[0-9]{4})$",
# urban population (P6343)
'#item+rem+i_qcc+is_zxxx+ix_iso8601v{v1}+ix_xywdatap6343': r"^#population\+urban\+year(?P<v1>[0-9]{4})$",

# Houseolds? No data with this yet
# https://www.wikidata.org/wiki/Property:P1538

# Population statistics, without year -------------------------------------
# population (P1082)
# '#item+rem+i_qcc+is_zxxx+ix_xywdatap1082': r"^#population\+t$",
# # female population (P1539)
# '#item+rem+i_qcc+is_zxxx+ix_xywdatap1539': r"^#population\+f$",
# # male population (P1540)
# '#item+rem+i_qcc+is_zxxx+ix_xywdatap1540': r"^#population\+m$",
}

DATA_HXL_DE_CSV_REGEX = {
# @see https://data.humdata.org/tools/hxl-example/
# @see https://data.worldbank.org/indicator
Expand All @@ -194,6 +229,11 @@
# Population statistics, thematic
# Only for numeric
'SP.POP.TOTL': '#population+t+year{0}',

# https://data.worldbank.org/indicator/SP.RUR.TOTL
# https://www.wikidata.org/wiki/Property:P6344
# 'SP.RUR.TOTL': '#population+ix_xywdatap6344+year{0}',
'SP.RUR.TOTL': '#population+rural+year{0}',
# https://data.worldbank.org/indicator/SP.POP.TOTL.MA.IN
'SP.POP.TOTL.MA.IN': '#population+m+year{0}',
# https://data.worldbank.org/indicator/SP.POP.TOTL.FE.IN
Expand Down Expand Up @@ -680,20 +720,34 @@ def _hxltmize(self, caput: list):
if not res:
resultatum.append('')
continue
if res.lower().strip() in DATA_HXL_DE_CSV_GENERIC:
resultatum.append(DATA_HXL_DE_CSV_GENERIC[res.lower().strip()])
continue

if self.methodus in DATA_HXL_DE_CSV_REGEX['worldbank'].keys():
if len(res) == 4:
resultatum.append(DATA_HXL_DE_CSV_REGEX[
'worldbank'][self.methodus].format(res))
_done = False
for _ht_novo, _ht_retest in DATA_HXLTM_DE_HXL_GENERIC.items():

if isinstance(_ht_retest, str) and _ht_retest == res:
resultatum.append(_ht_novo)
_done = True
break

_resultatum = re.match(_ht_retest, res)
if not _resultatum:
continue
_vars = _resultatum.groupdict()
if _vars and len(_vars.keys()) > 0:
resultatum.append(_ht_novo.format_map(_vars))
else:
resultatum.append(_ht_novo)
_done = True
break

if _done is True:
continue

resultatum.append(
'#meta+{0}'.format(
'#meta+rem+i_qcc+is_zxxx+{0}'.format(
res.lower().strip().replace(
' ', '').replace('-', '_'))
' ', '').replace('-', '_').replace(
'#', '').replace('+', '_'))
)
return resultatum

Expand Down
18 changes: 13 additions & 5 deletions officina/999999999/0/999999999_54872.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,19 @@ def execute_cli(self, pyargs, stdin=STDIN, stdout=sys.stdout,
if pyargs.methodus == '_temp_no1':
caput_novo = []
for _item in caput:
# print('hxl item > ', _item)
_hxl = HXLHashtagSimplici(_item).praeparatio()
_item_bcp47 = _hxl.quod_bcp47(strictum=False)
# print('_item_bcp47 > ', _item_bcp47)
caput_novo.append(_item_bcp47)
if not _item or len(_item) == 0:
raise SyntaxError(
'Input have empty hashtag, <{0}>'.format(caput))
# print('hxl item > ', _item, caput)
try:
_hxl = HXLHashtagSimplici(_item).praeparatio()
_item_bcp47 = _hxl.quod_bcp47(strictum=False)
# print('_item_bcp47 > ', _item_bcp47)
caput_novo.append(_item_bcp47)
except AttributeError:
# raise SyntaxError('HXLTM/No1 non hashtag[{0}]? <{1}>'.format(_item, caput))
raise SyntaxError(
'HXLTM/No1 non hashtag[{0}]?'.format(_item))
caput = caput_novo
# print('caput', caput)

Expand Down
22 changes: 18 additions & 4 deletions officina/999999999/999999_17.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,29 @@ set -x

./999999999/0/999999999_521850.py \
--methodus-fonti=worldbank \
--methodus="SP.POP.TOTL.MA.IN" \
--methodus="SP.POP.TOTL" \
--objectivum-formato=no1 \
>"999999/0/1603_992_1_0~worldbank~SP_POP_TOTL.no1.tm.hxl.csv"


./999999999/0/999999999_54872.py \
--methodus=_temp_no1 \
--rdf-sine-spatia-nominalibus=devnull \
--rdf-trivio=1603 \
"999999/0/1603_992_1_0~worldbank~SP_POP_TOTL.no1.tm.hxl.csv" \
>"999999/0/1603_992_1_0~worldbank~SP_POP_TOTL.no1.owl.ttl"

./999999999/0/999999999_521850.py \
--methodus-fonti=worldbank \
--methodus="SP.RUR.TOTL" \
--objectivum-formato=hxltm \
>"999999/0/1603_992_1_0~worldbank~SP_POP_TOTL_MA_IN.tm.hxl.csv"
>"999999/0/1603_992_1_0~worldbank~SP_RUR_TOTL.tm.hxl.csv"

./999999999/0/999999999_521850.py \
--methodus-fonti=worldbank \
--methodus="SP.POP.TOTL.FE.IN" \
--methodus="SP.POP.TOTL.MA.IN" \
--objectivum-formato=hxltm \
>"999999/0/1603_992_1_0~worldbank~SP_POP_TOTL_FE_IN.tm.hxl.csv"
>"999999/0/1603_992_1_0~worldbank~SP_POP_TOTL_MA_IN.tm.hxl.csv"

./999999999/0/999999999_521850.py \
--methodus-fonti=worldbank \
Expand Down

0 comments on commit 8ea96f2

Please sign in to comment.