<commit_before># coding: utf8
from __future__ import unicode_literals

from .render import DependencyRenderer, EntityRenderer
from ..tokens import Doc
from ..util import prints


_html = {}


def render(docs, style='dep', page=False, minify=False, jupyter=False, options={}):
    """Render displaCy visualisation.

    docs (list or Doc): Document(s) to visualise.
    style (unicode): Visualisation style, 'dep' or 'ent'.
    page (bool): Render markup as full HTML page.
    minify (bool): Minify HTML markup.
    jupyter (bool): Experimental, use Jupyter's display() to output markup.
    options (dict): Visualiser-specific options, e.g. colors.
    RETURNS (unicode): Rendered HTML markup.
    """
    if isinstance(docs, Doc):
        docs = [docs]
    if style is 'dep':
        renderer = DependencyRenderer(options=options)
        parsed = [parse_deps(doc, options) for doc in docs]
    elif style is 'ent':
        renderer = EntityRenderer(options=options)
        parsed = [parse_ents(doc, options) for doc in docs]
    _html['parsed'] = renderer.render(parsed, page=page, minify=minify).strip()
    html = _html['parsed']
    if jupyter: # return HTML rendered by IPython display()
        from IPython.core.display import display, HTML
        return display(HTML(html))
    return html


def serve(docs, style='dep', page=True, minify=False, options={}, port=5000):
    """Serve displaCy visualisation.

    docs (list or Doc): Document(s) to visualise.
    style (unicode): Visualisation style, 'dep' or 'ent'.
    page (bool): Render markup as full HTML page.
    minify (bool): Minify HTML markup.
    options (dict): Visualiser-specific options, e.g. colors.
    port (int): Port to serve visualisation.
    """
    from wsgiref import simple_server
    render(docs, style=style, page=page, minify=minify, options=options)
    httpd = simple_server.make_server('0.0.0.0', port, app)
    prints("Using the '%s' visualizer" % style, title="Serving on port %d..." % port)
    httpd.serve_forever()


def app(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/html; charset=utf-8')])
    res = _html['parsed'].encode(encoding='utf-8')
    return [res]<commit_msg>Fix style check in displacy<commit_after># coding: utf8
from __future__ import unicode_literals

from .render import DependencyRenderer, EntityRenderer
from ..tokens import Doc
from ..util import prints


_html = {}


def render(docs, style='dep', page=False, minify=False, jupyter=False, options={}):
    """Render displaCy visualisation.

    docs (list or Doc): Document(s) to visualise.
    style (unicode): Visualisation style, 'dep' or 'ent'.
    page (bool): Render markup as full HTML page.
    minify (bool): Minify HTML markup.
    jupyter (bool): Experimental, use Jupyter's display() to output markup.
    options (dict): Visualiser-specific options, e.g. colors.
    RETURNS (unicode): Rendered HTML markup.
    """
    if isinstance(docs, Doc):
        docs = [docs]
    if style == 'dep':
        renderer = DependencyRenderer(options=options)
        parsed = [parse_deps(doc, options) for doc in docs]
    elif style == 'ent':
        renderer = EntityRenderer(options=options)
        parsed = [parse_ents(doc, options) for doc in docs]
    else:
        raise ValueError("Unknown style: %s" % style)
    _html['parsed'] = renderer.render(parsed, page=page, minify=minify).strip()
    html = _html['parsed']
    if jupyter: # return HTML rendered by IPython display()
        from IPython.core.display import display, HTML
        return display(HTML(html))
    return html


def serve(docs, style='dep', page=True, minify=False, options={}, port=5000):
    """Serve displaCy visualisation.

    docs (list or Doc): Document(s) to visualise.
    style (unicode): Visualisation style, 'dep' or 'ent'.
    page (bool): Render markup as full HTML page.
    minify (bool): Minify HTML markup.
    options (dict): Visualiser-specific options, e.g. colors.
    port (int): Port to serve visualisation.
    """
    from wsgiref import simple_server
    render(docs, style=style, page=page, minify=minify, options=options)
    httpd = simple_server.make_server('0.0.0.0', port, app)
    prints("Using the '%s' visualizer" % style, title="Serving on port %d..." % port)
    httpd.serve_forever()


def app(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/html; charset=utf-8')])
    res = _html['parsed'].encode(encoding='utf-8')
    return [res]
{'fraction_non_alphanumeric': 0.12822796081923418, 'fraction_numerical': 0.006233303650934996, 'mean_word_length': 3.6607883817427385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4901621', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1383, 'n_words': 441}