Skip to content

Commit

Permalink
#11: Ontologia.est_validum_ad_regula(); cor.hxltm.215.yml:ontologia_r…
Browse files Browse the repository at this point in the history
…egulam
  • Loading branch information
fititnt committed Nov 28, 2021
1 parent 28ab173 commit 991fdde
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hxltm-computo_testum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
# python-version: [3.7, 3.8, 3.9, 3.10]
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, 3.10]

# # Don't run https://github.com/nektos/act locally. Can be removed later.
# if: ${{ !env.ACT }}
Expand Down
87 changes: 79 additions & 8 deletions bin/hxltmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5026,10 +5026,9 @@ class HXLTMOntologia:
>>> ontologia.quid_est_hashtag_circa_linguam('#item+conceptum+codicem')
False
>>> ontologia.quid_est_hashtag_circa_linguam('#rem+rem+i_la+i_lat+is_latn')
>>> ontologia.est_validum_ad_regula('#item+conceptum+codicem')
True
#>>> ontologia.quod_rem_statum()
{'accuratum': None, 'crudum': [], 'crudum_originale': [], \
'XLIFF': 'initial', 'UTX': 'provisional'}
Expand Down Expand Up @@ -5061,6 +5060,16 @@ def __init__(self, ontologia: Dict, vacuum: bool = False):
else:
self.crudum = ontologia

def _ontologia_regulam_regex(self, clavem: str) -> str:
"""_ontologia_regulam_regex
"""
try:
return self.crudum['ontologia_regulam'][clavem]
# return self.crudum['ontologia_regulam'][clavem]['regex']
except:
raise ValueError(
'Non {0} ad ontologia_regulam.{0}.regex'.format(clavem))

def hxl_de_aliud_nomen_breve(self, structum=False):
"""HXL attribūtum de aliud nōmen breve (cor.hxltm.215.yml)
Expand Down Expand Up @@ -5157,6 +5166,36 @@ def de(self, dotted_key: str, # pylint: disable=invalid-name
key) if d else default, keys, fontem
)

def est_validum_ad_regula(
self,
hxlhashtag: str,
regulam_clavem: str = None
) -> bool:
"""est_validum_ad_regula est validum ad rēgulam? [ ontologia_regulam ]
_[eng-Latn]
Is this hashtag valid based on Ontologia regexes?
[eng-Latn]_
Trivia:
- rēgulam, https://en.wiktionary.org/wiki/regula#Latin
- validum, https://en.wiktionary.org/wiki/validus#Latin
Args:
hxlhashtag (str): HXL Hashtag
ontologia_regex (str, optional): ontologia_regulam clavem
Returns:
bool: Python True est validum
"""
if regulam_clavem is None:
regulam_clavem = 'abstractum_aut_concretum'

regula = self._ontologia_regulam_regex(regulam_clavem)
regula_regex = re.compile(regula['regex'])

return bool(regula_regex.match(hxlhashtag))

def quod_aliud(self, aliud_typum: str, aliud_valorem: str) -> Dict:
"""Quod Aliud?
Expand Down Expand Up @@ -5418,9 +5457,38 @@ def quod_rem_statum(self,
# TODO: implement this check
return resultatum

@staticmethod
# @staticmethod
# def quid_est_columnam_aut_lineam(
# hxl_hashtag: str) -> Union[str, None]:
# """Quid est columnam aut līneam?

# _[eng-Latn]
# Is this hashtag type maximixed columns or maximized rows?
# See https://en.wikipedia.org/wiki/Wide_and_narrow_data
# [eng-Latn]

# Args:
# hxl_hashtag (str): Hashtag ad textum

# Returns:
# str: 'columnam', 'lineam', None
# """
# # TODO: make this actually read the cor.hxltm.215.yml. This hardcoded
# # part is just a quick fix

# if HXLTMOntologia.quid_est_hashtag_circa_conceptum(hxl_hashtag):
# # Concept hashtags are neither cases
# return None

# if hxl_hashtag.find('+conceptum') > -1:
# return True

# return False

def quid_est_hashtag_circa_conceptum(
hxl_hashtag: str) -> Union[bool, None]:
self,
hxl_hashtag: str
) -> Union[bool, None]:
"""Quid est hashtag circa +conceptum?
_[eng-Latn]
Expand All @@ -5436,16 +5504,15 @@ def quid_est_hashtag_circa_conceptum(
# TODO: make this actually read the cor.hxltm.215.yml. This hardcoded
# part is just a quick fix

if HXLTMOntologia.quid_est_hashtag_circa_linguam(hxl_hashtag):
if self.quid_est_hashtag_circa_linguam(hxl_hashtag):
return False

if hxl_hashtag.find('+conceptum') > -1:
return True

return False

@staticmethod
def quid_est_hashtag_circa_linguam(hxl_hashtag: str) -> bool:
def quid_est_hashtag_circa_linguam(self, hxl_hashtag: str) -> bool:
"""Quid est hashtag circa linguam?
_[eng-Latn]
Expand All @@ -5462,9 +5529,13 @@ def quid_est_hashtag_circa_linguam(hxl_hashtag: str) -> bool:
# part is just a quick fix

