diff --git a/officina/999999999/0/L999999999_0.py b/officina/999999999/0/L999999999_0.py index 97e7c8b..114c5ed 100644 --- a/officina/999999999/0/L999999999_0.py +++ b/officina/999999999/0/L999999999_0.py @@ -883,7 +883,11 @@ def bcp47_langtag_callback_hxl( if _r['rdf:subject'] and len(_r['rdf:subject']) > 0: for item in _r['rdf:subject']: - subject_key, subject_namespace, _nop = item.lower().split(':') + # subject_key, subject_namespace, _nop = item.lower().split(':') + _temp1, temp2 = item.lower().split('||') + subject_key = _temp1 + subject_namespace = temp2 + subject_namespace = subject_namespace.replace(':nop', '') resultatum.append( '+rdf_s_{0}_s{1}'.format(subject_key, subject_namespace)) @@ -893,11 +897,15 @@ def bcp47_langtag_callback_hxl( prefix, term = _temp1.split(':') resultatum.append('+rdf_t_{0}_{1}'.format(prefix, term)) - if len(_r["xsl:transform"]) > 0: + if _r["xsl:transform"] and len(_r["xsl:transform"]) > 0: value_prefixes = None value_separator = None for titem in _r["xsl:transform"]: - tverb, tval_1, _nop_tval_2 = titem.split(':') + # tverb, tval_1, _nop_tval_2 = titem.split(':') + + _temp1, temp2 = titem.split('||') + tverb = _temp1 + tval_1, _nop_tval_2 = temp2.split(':') if tverb.lower() == EXTRA_OPERATORS['STX']['hxl']: if value_prefixes is None: @@ -1094,7 +1102,7 @@ def bcp47_rdf_extension( r_verb.lower(), r_op_1, r_op_2, 'NOP' )) elif r_op == 's': - _subjects.append('{0}:{1}:{2}'.format( + _subjects.append('{0}||{1}:{2}'.format( r_verb.upper(), r_op_1.lower(), r_op_2 )) elif r_op == 'o': @@ -1119,7 +1127,7 @@ def bcp47_rdf_extension( r_op_1 )) elif r_op == 'y': - result['xsl:transform'].append('{0}:{1}:{2}'.format( + result['xsl:transform'].append('{0}||{1}:{2}'.format( r_verb.upper(), r_op_1.lower(), r_op_2, )) else: @@ -1214,6 +1222,7 @@ def bcp47_rdf_extension( if len(result['xsl:transform']) > 0: result['xsl:transform'].sort() + # result['rdf:subject'] = _subjects else: @@ -1394,17 +1403,21 @@ def bcp47_rdf_extension_relationship( # RDFStatement: Subject -> [[ Predicate ]] -> Object if 'r' in item_meta['extension'] and \ len(item_meta['extension']['r']['rdf:predicate']) > 0: - for predicate in item_meta['extension']['r']['rdf:predicate']: - prefix, suffix = predicate.split(':') - if prefix not in result['prefixes']: + for item in item_meta['extension']['r']['rdf:predicate']: + # raise ValueError(predicate) + # prefix, suffix = predicate.split(':') + predicate, subject = item.split('||') + predicate_namespce, _ignore = predicate.split(':') + subject = subject.replace(':NOP', '') # Not used... yet + if predicate_namespce not in result['prefixes']: # if prefix not in RDF_NAMESPACES: - if prefix not in RDF_NAMESPACES_EXTRAS: + if predicate_namespce not in RDF_NAMESPACES_EXTRAS: raise SyntaxError( 'prefix [{0}]? <{1}> <{2}>'.format( - prefix, header, RDF_NAMESPACES_EXTRAS + predicate_namespce, header, RDF_NAMESPACES_EXTRAS )) - result['prefixes'][prefix] = \ - RDF_NAMESPACES_EXTRAS[prefix] + result['prefixes'][predicate_namespce] = \ + RDF_NAMESPACES_EXTRAS[predicate_namespce] result['columns'].append(item_meta) # raise ValueError(result['rdfs:Container']) @@ -1485,8 +1498,11 @@ def bcp47_rdf_extension_poc( # print(meta['rdfs:Container']) if objective_bag not in meta['rdfs:Container']: - raise SyntaxError('objective_bag({0})? {1} <{2}>'.format( - objective_bag, header, meta)) + possible_bags = meta['rdfs:Container'].keys() + raise SyntaxError( + 'objective_bag({0})? possible <{1}>: ' + 'header <{2}> Meta <{3}>'.format( + objective_bag, possible_bags, header, meta)) # print(meta) # print('') @@ -1529,7 +1545,11 @@ def _helper_aux( value_prefixes = None if len(bag_meta["xsl:transform"]) > 0: for titem in bag_meta["xsl:transform"]: - tverb, tval_1, _nop_tval_2 = titem.split(':') + + # tverb, tval_1, _nop_tval_2 = titem.split(':') + _temp1, temp2 = titem.split('||') + tverb = _temp1 + tval_1, _nop_tval_2 = temp2.split(':') if tverb == EXTRA_OPERATORS['STX']['hxl']: if value_prefixes is None: @@ -2849,9 +2869,10 @@ def hxl_hashtag_to_bcp47(hashtag: str) -> str: _subjec_value = _subjec_value.replace('s', '') _subjec_value = _subjec_value.replace('s', '') - result['extension']['r']['rdf:subject'].append('{0}:{1}'.format( - _subject_code, _subjec_value - )) + result['extension']['r']['rdf:subject'].append( + '{0}||{1}:NOP'.format( + _subject_code, _subjec_value + )) _bpc47_g_parts.append('s{0}-s{1}-snop'.format( _subject_code, _subjec_value @@ -2905,6 +2926,11 @@ def hxl_hashtag_to_bcp47(hashtag: str) -> str: '{0}||{1}:{2}'.format( RDF_NAMESPACES_PREFIX[raw_predicate], _subject, _subject_nop) + else: + result['extension']['r']['rdf:predicate'][_index_p] = \ + '{0}||{1}:{2}'.format( + raw_predicate, + _subject, _subject_nop) _bpc47_g_parts.append('p{0}-p{1}-ps{2}'.format( _predicate_ns.upper(), _predicate_item, _subject, @@ -2933,22 +2959,27 @@ def hxl_hashtag_to_bcp47(hashtag: str) -> str: tval_1, hashtag, CSVW_SEPARATORS )) - # result['extension']['r']['csvw:separator'] = \ - # decoded_separator - # _predicate_key, _object = _predicate.split(':') + result['extension']['r']['xsl:transform'].append( + '{0}||{1}:NOP'.format(tverb.upper(), tval_1.lower())) + _bpc47_g_parts.append('y{0}-y{1}-ynop'.format( EXTRA_OPERATORS['GS']['hxl'].upper(), decoded_separator )) elif tverb == EXTRA_OPERATORS['STX']['hxl']: - # if value_prefixes is None: - # value_prefixes = [] - # value_prefixes.append(tval_1) + result['extension']['r']['xsl:transform'].append( + '{0}||{1}:NOP'.format(tverb.upper(), tval_1.lower())) + _bpc47_g_parts.append('y{0}-y{1}-ynop'.format( tverb.upper(), tval_1.lower() )) else: result['_unknown'].append('rdf_parts [{0}]'.format(item)) + # result['extension']['r']['xsl:transform'].append(_item_parts) + # _index_p = result['extension']['r']['rdf:predicate'].index( + # _item_parts + # ) + elif item.startswith('t_'): # _cell_transformer = item.replace('y_', '').lower() _cell_transformer = item[2:] diff --git a/officina/999999999/1568346/bcp47-to-hxl-to-rdf.sh b/officina/999999999/1568346/bcp47-to-hxl-to-rdf.sh index 401407e..f71d378 100755 --- a/officina/999999999/1568346/bcp47-to-hxl-to-rdf.sh +++ b/officina/999999999/1568346/bcp47-to-hxl-to-rdf.sh @@ -94,6 +94,7 @@ test_unesco_thesaurus() { archivum__resultata_ttl="${ROOTDIR}/999999/0/unesco-thesaurus.rdf.ttl" archivum__resultata_xml="${ROOTDIR}/999999/0/unesco-thesaurus.rdf.xml" + set -x "${ROOTDIR}/999999999/0/999999999_54872.py" \ --objectivum-formato=_temp_bcp47 \ --rdf-bag=1 \ @@ -121,6 +122,7 @@ test_unesco_thesaurus() { >"${archivum__resultata_ttl}" riot --validate "${archivum__resultata_ttl}" + set -x } ####################################### @@ -171,7 +173,7 @@ bcp47_and_hxlrdf_roundtrip() { echo "${stype_green}OK [$bpc47_final]${style_normal}" # printf "$STARTCOLOR%b$ENDCOLOR" "$1"; else - echo "${style_red}FAILED [$bpc47_final]${style_normal}" + echo "${style_red}FAILED [$bpc47_final] != [$bpc47_discovered_2nd] ${style_normal}" fi else echo "${stype_blue}INFO: No enforced expected result${style_normal}" @@ -201,7 +203,7 @@ bcp47_and_hxlrdf_roundtrip() { if [ "$hxlattr_final" = "$hxlattr_discovered_2nd" ]; then echo "${stype_green}OK [$hxlattr_final]${style_normal}" else - echo "${style_red}FAILED [$hxlattr_final]${style_normal}" + echo "${style_red}FAILED [$hxlattr_final] != [$hxlattr_discovered_2nd] ${style_normal}" fi else echo "${stype_blue}INFO: No enforced expected result${style_normal}" diff --git a/officina/999999999/1568346/data/unesco-thesaurus.bcp47g.tsv b/officina/999999999/1568346/data/unesco-thesaurus.bcp47g.tsv index 6338f78..3671049 100644 --- a/officina/999999999/1568346/data/unesco-thesaurus.bcp47g.tsv +++ b/officina/999999999/1568346/data/unesco-thesaurus.bcp47g.tsv @@ -1,4 +1,4 @@ -qcc-Zxxx-r-sU2200-s1-snop qcc-Zxxx-r-sU2203-s2-snop-yU001D-yu007c-ynop-yU0002-yunescothes-ynop qcc-Zxxx-r-pSKOS-pbroader-ps2-sU0001D53B-s2-snop-yU001D-yu007c-ynop-yU0002-yunescothes-ynop qcc-Zxxx-r-pSKOS-narrower-sS-s2-yCSVWseparator-u007c-yPREFIX-unescothes qcc-Zxxx-r-pSKOS-related-sS-s2-yCSVWseparator-u007c-yPREFIX-unescothes rus-Cyrl-r-pSKOS-prefLabel-sS-s1 arb-Arab-r-pSKOS-prefLabel-sS-s1 spa-Latn-r-pSKOS-prefLabel-sS-s1 qcc-Zxxx-r-pDCT-modified-txsd-datetime-sS-s1 +qcc-Zxxx-r-sU2200-s1-snop qcc-Zxxx-r-sU2203-s2-snop-yU001D-yu007c-ynop-yU0002-yunescothes-ynop qcc-Zxxx-r-pSKOS-pbroader-ps2-sU0001D53B-s2-snop-yU001D-yu007c-ynop-yU0002-yunescothes-ynop qcc-Zxxx-r-pSKOS-pnarrower-ps2-yU001D-yu007c-ynop-yU0002-yunescothes-ynop qcc-Zxxx-r-pSKOS-prelated-ps2-yU001D-yu007c-ynop-yU0002-yunescothes-ynop rus-Cyrl-r-pSKOS-pprefLabel-ps1 arb-Arab-r-pSKOS-pprefLabel-ps1 spa-Latn-r-pSKOS-pprefLabel-ps1 qcc-Zxxx-r-pDCT-pmodified-pnop-txsd-tdatetime-tnop 1603:999:9 concept9 concept10 Политика в области образования سياسة تربوية Política educacional 2019-12-15T22:36:40Z 1603:999:10 concept10 concept4938|concept7597 concept9 Право на образование حق في التعليم Derecho a la educación 2019-12-15T13:26:49Z 1603:999:4938 concept4938 concept10 concept10 Возможности получения образования فرص تربوية Oportunidades educacionales 2019-12-15T22:36:42Z