diff --git a/officina/999999999/0/L999999999_0.py b/officina/999999999/0/L999999999_0.py index 5b8c6fb..17023e1 100644 --- a/officina/999999999/0/L999999999_0.py +++ b/officina/999999999/0/L999999999_0.py @@ -383,7 +383,9 @@ 'obo:ro1025': 'obo:RO_0001025', # purl.obolibrary.org/obo/RO_0001025 'obo:rolocatedin': 'obo:BFO_0000002', } -# @TODO https://protegeproject.github.io/owl2lpg/ +# Note: prefixes that already are lower case do not be here +RDF_NAMESPACES_PREFIX_EXTRAS = { +} def bcp47_langtag( @@ -995,7 +997,7 @@ def bcp47_rdf_extension( # 'csvw:separator': '', # Added only if necessary # 'prefix': [], # Added only if necessary } - _predicates = [] + # _predicates = [] _subjects = [] _objects = [] @@ -1102,8 +1104,17 @@ def bcp47_rdf_extension( # if len(_predicates) > 0: # _predicates.sort() # result['rdf:predicate'] = _predicates - if len(_predicates) > 1: + if len(result['rdf:predicate']) > 0: result['rdf:predicate'].sort() + # raise ValueError(result['rdf:predicate']) + # for index in range(len(result['rdf:predicate'])): + # predicate_prefix, predicate, subject = \ + # result['rdf:predicate'][index].split(':') + # raw_predicate = f'{predicate_prefix}:{predicate}' + # if raw_predicate in RDF_NAMESPACES_PREFIX: + # result['rdf:predicate'] = '{0}:{1}'.format( + # RDF_NAMESPACES_PREFIX[raw_predicate], subject) + # # pass if len(_objects) > 0: _objects.sort() @@ -2759,11 +2770,50 @@ def hxl_hashtag_to_bcp47(hashtag: str) -> str: )) elif item.startswith('p_'): - _predicate = item.replace('p_', '').replace('_', ':') - result['extension']['r']['rdf:predicate'].append(_predicate) - _predicate_key, _object, _subject = _predicate.split(':') + _item_parts = item.replace('p_', '').replace('_', ':') + result['extension']['r']['rdf:predicate'].append(_item_parts) + _index_p = result['extension']['r']['rdf:predicate'].index( + _item_parts + ) + _predicate_ns, _predicate_item, _subject = \ + _item_parts.split(':') + + raw_predicate = f'{_predicate_ns}:{_predicate_item}' + normalized_predicate = None + + if raw_predicate in RDF_NAMESPACES_PREFIX: + normalized_predicate = RDF_NAMESPACES_PREFIX[raw_predicate] + elif raw_predicate in RDF_NAMESPACES_PREFIX_EXTRAS: + normalized_predicate = \ + RDF_NAMESPACES_PREFIX_EXTRAS[raw_predicate] + + if normalized_predicate is not None: + if normalized_predicate.startswith('obo:'): + normalized_predicate = normalized_predicate.lower() + _predicate_ns = 'obo' + _predicate_item_raw = \ + normalized_predicate.replace('obo:', '') + _predicate_item_raw_digits = ''.join( + filter(str.isdigit, _predicate_item_raw)) + _predicate_item_raw_alpha = \ + _predicate_item_raw.replace(\ + _predicate_item_raw_digits, '').replace( + '_', '') + _predicate_item = '{0}{1}'.format( + _predicate_item_raw_alpha, + _predicate_item_raw_digits.lstrip('0') + ) + else: + _predicate_ns, _predicate_item = \ + normalized_predicate.split(':') + # pass + + result['extension']['r']['rdf:predicate'][_index_p] = \ + '{0}:{1}'.format( + RDF_NAMESPACES_PREFIX[raw_predicate], _subject) + _bpc47_g_parts.append('p{0}-p{1}-p{2}'.format( - _predicate_key.upper(), _object, _subject + _predicate_ns.upper(), _predicate_item, _subject )) elif item.startswith('y_'):