Skip to content

Commit

Permalink
#11: argument draft: --transformare-ad-maximum-columnam, --transforma…
Browse files Browse the repository at this point in the history
…re-ad-maximum-lineam
  • Loading branch information
fititnt committed Nov 28, 2021
1 parent 2b79de7 commit 28ab173
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 46 deletions.
93 changes: 84 additions & 9 deletions bin/hxltmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,39 @@ def make_args_hxltmcli(self):
nargs='?'
)

# Trivia: trānsfōrmāre, https://en.wiktionary.org/wiki/transformo#Latin
parser.add_argument(
'--transformare-ad-maximum-columnam',
help='(Early draft) '
'Transformation of type reshape entire dataset. '
'Convert HXLTM narrow '
'(more rows) to wide (more columns; each new language means '
'add more columns). '
'more columns; also called vertical database model or '
'open schema). '
'See https://en.wikipedia.org/wiki/Wide_and_narrow_data.',
metavar='transformare_ad_maximum_columnam',
action='store_const',
const=True,
default=False
)

parser.add_argument(
'--transformare-ad-maximum-lineam',
help='(Early draft) '
'Transformation of type reshape entire dataset. '
'Convert HXLTM wide '
'(more columns; each new language means add more columns) '
'to narrow (more rows; each new language does not require '
'more columns; also called vertical database model or '
'open schema). '
'See https://en.wikipedia.org/wiki/Wide_and_narrow_data.',
metavar='transformare_ad_maximum_lineam',
action='store_const',
const=True,
default=False
)

parser.add_argument(
'--limitem-quantitatem',
help='(Advanced, large data sets) '
Expand Down Expand Up @@ -1641,6 +1674,7 @@ class HXLTMArgumentum: # pylint: disable=too-many-instance-attributes
objectivum_formulam: InitVar[str] = None
objectivum_formatum_speciale: InitVar[str] = None
objectivum_archivum_nomen: InitVar[str] = None
transformare_ad_maximum: InitVar[str] = None # columnam, lineam, None
columnam_numerum: InitVar[List] = []
non_columnam_numerum: InitVar[List] = []
limitem_initiale_lineam: InitVar[int] = -1
Expand Down Expand Up @@ -1739,6 +1773,20 @@ def de_argparse(self, args_rem: Dict = None):
self.objectivum_formatum_speciale = \
args_rem.objectivum_formatum_speciale

if hasattr(args_rem, 'transformare_ad_maximum_columnam') and \
args_rem.transformare_ad_maximum_columnam:
self.transformare_ad_maximum = 'columnam'

if hasattr(args_rem, 'transformare_ad_maximum_lineam') and \
args_rem.transformare_ad_maximum_lineam:

if self.transformare_ad_maximum:
raise ValueError(
'--transformare-ad-maximum-columnam + '
'--transformare-ad-maximum-lineam'
)
self.transformare_ad_maximum = 'lineam'

if hasattr(args_rem, 'columnam_numerum'):
self.columnam_numerum = args_rem.columnam_numerum
if hasattr(args_rem, 'non_columnam_numerum'):
Expand Down Expand Up @@ -2310,7 +2358,8 @@ def asa(self, hxltm_asa: Type['HXLTMASA'] = None) -> Type['HXLTMASA']:
if not self.__commune_asa:
raise ReferenceError('hxltm_asa not initialized yet')
return self.__commune_asa
elif self.__commune_asa is not None:

if self.__commune_asa is not None:
raise ReferenceError('hxltm_asa already initialized')

self.__commune_asa = hxltm_asa
Expand Down Expand Up @@ -2867,7 +2916,7 @@ def __init__(
datum_rem_brevis: List = None,
columnam_collectionem: List[Type['HXLTMDatumColumnam']] = None,
argumentum: Type['HXLTMArgumentum'] = None
):
): # pylint: disable=too-many-arguments
"""Datum Caput
Args:
Expand Down Expand Up @@ -3061,6 +3110,7 @@ def linguam_de_columnam(self, _numerum: int) -> Type['HXLTMLinguam']:
Returns:
Union[str, None]: linguam aut python None
"""
# pylint: disable=no-self-use
# https://en.wiktionary.org/wiki/columna#Latin
print('TODO')

