Skip to content

Commit

Permalink
rdf+bcp47+hxl (#41): improved abstract syntax tree AST for relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Jun 11, 2022
1 parent 5de67a8 commit 9c2922f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 35 deletions.
4 changes: 3 additions & 1 deletion officina/999999999/0/999999999_54872.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from L999999999_0 import (
BCP47_AD_HXL,
RDF_SPATIA_NOMINALIBUS_EXTRAS,
SetEncoder,
bcp47_langtag,
bcp47_rdf_extension_poc,
hxl_hashtag_to_bcp47,
Expand Down Expand Up @@ -389,7 +390,8 @@ def execute_cli(self, pyargs, stdin=STDIN, stdout=sys.stdout,
caput, data, objective_bag=pyargs.rdf_bag,
rdf_sine_spatia_nominalibus=pyargs.rdf_sine_spatia_nominalibus,
est_meta=True)
print(json.dumps(meta, sort_keys=False, ensure_ascii=False))
print(json.dumps(
meta, sort_keys=False, ensure_ascii=False, cls=SetEncoder))
return self.EXIT_OK

# @TODO remove thsi temporary part
Expand Down
95 changes: 61 additions & 34 deletions officina/999999999/0/L999999999_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,10 @@ def _aux_init_container(result: dict, subject: str) -> dict:
"""
result['rdfs:Container'][subject] = {
'trivium': {
# 'alia': (str(subject), str(subject)),
# 'alia': {str(subject)},
'alia': [str(subject)],
# 'alia': [str(subject)],
'index': -1,
# 'iri': inline_namespace_iri,
# 'rdf_praefixum': 'urn',
Expand All @@ -1563,12 +1567,12 @@ def _aux_init_container(result: dict, subject: str) -> dict:
'rdf:predicate': [],
# @TODO: implement the semantics of is_a
'rdf:type': [],
# aliīs, pl, m/f/n, dativus, en.wiktionary.org/wiki/alius#Latin
'trivium_aliis': []
# # aliīs, pl, m/f/n, dativus, en.wiktionary.org/wiki/alius#Latin
# 'trivium_aliis': []
},
'indices_columnis': [],
# aliīs, pl, n, ablativus, en.wiktionary.org/wiki/alius#Latin
'indices_columnis_cum_aliis': []
'indices_cum_aliis': []
}
return result

Expand All @@ -1581,14 +1585,9 @@ def _aux_recalc_containers(result: dict) -> dict:
and use these names to create more focused relations
"""
trivium_aliis = {}
# print(result.keys())

# First pass
for item_caput_asa in result['caput_originali_asa']:
# print('oi keys', item_caput_asa.keys())
# print('oi extension in', 'extension' in item_caput_asa.keys())
# print('oi extension in', 'extension' in item_caput_asa)
# # print('oi', 'extension' not in result.keys())
# # print('oi', 'extension' in result.keys(), 'extension' in result)
# # print('oi', result['extension'])
if 'extension' not in item_caput_asa or \
'r' not in item_caput_asa['extension']:
continue
Expand All @@ -1604,30 +1603,51 @@ def _aux_recalc_containers(result: dict) -> dict:
_temp1, _temp2 = item_subject.split('||')
aliud = _temp2.split(':').pop(0)
if index_ex_tabula not in trivium_aliis:
trivium_aliis[index_ex_tabula] = []
trivium_aliis[int(index_ex_tabula)].append(aliud)

pass
# _r = result[]
# result['rdfs:Container'][subject] = {
# 'trivium': {
# 'index': -1,
# # 'iri': inline_namespace_iri,
# # 'rdf_praefixum': 'urn',
# 'rdf_praefixum': 'urnmdciii',
# # We will fallback the pivots as generic classes
# # We should enable later override this behavior
# # via language tag on the pivot
# 'rdf:predicate': [],
# # @TODO: implement the semantics of is_a
# 'rdf:type': [],
# # aliīs, pl, m/f/n, dativus, en.wiktionary.org/wiki/alius#Latin
# 'trivium_aliis': []
# },
# 'indices_columnis': [],
# # alia, pl, n, accusativus, en.wiktionary.org/wiki/alius#Latin
# 'indices_columnis_per_alia': {}
# }
trivium_aliis[index_ex_tabula] = set()
trivium_aliis[int(index_ex_tabula)].add(aliud)

# Second pass
_trivium_aliis = []
for trivium_alii, _item in result['rdfs:Container'].items():
_trivium_aliis.append(trivium_alii)
_trivium_indici = _item['trivium']['index']
_cum_aliis = []

for _item in trivium_aliis[_trivium_indici]:
_cum_aliis.extend(
result['rdfs:Container'][_item]['indices_columnis'])

# trivium_aliis[_trivium_indici] = \
# set(list(trivium_aliis[_trivium_indici]).sort())
# trivium_aliis[_trivium_indici].sort()
trivium_aliis[_trivium_indici] = \
list(trivium_aliis[_trivium_indici])
trivium_aliis[_trivium_indici].sort(key=int)

result['rdfs:Container'][trivium_alii]['trivium']['alia'] = \
trivium_aliis[_trivium_indici]

_cum_aliis = list(set(_cum_aliis))
_cum_aliis.sort(key=int)

result['rdfs:Container'][trivium_alii]['indices_cum_aliis'] = \
_cum_aliis
# print(trivium_alii, _item)
# if 'extension' not in item_caput_asa or \
# 'r' not in item_caput_asa['extension']:
# continue

# Third pass; mostly to re-order rdfs:Container to generate same
# abstract syntax tree even if order of columns change
_trivium_aliis.sort(key=int)
rdfs_container_novo = {}
for trivium_alii in _trivium_aliis:
rdfs_container_novo[trivium_alii] = \
result['rdfs:Container'][trivium_alii]
# pass

result['rdfs:Container'] = rdfs_container_novo

result['trivium_aliis_per_indicem'] = trivium_aliis
return result

Expand Down Expand Up @@ -5043,6 +5063,13 @@ def rdf_namespaces_extras(archivum: str) -> dict:
return RDF_SPATIA_NOMINALIBUS_EXTRAS


class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return json.JSONEncoder.default(self, obj)


def numerordinatio_descendentibus(
numerordinatio: str, collectio: list, ordo_maximo: int = None) -> list:
"""numerordinatio_descendentibus _summary_
Expand Down

0 comments on commit 9c2922f

Please sign in to comment.