💫 Tidy up and auto-format .py files (#2983)
<!--- Provide a general summary of your changes in the title. -->
## Description
- [x] Use [`black`](https://github.com/ambv/black) to auto-format all `.py` files.
- [x] Update flake8 config to exclude very large files (lemmatization tables etc.)
- [x] Update code to be compatible with flake8 rules
- [x] Fix various small bugs, inconsistencies and messy stuff in the language data
- [x] Update docs to explain new code style (`black`, `flake8`, when to use `# fmt: off` and `# fmt: on` and what `# noqa` means)
Once #2932 is merged, which auto-formats and tidies up the CLI, we'll be able to run `flake8 spacy` actually get meaningful results.
At the moment, the code style and linting isn't applied automatically, but I'm hoping that the new [GitHub Actions](https://github.com/features/actions) will let us auto-format pull requests and post comments with relevant linting information.
### Types of change
enhancement, code style
## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2018-11-30 16:03:03 +00:00
|
|
|
# Setting explicit height and max-width: none on the SVG is required for
|
2017-05-14 16:39:01 +00:00
|
|
|
# Jupyter to render it properly in a cell
|
|
|
|
|
2017-05-14 15:50:23 +00:00
|
|
|
TPL_DEP_SVG = """
|
2019-03-11 17:52:50 +00:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="{lang}" id="{id}" class="displacy" width="{width}" height="{height}" direction="{dir}" style="max-width: none; height: {height}px; color: {color}; background: {bg}; font-family: {font}; direction: {dir}">{content}</svg>
|
2017-05-14 15:50:23 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
TPL_DEP_WORDS = """
|
|
|
|
<text class="displacy-token" fill="currentColor" text-anchor="middle" y="{y}">
|
|
|
|
<tspan class="displacy-word" fill="currentColor" x="{x}">{text}</tspan>
|
|
|
|
<tspan class="displacy-tag" dy="2em" fill="currentColor" x="{x}">{tag}</tspan>
|
|
|
|
</text>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2020-02-22 13:11:51 +00:00
|
|
|
TPL_DEP_WORDS_LEMMA = """
|
|
|
|
<text class="displacy-token" fill="currentColor" text-anchor="middle" y="{y}">
|
|
|
|
<tspan class="displacy-word" fill="currentColor" x="{x}">{text}</tspan>
|
|
|
|
<tspan class="displacy-lemma" dy="2em" fill="currentColor" x="{x}">{lemma}</tspan>
|
|
|
|
<tspan class="displacy-tag" dy="2em" fill="currentColor" x="{x}">{tag}</tspan>
|
|
|
|
</text>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2017-05-14 15:50:23 +00:00
|
|
|
TPL_DEP_ARCS = """
|
|
|
|
<g class="displacy-arrow">
|
|
|
|
<path class="displacy-arc" id="arrow-{id}-{i}" stroke-width="{stroke}px" d="{arc}" fill="none" stroke="currentColor"/>
|
2017-06-03 11:25:41 +00:00
|
|
|
<text dy="1.25em" style="font-size: 0.8em; letter-spacing: 1px">
|
2019-03-11 17:52:50 +00:00
|
|
|
<textPath xlink:href="#arrow-{id}-{i}" class="displacy-label" startOffset="50%" side="{label_side}" fill="currentColor" text-anchor="middle">{label}</textPath>
|
2017-05-14 15:50:23 +00:00
|
|
|
</text>
|
|
|
|
<path class="displacy-arrowhead" d="{head}" fill="currentColor"/>
|
|
|
|
</g>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
TPL_FIGURE = """
|
|
|
|
<figure style="margin-bottom: 6rem">{content}</figure>
|
|
|
|
"""
|
|
|
|
|
|
|
|
TPL_TITLE = """
|
|
|
|
<h2 style="margin: 0">{title}</h2>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
TPL_ENTS = """
|
2019-03-11 17:52:50 +00:00
|
|
|
<div class="entities" style="line-height: 2.5; direction: {dir}">{content}</div>
|
2017-05-14 15:50:23 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
TPL_ENT = """
|
2019-10-31 14:09:43 +00:00
|
|
|
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;">
|
2017-05-14 15:50:23 +00:00
|
|
|
{text}
|
|
|
|
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; text-transform: uppercase; vertical-align: middle; margin-left: 0.5rem">{label}</span>
|
|
|
|
</mark>
|
|
|
|
"""
|
|
|
|
|
2019-03-11 17:52:50 +00:00
|
|
|
TPL_ENT_RTL = """
|
2019-10-31 14:10:25 +00:00
|
|
|
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em">
|
2019-03-11 17:52:50 +00:00
|
|
|
{text}
|
|
|
|
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; text-transform: uppercase; vertical-align: middle; margin-right: 0.5rem">{label}</span>
|
|
|
|
</mark>
|
|
|
|
"""
|
|
|
|
|
2017-05-14 15:50:23 +00:00
|
|
|
|
|
|
|
TPL_PAGE = """
|
|
|
|
<!DOCTYPE html>
|
2019-03-11 17:52:50 +00:00
|
|
|
<html lang="{lang}">
|
2017-05-14 15:50:23 +00:00
|
|
|
<head>
|
|
|
|
<title>displaCy</title>
|
|
|
|
</head>
|
|
|
|
|
2019-03-11 17:52:50 +00:00
|
|
|
<body style="font-size: 16px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; padding: 4rem 2rem; direction: {dir}">{content}</body>
|
2017-05-14 15:50:23 +00:00
|
|
|
</html>
|
|
|
|
"""
|