Expand Down Expand Up @@ -3517,6 +3567,7 @@ def quod_clavem_et_valorem(self) -> Dict:
Returns:
[Dict]: [description]
"""
# pylint: disable=too-many-locals,too-many-branches,too-many-statements

# NOTE: the agendum-linguam should already be filtered steps before
# this method would try to check it.
Expand Down Expand Up @@ -3673,9 +3724,10 @@ def quod_clavem_et_valorem(self) -> Dict:
return self._quod_clavem_et_valorem_ii(
resultatum, supplementum_valorem)

def _quod_clavem_et_valorem_ii(self,
clavem_et_valorem: Dict,
statum_rem_accuratuam: Dict):
def _quod_clavem_et_valorem_ii(
self,
clavem_et_valorem: Dict,
statum_rem_accuratuam: Dict):
"""[summary]
Args:
Expand All @@ -3686,6 +3738,8 @@ def _quod_clavem_et_valorem_ii(self,
Returns:
[type]: [description]
"""
# pylint: disable=no-self-use

# clavem_de_linguam = ['de_linguam', 'de_fontem_linguam',
# 'de_objectivum_linguam', 'de_auxilium_linguam']
clavem_de_linguam = ['de_linguam', 'de_auxilium_linguam']
Expand Down Expand Up @@ -3776,6 +3830,9 @@ def quod_rem_de_linguam(self, linguam: Type['HXLTMLinguam']) -> Dict:
return None

def quod_statum(self, _option) -> Dict:
"""quod_statum
"""
# pylint: disable=no-self-use
# @deprecated use HXLTMOntologia.quod_aliud_de_multiplum()
resultatum = {
# 1-10, TBX uses it
Expand Down Expand Up @@ -3838,6 +3895,11 @@ def quod_tabulam_valorem_ad_conceptum(self) -> Dict:
return resultatum

def quod_nomen(self) -> str:
"""quod_nomen
Returns:
str: Nomen
"""
conceptum_index = [0] # TODO: make it not hardcoded
conceptum_nomen = ''

Expand Down Expand Up @@ -5022,6 +5084,9 @@ def hxl_de_aliud_nomen_breve(self, structum=False):
# pylint: disable=invalid-name

def recursionem(rem):
"""recursionem
"""
# pylint: disable=no-self-use
# Trivia:
# - recursiōnem, https://en.wiktionary.org/wiki/recursio#Latin
for _k, v in rem.items():
Expand Down Expand Up @@ -5055,6 +5120,7 @@ def hxlhashtag(self, objectivum: Union[Dict, None], strictum=False):
Returns:
[str]: an HXL hashtag without spaces
"""
# pylint: disable=no-self-use
if objectivum is not None:
if '__HXL' in objectivum:
return ''.join(objectivum['__HXL'].split())
Expand Down Expand Up @@ -5326,6 +5392,8 @@ def quod_rem_statum(self,
Returns:
Dict: [description]
"""
# pylint: disable=no-self-use

# TODO: make the defaults configurable

resultatum = {
Expand Down Expand Up @@ -5458,6 +5526,7 @@ def quod_nomen_breve_de_hxl(self, hxl_hashtag: str) -> str:
def quod_nomen_breve_de_id(self, _hxl_hashtag: str) -> str:
"""TODO quod_nomen_breve_de_id
"""
# pylint: disable=no-self-use
return ''

# def in_rem(self, focused_datum: List) -> Type['HXLTMRem']:
Expand Down Expand Up @@ -5537,9 +5606,9 @@ def iso6392a3(textum: str) -> str:
Returns:
str: ISO 639-3 language code
"""
L = langcodes.Language.get(textum)
if L.is_valid():
return L.to_alpha3()
Lang = langcodes.Language.get(textum)
if Lang.is_valid():
return Lang.to_alpha3()
# resultatum = L.to_alpha3()
return None

Expand Down Expand Up @@ -7435,6 +7504,7 @@ class HXLUtils:
def __init__(self):

self.logger = logging.getLogger(__name__)
# pylint: disable=invalid-name

# Posix exit codes
self.EXIT_OK = 0
Expand All @@ -7452,6 +7522,7 @@ def make_args(self, description, epilog=None, hxl_output=True):
@param hxl_output: if True (default), include options for HXL output.
@returns: an argument parser, partly set up.
"""
# pylint: disable=no-self-use
if epilog is None:
parser = argparse.ArgumentParser(description=description)
else:
Expand Down Expand Up @@ -7527,6 +7598,7 @@ def add_queries_arg(
parser,
help='Apply only to rows matching at least one query.'
):
# pylint: disable=no-self-use
parser.add_argument(
'-q',
'--query',
Expand All @@ -7538,6 +7610,7 @@ def add_queries_arg(

def do_common_args(self, args):
"""Process standard args"""
# pylint: disable=no-self-use
logging.basicConfig(
format='%(levelname)s (%(name)s): %(message)s',
level=args.log.upper())
Expand Down Expand Up @@ -7576,12 +7649,14 @@ def make_input(self, args, stdin=sys.stdin, url_or_filename=None):

def make_output(self, args, stdout=sys.stdout):
"""Create an output stream."""
# pylint: disable=no-self-use
if args.outfile:
return FileOutput(args.outfile)
else:
return StreamOutput(stdout)

def make_headers(self, args):
# pylint: disable=no-self-use
# get custom headers
header_strings = []
header = os.environ.get("HXL_HTTP_HEADER")
Expand Down Expand Up @@ -7761,7 +7836,7 @@ def __enter__(self):
def __exit__(self, value, type, traceback):
pass

def write(self, s):
def write(self, s): # pylint: disable=invalid-name
self.output.write(s)


Expand Down
Loading

0 comments on commit 28ab173

Please sign in to comment.