<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
Created by 'bens3' on 2013-06-21.
Copyright (c) 2013 'bens3'. All rights reserved.
"""

from rdflib import URIRef, BNode, Literal
from ckanext.dcat.processors import RDFSerializer as DCATSerializer
from ckanext.dcat.utils import catalog_uri, dataset_uri, url_to_rdflib_format
from ckanext.nhm.dcat.utils import object_uri

class RDFSerializer(DCATSerializer):

    def serialize_record(self, record_dict, resource_dict, _format='xml'):
        '''
        Given a CKAN dataset dict, returns an RDF serialization

        The serialization format can be defined using the `_format` parameter.
        It must be one of the ones supported by RDFLib, defaults to `xml`.

        Returns a string with the serialized dataset
        '''

        self.graph_from_record(record_dict, resource_dict)

        _format = url_to_rdflib_format(_format)

        if _format == 'json-ld':
            output = self.g.serialize(format=_format, auto_compact=True)
        else:
            output = self.g.serialize(format=_format)

        return output

    def graph_from_record(self, record_dict=None, resource=None):
        '''
        Creates a graph for the catalog (CKAN site) using the loaded profiles

        The class RDFLib graph (accessible via `serializer.g`) will be updated
        by the loaded profiles.

        Returns the reference to the catalog, which will be an rdflib URIRef.
        '''

        record_ref = URIRef(object_uri(record_dict))

        for profile_class in self._profiles:
            profile = profile_class(self.g, self.compatibility_mode)
            profile.graph_from_record(record_dict, resource, record_ref)

        return record_ref

<commit_msg>Handle non nhm profile<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
Created by 'bens3' on 2013-06-21.
Copyright (c) 2013 'bens3'. All rights reserved.
"""

from rdflib import URIRef, BNode, Literal
from ckanext.dcat.processors import RDFSerializer as DCATSerializer
from ckanext.dcat.utils import catalog_uri, dataset_uri, url_to_rdflib_format
from ckanext.nhm.dcat.utils import object_uri

class RDFSerializer(DCATSerializer):

    def serialize_record(self, record_dict, resource_dict, _format='xml'):
        '''
        Given a CKAN dataset dict, returns an RDF serialization

        The serialization format can be defined using the `_format` parameter.
        It must be one of the ones supported by RDFLib, defaults to `xml`.

        Returns a string with the serialized dataset
        '''

        self.graph_from_record(record_dict, resource_dict)

        _format = url_to_rdflib_format(_format)

        if _format == 'json-ld':
            output = self.g.serialize(format=_format, auto_compact=True)
        else:
            output = self.g.serialize(format=_format)

        return output

    def graph_from_record(self, record_dict=None, resource=None):
        '''
        Creates a graph for the catalog (CKAN site) using the loaded profiles

        The class RDFLib graph (accessible via `serializer.g`) will be updated
        by the loaded profiles.

        Returns the reference to the catalog, which will be an rdflib URIRef.
        '''

        record_ref = URIRef(object_uri(record_dict))

        for profile_class in self._profiles:
            profile = profile_class(self.g, self.compatibility_mode)
            try:
                profile.graph_from_record(record_dict, resource, record_ref)
            except AttributeError:
                continue

        return record_ref
{'fraction_non_alphanumeric': 0.07563025210084033, 'fraction_numerical': 0.008403361344537815, 'mean_word_length': 2.9155701754385963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '945712', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1015, 'n_words': 317}