<commit_before># -*- coding: utf8 -*-

from zope.interface import Interface

from skosprovider.registry import Registry


class ISkosRegistry(Interface):
    pass


def _build_skos_registry(registry):
    skos_registry = registry.queryUtility(ISkosRegistry)
    if skos_registry is not None:
        return skos_registry

    skos_registry = Registry()

    registry.registerUtility(skos_registry, ISkosRegistry)
    return registry.queryUtility(ISkosRegistry)


def get_skos_registry(registry):
    #Argument might be a config or request
    regis = getattr(registry, 'registry', None)
    if regis is None:
        regis = registry
    return regis.queryUtility(ISkosRegistry)


def includeme(config):
    _build_skos_registry(config.registry)
    config.add_directive('get_skos_registry', get_skos_registry)
    config.add_route('skosprovider.conceptschemes', '/conceptschemes')
    config.add_route('skosprovider.conceptscheme', '/conceptschemes/{scheme_id}')
    config.add_route('skosprovider.conceptscheme.concepts', '/conceptschemes/{scheme_id}/concepts')
    config.add_route('skosprovider.concept', '/conceptschemes/{scheme_id}/concepts/{concept_id}')

    config.scan()<commit_msg>Add skos_registry to the request.<commit_after># -*- coding: utf8 -*-

from zope.interface import Interface

from skosprovider.registry import Registry


class ISkosRegistry(Interface):
    pass


def _build_skos_registry(registry):
    skos_registry = registry.queryUtility(ISkosRegistry)
    if skos_registry is not None:
        return skos_registry

    skos_registry = Registry()

    registry.registerUtility(skos_registry, ISkosRegistry)
    return registry.queryUtility(ISkosRegistry)


def get_skos_registry(registry):
    #Argument might be a config or request
    regis = getattr(registry, 'registry', None)
    if regis is None:
        regis = registry
    return regis.queryUtility(ISkosRegistry)


def includeme(config):
    _build_skos_registry(config.registry)
    config.add_directive('get_skos_registry', get_skos_registry)
    config.add_request_method(get_skos_registry, 'skos_registry', reify=True)
    config.add_route('skosprovider.conceptschemes', '/conceptschemes')
    config.add_route('skosprovider.conceptscheme', '/conceptschemes/{scheme_id}')
    config.add_route('skosprovider.conceptscheme.concepts', '/conceptschemes/{scheme_id}/concepts')
    config.add_route('skosprovider.concept', '/conceptschemes/{scheme_id}/concepts/{concept_id}')

    config.scan()
{'fraction_non_alphanumeric': 0.10032232070910556, 'fraction_numerical': 0.0008058017727639, 'mean_word_length': 4.997584541062802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3723999', 'n_tokens_mistral': 794, 'n_tokens_neox': 757, 'n_words': 138}