if hxl_hashtag.startswith('#item+rem+i_'):
self._deprecatum.add('deprecatum [{0}]'.format(hxl_hashtag))
return True

if hxl_hashtag.startswith('#meta+rem+i_'):
self._deprecatum.add('deprecatum [{0}]'.format(hxl_hashtag))
return True

if re.match(r"\#.*(\+i_).*(\+is_).*", hxl_hashtag):
# # +i_ +is_
return True
Expand Down Expand Up @@ -7836,7 +7907,7 @@ def __enter__(self):
def __exit__(self, value, type, traceback):
pass

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


Expand Down
21 changes: 21 additions & 0 deletions ontologia/cor.hxltm.215.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,27 @@ ontologia_aliud_familiam:

# end::ontologia_aliud[]


# Trivia: rēgulam, https://en.wiktionary.org/wiki/regula#Latin
ontologia_regulam:
# @see https://regex101.com/ (online regex tester, multiple engines)
# @see https://docs.python.org/3/howto/regex.html
# @see https://developer.mozilla.org/en-US/docs/Web/JavaScript
# /Reference/Global_Objects/RegExp
# @see https://pkg.go.dev/regexp/syntax
# @see https://www.php.net/manual/en/reference.pcre.pattern.syntax.php

# abstractum, https://en.wiktionary.org/wiki/abstractus#Latin
abstractum:
regex: "^#item"

abstractum_aut_concretum:
regex: "^#item|^#meta"

# concrētum, https://en.wiktionary.org/wiki/concretus
concretum:
regex: "^#item"

## TBX Basic 3.1 (http://www.terminorgs.net/downloads/TBX_Basic_Version_3.1.pdf)
# 5 Mandatory data categories
# There are only two mandatory data categories in TBX-Basic: term, and language.
Expand Down
16 changes: 16 additions & 0 deletions testum/hxltmcli--help_eng-Latn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ usage: hxltmcli [-h] [--sheet [number]] [--selector [path]]
[--objectivum-CSV-3] [--objectivum-TSV-3]
[--objectivum-JSON-kv]
[--objectivum-formatum-speciale [objectivum_formatum_speciale]]
[--transformare-ad-maximum-columnam]
[--transformare-ad-maximum-lineam]
[--limitem-quantitatem [limitem_quantitatem]]
[--limitem-initiale-lineam [limitem_initiale_lineam]]
[--non-securum-limitem]
Expand Down Expand Up @@ -156,6 +158,20 @@ optional arguments:
Example: "hxltmcli fontem.hxl.csv objectivum.tmx
--objectivum-TMX --objectivum-formatum-speciale TMX-
de-marcus"
--transformare-ad-maximum-columnam
(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.
--transformare-ad-maximum-lineam
(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.
--limitem-quantitatem [limitem_quantitatem]
(Advanced, large data sets) Customize the limit of the
maximum number of raw rows can be in a single step.
Expand Down

0 comments on commit 991fdde

Please sign in to comment.