<commit_before>__author__ = 'moskupols'

import cherrypy
import explanator
import pickle

PICKLE_PROTOCOL = 3

class ExplanationServer:
    @cherrypy.expose
    @cherrypy.tools.json_out()
    def explain(self, word=None):
        if word is None:
            raise cherrypy.HTTPError(400)
        e = explanator.explain(word)
        if e is None:
            raise cherrypy.HTTPError(400)
        return {'explanation': {
            'id_protocol': 'pickle' + str(PICKLE_PROTOCOL) + '+int-little',
            'id': int.from_bytes(pickle.dumps(e, PICKLE_PROTOCOL), 'little'),
            'text': repr(e)
        }}

    @cherrypy.expose
    def explain_plain(self, word=None):
        if word is None:
            raise cherrypy.HTTPError(400)
        e = explanator.explain(word)
        if e is None:<commit_msg>Changed JSON explanation format to gather id and its protocol<commit_after>__author__ = 'moskupols'

import cherrypy
import explanator
import pickle

PICKLE_PROTOCOL = 3

class ExplanationServer:
    @cherrypy.expose
    @cherrypy.tools.json_out()
    def explain(self, word=None):
        if word is None:
            raise cherrypy.HTTPError(400)
        e = explanator.explain(word)
        if e is None:
            raise cherrypy.HTTPError(400)
        return {
            'explanation': {
                'id': {
                    'protocol': 'pickle' + str(PICKLE_PROTOCOL) + '+int-little',
                    'code': int.from_bytes(pickle.dumps(e, PICKLE_PROTOCOL), 'little'),
                },
                'text': repr(e)
            }
        }

    @cherrypy.expose
    def explain_plain(self, word=None):
        if word is None:
            raise cherrypy.HTTPError(400)
        e = explanator.explain(word)
        if e is None:
{'fraction_non_alphanumeric': 0.10305775764439411, 'fraction_numerical': 0.011325028312570781, 'mean_word_length': 2.1164021164021163, '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': '5420443', 'n_tokens_mistral': 592, 'n_tokens_neox': 568, 'n_words': 127}