コード例 #1
0
def manage_uri_synonyms(collection: SolrCollection) -> None:
    logging.info('> managing uri_synonyms resources')

    uri_synonyms = {'uri_nl': {}, 'uri_en': {}}
    legacy_license_files = ['ckan_license.json', 'overheid_license.json']

    for valuelist in os.listdir(os.getenv('VALUELIST_DIR')):
        if not valuelist.endswith('.json'):
            continue

        if valuelist in legacy_license_files:
            continue

        filepath = os.path.join(os.getenv('VALUELIST_DIR'), valuelist)

        for uri, properties in utils.load_json_file(filepath).items():
            uri_synonyms['uri_nl'][uri] = properties['labels']['nl-NL']
            uri_synonyms['uri_en'][uri] = properties['labels']['en-US']

    for lang in uri_synonyms.keys():
        logging.info('managed resource: synonyms|%s', lang)

        current_uri_synonyms = collection.select_managed_synonyms(lang)

        if not current_uri_synonyms:
            current_uri_synonyms = {}

        logging.info(' current: %s synonyms', len(current_uri_synonyms))

        synonyms_to_add = {
            key: value
            for key, value in uri_synonyms[lang].items()
            if key not in current_uri_synonyms.keys()
        }

        logging.info(' adding: %s synonyms', len(synonyms_to_add))

        if len(synonyms_to_add) > 0:
            collection.add_managed_synonyms(lang, synonyms_to_add)
コード例 #2
0
def manage_label_synonyms(collection: SolrCollection,
                          language_code: str) -> None:
    logging.info('> managing label resource')

    current_label_synonyms = collection.select_managed_synonyms(
        'label_{0}'.format(language_code))

    logging.info(' current: %s synonyms', len(current_label_synonyms))

    label_synonyms = utils.load_resource('labels_{0}'.format(language_code))

    synonyms_to_add = {
        key: value
        for key, value in label_synonyms.items()
        if key not in current_label_synonyms.keys()
    }

    logging.info(' adding: %s synonyms', len(synonyms_to_add))

    if len(synonyms_to_add) > 0:
        collection.add_managed_synonyms('label_{0}'.format(language_code),
                                        synonyms_to_add)
コード例 #3
0
def manage_hierarchy_theme(collection: SolrCollection) -> None:
    logging.info('> managing hierarchy_theme resources')

    for hierarchy_item in ['hierarchy_theme', 'hierarchy_theme_query']:
        logging.info('managed resource: synonyms|{0}'.format(hierarchy_item))

        hierarchy_data = utils.load_resource(hierarchy_item)
        current_data = collection.select_managed_synonyms(hierarchy_item)

        if not current_data:
            current_data = {}

        logging.info(' current: %s synonyms', len(current_data))

        data_to_add = {
            key: value
            for key, value in hierarchy_data.items()
            if key not in current_data.keys()
        }

        logging.info(' adding: %s synonyms', len(data_to_add))

        if len(data_to_add) > 0:
            collection.add_managed_synonyms(hierarchy_item, data_to_add)