Skip to content

Commit

Permalink
999999999_54872.py (#42): planned: application/x-turtle, application/…
Browse files Browse the repository at this point in the history
…n-triples
  • Loading branch information
fititnt committed May 17, 2022
1 parent 6b8b6fe commit d0760f9
Showing 1 changed file with 62 additions and 39 deletions.
101 changes: 62 additions & 39 deletions officinam/999999999/0/999999999_54872.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
NOMEN = '999999999_54872'

DESCRIPTION = """
{0} Processamento de dados de referência do IBGE (Brasil).
{0} Conversor de HXLTM para formatos RDF (alternativa ao uso de 1603_1_1.py, \
que envolve processamento muito mais intenso para datasets enormes)
@see https://github.com/EticaAI/lexicographi-sine-finibus/issues/42
Expand Down Expand Up @@ -69,6 +70,9 @@
cat 999999/0/ibge_un_adm2.json | {0} --objectivum-formato=hxltm_csv \
> 999999/0/ibge_un_adm2.tm.hxl.csv
cat 999999/0/ibge_un_adm2.tm.hxl.csv | {0} --objectivum-formato=hxltm_csv \
> 999999/0/ibge_un_adm2.tm.hxl.csv
------------------------------------------------------------------------------
EXEMPLŌRUM GRATIĀ
------------------------------------------------------------------------------
Expand Down Expand Up @@ -131,33 +135,6 @@ def __init__(self):
Constructs all the necessary attributes for the Cli object.
"""

def _quod_configuratio(self, archivum_configurationi: str = None) -> dict:
"""_quod_configuratio
Args:
archivum_configurationi (str, optional):
Returns:
(dict):
"""
archivae = ARCHIVUM_CONFIGURATIONI_DEFALLO
if archivum_configurationi is not None:
if not exists(archivum_configurationi):
raise FileNotFoundError(
'archivum_configurationi {0}'.format(
archivum_configurationi))
archivae.append(archivum_configurationi)

for item in archivae:
if exists(item):
with open(item, "r") as read_file:
datum = yaml.safe_load(read_file)
return datum

raise FileNotFoundError(
'archivum_configurationi {0}'.format(
str(archivae)))

def make_args(self, hxl_output=True):
# parser = argparse.ArgumentParser(description=DESCRIPTION)
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -194,24 +171,31 @@ def make_args(self, hxl_output=True):
# objectīvum, n, s, nominativus,
# https://en.wiktionary.org/wiki/objectivus#Latin
# fōrmātō, n, s, dativus, https://en.wiktionary.org/wiki/formatus#Latin
# @see about formats and discussion
# - https://github.com/semantalytics/awesome-semantic-web#serialization
# - https://ontola.io/blog/rdf-serialization-formats/
# - doc.wikimedia.org/Wikibase/master/php/md_docs_topics_json.html
parser.add_argument(
'--objectivum-formato',
help='Formato do arquivo exportado',
dest='objectivum_formato',
nargs='?',
choices=[
'uri_fonti',
'json_fonti',
'json_fonti_formoso',
'csv',
'tsv',
'hxl_csv',
'hxl_tsv',
'hxltm_csv',
'hxltm_tsv',
# https://www.w3.org/TR/turtle/
'application/x-turtle',
# https://www.w3.org/TR/n-triples/
'application/n-triples',
# # http://ndjson.org/
# # https://github.com/ontola/hextuples
# # mimetype???
# # - https://stackoverflow.com/questions/51690624
# # /json-lines-mime-type
# # - https://github.com/wardi/jsonlines/issues/9
# # - https://bugzilla.mozilla.org/show_bug.cgi?id=1603986
# 'application/x-ndjson',
],
# required=True
default='csv'
default='application/x-turtle'
)

# archīvum, n, s, nominativus, https://en.wiktionary.org/wiki/archivum
Expand All @@ -224,6 +208,18 @@ def make_args(self, hxl_output=True):
nargs='?',
default=None
)
# archīvum, n, s, nominativus, https://en.wiktionary.org/wiki/archivum
# cōnfigūrātiōnī, f, s, dativus,
# https://en.wiktionary.org/wiki/configuratio#Latin
# ex
# fontī, m, s, dativus, https://en.wiktionary.org/wiki/fons#Latin
parser.add_argument(
'--archivum-configurationi-ex-fonti',
help='Arquivo de configuração .meta.yml da fonte de dados',
dest='archivum_configurationi',
nargs='?',
default=None
)

# parser.add_argument(
# 'outfile',
Expand All @@ -239,7 +235,7 @@ def execute_cli(self, pyargs, stdin=STDIN, stdout=sys.stdout,

_infile = None
_stdin = None
configuratio = self._quod_configuratio(pyargs.archivum_configurationi)
configuratio = self.quod_configuratio(pyargs.archivum_configurationi)

if stdin.isatty():
_infile = pyargs.infile
Expand Down Expand Up @@ -299,6 +295,33 @@ def execute_cli(self, pyargs, stdin=STDIN, stdout=sys.stdout,
print('Unknow option.')
return self.EXIT_ERROR

def quod_configuratio(self, archivum_configurationi: str = None) -> dict:
"""quod_configuratio
Args:
archivum_configurationi (str, optional):
Returns:
(dict):
"""
archivae = ARCHIVUM_CONFIGURATIONI_DEFALLO
if archivum_configurationi is not None:
if not exists(archivum_configurationi):
raise FileNotFoundError(
'archivum_configurationi {0}'.format(
archivum_configurationi))
archivae.append(archivum_configurationi)

for item in archivae:
if exists(item):
with open(item, "r") as read_file:
datum = yaml.safe_load(read_file)
return datum

raise FileNotFoundError(
'archivum_configurationi {0}'.format(
str(archivae)))


class CliMain:
"""Remove .0 at the end of CSVs from data exported from XLSX and likely
Expand Down

0 comments on commit d0760f9

Please sign in to comment.