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

import re

from pyramid.renderers import JSON

from skosprovider.skos import (
    Concept,
    Collection,
    Label,
    Note
)

def parse_range_header(range):
    match = re.match('^items=([0-9]+)-([0-9]+)$', range)
    if match:
        start = int(match.group(1))
        finish = int(match.group(2))
        if finish < start:
            finish = start
        return {
            'start': start,
            'finish': finish,
            'number': finish - start + 1
        }
    else:
        return False

json_renderer = JSON()

def concept_adapter(obj, request):
    return {
        'id': obj.id,
        'type': 'concept',
        'label': obj.label().label,
        'labels': obj.labels,
        'notes': obj.notes,
        'narrower': obj.narrower,
        'broader': obj.broader,
        'related': obj.related
    }

def collection_adapter(obj, request):
    return {
        'id': obj.id,
        'type': 'collection',
        'label': obj.label().label,
        'labels': obj.labels,
        'members': obj.members
    }

def label_adapter(obj, request):
    return {
        'label': obj.label,
        'type': obj.type,
        'language': obj.language
    }

def note_adapter(obj, request):
    return {
        'note': obj.note,
        'type': obj.type,
        'language': obj.language
    }

json_renderer.add_adapter(Concept, concept_adapter)
json_renderer.add_adapter(Collection, collection_adapter)
json_renderer.add_adapter(Label, label_adapter)
json_renderer.add_adapter(Note, note_adapter)<commit_msg>Added some docstrings.<commit_after># -*- coding: utf8 -*-

import re

from pyramid.renderers import JSON

from skosprovider.skos import (
    Concept,
    Collection,
    Label,
    Note
)

def parse_range_header(range):
    '''
    Parse a range header as used by the dojo Json Rest store.
    '''
    match = re.match('^items=([0-9]+)-([0-9]+)$', range)
    if match:
        start = int(match.group(1))
        finish = int(match.group(2))
        if finish < start:
            finish = start
        return {
            'start': start,
            'finish': finish,
            'number': finish - start + 1
        }
    else:
        return False

json_renderer = JSON()

def concept_adapter(obj, request):
    '''
    Adapter for rendering a :class:`skosprovider.skos.Concept` to json.
    '''
    return {
        'id': obj.id,
        'type': 'concept',
        'label': obj.label().label,
        'labels': obj.labels,
        'notes': obj.notes,
        'narrower': obj.narrower,
        'broader': obj.broader,
        'related': obj.related
    }

def collection_adapter(obj, request):
    '''
    Adapter for rendering a :class:`skosprovider.skos.Collection` to json.
    '''
    return {
        'id': obj.id,
        'type': 'collection',
        'label': obj.label().label,
        'labels': obj.labels,
        'members': obj.members
    }

def label_adapter(obj, request):
    '''
    Adapter for rendering a :class:`skosprovider.skos.Label` to json.
    '''
    return {
        'label': obj.label,
        'type': obj.type,
        'language': obj.language
    }

def note_adapter(obj, request):
    '''
    Adapter for rendering a :class:`skosprovider.skos.Note` to json.
    '''
    return {
        'note': obj.note,
        'type': obj.type,
        'language': obj.language
    }

json_renderer.add_adapter(Concept, concept_adapter)
json_renderer.add_adapter(Collection, collection_adapter)
json_renderer.add_adapter(Label, label_adapter)
json_renderer.add_adapter(Note, note_adapter)
{'fraction_non_alphanumeric': 0.13827711179258434, 'fraction_numerical': 0.004460551993309172, 'mean_word_length': 2.282708142726441, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3803744', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1129, 'n_words': 257}