slopometer 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- slopometer-0.0.1/LICENSE +201 -0
- slopometer-0.0.1/MANIFEST.in +5 -0
- slopometer-0.0.1/PKG-INFO +63 -0
- slopometer-0.0.1/README.md +43 -0
- slopometer-0.0.1/pyproject.toml +36 -0
- slopometer-0.0.1/setup.cfg +4 -0
- slopometer-0.0.1/slopometer/__init__.py +14 -0
- slopometer-0.0.1/slopometer/_modidx.py +64 -0
- slopometer-0.0.1/slopometer/cli.py +31 -0
- slopometer-0.0.1/slopometer/core.py +80 -0
- slopometer-0.0.1/slopometer/features.py +83 -0
- slopometer-0.0.1/slopometer/lexicon.py +93 -0
- slopometer-0.0.1/slopometer/para.py +115 -0
- slopometer-0.0.1/slopometer/score.py +93 -0
- slopometer-0.0.1/slopometer/segment.py +60 -0
- slopometer-0.0.1/slopometer/syntax.py +192 -0
- slopometer-0.0.1/slopometer.egg-info/PKG-INFO +63 -0
- slopometer-0.0.1/slopometer.egg-info/SOURCES.txt +20 -0
- slopometer-0.0.1/slopometer.egg-info/dependency_links.txt +1 -0
- slopometer-0.0.1/slopometer.egg-info/entry_points.txt +5 -0
- slopometer-0.0.1/slopometer.egg-info/requires.txt +4 -0
- slopometer-0.0.1/slopometer.egg-info/top_level.txt +1 -0
slopometer-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2022, fastai
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: slopometer
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Score prose for simplicity and precision against plain-English reference rules
|
|
5
|
+
Author-email: Jeremy Howard <github@jhoward.fastmail.fm>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/AnswerDotAI/slopometer
|
|
8
|
+
Project-URL: Documentation, https://AnswerDotAI.github.io/slopometer/
|
|
9
|
+
Keywords: nbdev
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: fastcore
|
|
16
|
+
Requires-Dist: spacy
|
|
17
|
+
Requires-Dist: mdhtml
|
|
18
|
+
Requires-Dist: warmpy>=0.1.0
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# slopometer
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
25
|
+
|
|
26
|
+
`slopometer` measures prose against the aai reference-prose rules defined in `aai_coding.write_docs`. The rules merge GOV.UK/GDS house style with the discipline of ASD-STE100. It covers 26 numbered tells, banned-word lists, and the reference register itself. The meter is for anyone shipping READMEs, docstrings, PR text, or agent responses. It catches slop mechanically, in milliseconds, with no LLM in the loop. Every finding cites a rule, quotes a span, and carries a weight. A document reduces to two numbers: density, the weighted findings per 100 prose words, and the single worst finding.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
pip install slopometer
|
|
31
|
+
|
|
32
|
+
The first score on a machine downloads spaCy’s `en_core_web_md` model (about 40MB, once) into `~/.cache/slopometer` and loads it by path. The model never enters a virtual environment. One copy serves every project. Environment syncs cannot remove it.
|
|
33
|
+
|
|
34
|
+
## Use
|
|
35
|
+
|
|
36
|
+
``` python
|
|
37
|
+
from slopometer.score import score_text, score_path
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
``` python
|
|
41
|
+
score_text("This section describes our approach. It isn't just a linter - it's a comprehensive paradigm for quality.")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
density 252.9 (weight 43 on 17 prose words), worst 10
|
|
45
|
+
1: [10] notxbuty (tell 16, not-X-but-Y): "isn't just a"
|
|
46
|
+
1: [10] splice (tell 1, splices): ' - '
|
|
47
|
+
1: [10] banned: 'comprehensive' -> 'complete'
|
|
48
|
+
1: [10] banned: 'paradigm'
|
|
49
|
+
1: [3] throat_clearing (tell 13, throat-clearing): 'This section describes'
|
|
50
|
+
|
|
51
|
+
[`score_path`](https://AnswerDotAI.github.io/slopometer/score.html#score_path) does the same for a file, and its rows carry `lineno|hash|` addresses in the exhash format, ready for hash-verified editors. The command line wraps both:
|
|
52
|
+
|
|
53
|
+
slopometer README.md
|
|
54
|
+
git log -1 --format=%B | slopometer
|
|
55
|
+
slopometer draft.md --threshold 10
|
|
56
|
+
|
|
57
|
+
The threshold turns the density into an exit code for CI. The command runs warm through `warmpy`. The first call loads the model in a background process. Later calls answer in milliseconds. After thirty idle minutes the process exits.
|
|
58
|
+
|
|
59
|
+
## What it checks, and what it cannot
|
|
60
|
+
|
|
61
|
+
The rules live in notebooks that teach each family beside its code. Each rule states its tell, shows a violating example, and shows the plain rewrite. The [lexicon notebook](https://AnswerDotAI.github.io/slopometer/lexicon.html) holds the word and phrase rules. The [syntax notebook](https://AnswerDotAI.github.io/slopometer/syntax.html) builds sentence rules on spaCy’s parse. The [para notebook](https://AnswerDotAI.github.io/slopometer/para.html) builds its rules on word vectors. The [score notebook](https://AnswerDotAI.github.io/slopometer/score.html) assembles the pipeline. A drift test asserts that every `write_docs` tell maps to a rule or to an explicit unscoreable registry. The meter and the style guide cannot drift apart silently.
|
|
62
|
+
|
|
63
|
+
A rule ships only when its false-positive rate on clean reference prose is near zero. The meter scores the style guide’s own clean passage at exactly 0.0. The score notebook measures the blind spot instead of hiding it: mechanically chopped prose passes every surface rule while staying opaque. Agent review (`check_docs`) and an optional, explicitly invoked [Pangram](https://www.pangram.com) check cover that residue. Vale, write-good, and proselint solve neighboring problems. The [lexicon notebook](https://AnswerDotAI.github.io/slopometer/lexicon.html) records what came from them. It also credits the [GOV.UK words-to-avoid list](https://www.gov.uk/guidance/style-guide/a-to-z-of-gov-uk-style#words-to-avoid) (OGL v3).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# slopometer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
5
|
+
|
|
6
|
+
`slopometer` measures prose against the aai reference-prose rules defined in `aai_coding.write_docs`. The rules merge GOV.UK/GDS house style with the discipline of ASD-STE100. It covers 26 numbered tells, banned-word lists, and the reference register itself. The meter is for anyone shipping READMEs, docstrings, PR text, or agent responses. It catches slop mechanically, in milliseconds, with no LLM in the loop. Every finding cites a rule, quotes a span, and carries a weight. A document reduces to two numbers: density, the weighted findings per 100 prose words, and the single worst finding.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
pip install slopometer
|
|
11
|
+
|
|
12
|
+
The first score on a machine downloads spaCy’s `en_core_web_md` model (about 40MB, once) into `~/.cache/slopometer` and loads it by path. The model never enters a virtual environment. One copy serves every project. Environment syncs cannot remove it.
|
|
13
|
+
|
|
14
|
+
## Use
|
|
15
|
+
|
|
16
|
+
``` python
|
|
17
|
+
from slopometer.score import score_text, score_path
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
``` python
|
|
21
|
+
score_text("This section describes our approach. It isn't just a linter - it's a comprehensive paradigm for quality.")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
density 252.9 (weight 43 on 17 prose words), worst 10
|
|
25
|
+
1: [10] notxbuty (tell 16, not-X-but-Y): "isn't just a"
|
|
26
|
+
1: [10] splice (tell 1, splices): ' - '
|
|
27
|
+
1: [10] banned: 'comprehensive' -> 'complete'
|
|
28
|
+
1: [10] banned: 'paradigm'
|
|
29
|
+
1: [3] throat_clearing (tell 13, throat-clearing): 'This section describes'
|
|
30
|
+
|
|
31
|
+
[`score_path`](https://AnswerDotAI.github.io/slopometer/score.html#score_path) does the same for a file, and its rows carry `lineno|hash|` addresses in the exhash format, ready for hash-verified editors. The command line wraps both:
|
|
32
|
+
|
|
33
|
+
slopometer README.md
|
|
34
|
+
git log -1 --format=%B | slopometer
|
|
35
|
+
slopometer draft.md --threshold 10
|
|
36
|
+
|
|
37
|
+
The threshold turns the density into an exit code for CI. The command runs warm through `warmpy`. The first call loads the model in a background process. Later calls answer in milliseconds. After thirty idle minutes the process exits.
|
|
38
|
+
|
|
39
|
+
## What it checks, and what it cannot
|
|
40
|
+
|
|
41
|
+
The rules live in notebooks that teach each family beside its code. Each rule states its tell, shows a violating example, and shows the plain rewrite. The [lexicon notebook](https://AnswerDotAI.github.io/slopometer/lexicon.html) holds the word and phrase rules. The [syntax notebook](https://AnswerDotAI.github.io/slopometer/syntax.html) builds sentence rules on spaCy’s parse. The [para notebook](https://AnswerDotAI.github.io/slopometer/para.html) builds its rules on word vectors. The [score notebook](https://AnswerDotAI.github.io/slopometer/score.html) assembles the pipeline. A drift test asserts that every `write_docs` tell maps to a rule or to an explicit unscoreable registry. The meter and the style guide cannot drift apart silently.
|
|
42
|
+
|
|
43
|
+
A rule ships only when its false-positive rate on clean reference prose is near zero. The meter scores the style guide’s own clean passage at exactly 0.0. The score notebook measures the blind spot instead of hiding it: mechanically chopped prose passes every surface rule while staying opaque. Agent review (`check_docs`) and an optional, explicitly invoked [Pangram](https://www.pangram.com) check cover that residue. Vale, write-good, and proselint solve neighboring problems. The [lexicon notebook](https://AnswerDotAI.github.io/slopometer/lexicon.html) records what came from them. It also credits the [GOV.UK words-to-avoid list](https://www.gov.uk/guidance/style-guide/a-to-z-of-gov-uk-style#words-to-avoid) (OGL v3).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "slopometer"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Score prose for simplicity and precision against plain-English reference rules"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "Apache-2.0"}
|
|
12
|
+
authors = [{name = "Jeremy Howard", email = "github@jhoward.fastmail.fm"}]
|
|
13
|
+
keywords = ['nbdev']
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
17
|
+
]
|
|
18
|
+
dependencies = ["fastcore", "spacy", "mdhtml", "warmpy>=0.1.0"]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Repository = "https://github.com/AnswerDotAI/slopometer"
|
|
22
|
+
Documentation = "https://AnswerDotAI.github.io/slopometer/"
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
slopometer = "slopometer.cli:main"
|
|
26
|
+
|
|
27
|
+
[project.entry-points.nbdev]
|
|
28
|
+
slopometer = "slopometer._modidx:d"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.dynamic]
|
|
31
|
+
version = {attr = "slopometer.__version__"}
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
include = ["slopometer"]
|
|
35
|
+
|
|
36
|
+
[tool.nbdev]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Score prose for simplicity and precision against plain-English reference rules
|
|
2
|
+
|
|
3
|
+
Modules:
|
|
4
|
+
|
|
5
|
+
- `slopometer.cli`: The command line: score a file or stdin, warm
|
|
6
|
+
- `slopometer.core`: Tells, findings, the rule registry, and what the meter cannot see
|
|
7
|
+
- `slopometer.features`: Continuous measurements for learned scoring
|
|
8
|
+
- `slopometer.lexicon`: Word and phrase rules: banned vocabulary, hedges, fillers, and splices
|
|
9
|
+
- `slopometer.para`: Paragraph rules: restatement, elegant variation, forced symmetry, and coinage
|
|
10
|
+
- `slopometer.score`: Run every rule, weigh the findings, and report worst first
|
|
11
|
+
- `slopometer.segment`: Markdown becomes typed blocks that keep their file positions
|
|
12
|
+
- `slopometer.syntax`: The spaCy rules: sentences, clauses, passives, and the patterns anchored to them"""
|
|
13
|
+
|
|
14
|
+
__version__ = "0.0.1"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Autogenerated by nbdev
|
|
2
|
+
|
|
3
|
+
d = { 'settings': { 'branch': 'main',
|
|
4
|
+
'doc_baseurl': '/slopometer',
|
|
5
|
+
'doc_host': 'https://AnswerDotAI.github.io',
|
|
6
|
+
'git_url': 'https://github.com/AnswerDotAI/slopometer',
|
|
7
|
+
'lib_path': 'slopometer'},
|
|
8
|
+
'syms': { 'slopometer.cli': {'slopometer.cli.main': ('cli.html#main', 'slopometer/cli.py')},
|
|
9
|
+
'slopometer.core': { 'slopometer.core.Finding': ('core.html#finding', 'slopometer/core.py'),
|
|
10
|
+
'slopometer.core.Finding.__init__': ('core.html#finding.__init__', 'slopometer/core.py'),
|
|
11
|
+
'slopometer.core.Finding.__repr__': ('core.html#finding.__repr__', 'slopometer/core.py'),
|
|
12
|
+
'slopometer.core.find_decoration': ('core.html#find_decoration', 'slopometer/core.py'),
|
|
13
|
+
'slopometer.core.rule': ('core.html#rule', 'slopometer/core.py')},
|
|
14
|
+
'slopometer.features': { 'slopometer.features.burstiness': ('features.html#burstiness', 'slopometer/features.py'),
|
|
15
|
+
'slopometer.features.features': ('features.html#features', 'slopometer/features.py'),
|
|
16
|
+
'slopometer.features.flattest_window': ('features.html#flattest_window', 'slopometer/features.py')},
|
|
17
|
+
'slopometer.lexicon': { 'slopometer.lexicon.find_conseq': ('lexicon.html#find_conseq', 'slopometer/lexicon.py'),
|
|
18
|
+
'slopometer.lexicon.find_emphasis': ('lexicon.html#find_emphasis', 'slopometer/lexicon.py'),
|
|
19
|
+
'slopometer.lexicon.find_splice': ('lexicon.html#find_splice', 'slopometer/lexicon.py'),
|
|
20
|
+
'slopometer.lexicon.lex_rule': ('lexicon.html#lex_rule', 'slopometer/lexicon.py')},
|
|
21
|
+
'slopometer.para': { 'slopometer.para._content': ('para.html#_content', 'slopometer/para.py'),
|
|
22
|
+
'slopometer.para.find_bullet_mold': ('para.html#find_bullet_mold', 'slopometer/para.py'),
|
|
23
|
+
'slopometer.para.find_coinage': ('para.html#find_coinage', 'slopometer/para.py'),
|
|
24
|
+
'slopometer.para.find_heading_echo': ('para.html#find_heading_echo', 'slopometer/para.py'),
|
|
25
|
+
'slopometer.para.find_para_cap': ('para.html#find_para_cap', 'slopometer/para.py'),
|
|
26
|
+
'slopometer.para.find_triad': ('para.html#find_triad', 'slopometer/para.py'),
|
|
27
|
+
'slopometer.para.find_variation': ('para.html#find_variation', 'slopometer/para.py'),
|
|
28
|
+
'slopometer.para.parse_blocks': ('para.html#parse_blocks', 'slopometer/para.py')},
|
|
29
|
+
'slopometer.score': { 'slopometer.score.Result': ('score.html#result', 'slopometer/score.py'),
|
|
30
|
+
'slopometer.score.Result.__init__': ('score.html#result.__init__', 'slopometer/score.py'),
|
|
31
|
+
'slopometer.score.Result.__repr__': ('score.html#result.__repr__', 'slopometer/score.py'),
|
|
32
|
+
'slopometer.score.Result._addr': ('score.html#result._addr', 'slopometer/score.py'),
|
|
33
|
+
'slopometer.score.Result.density': ('score.html#result.density', 'slopometer/score.py'),
|
|
34
|
+
'slopometer.score.Result.total': ('score.html#result.total', 'slopometer/score.py'),
|
|
35
|
+
'slopometer.score.Result.worst': ('score.html#result.worst', 'slopometer/score.py'),
|
|
36
|
+
'slopometer.score._rebase': ('score.html#_rebase', 'slopometer/score.py'),
|
|
37
|
+
'slopometer.score.find_overstructure': ('score.html#find_overstructure', 'slopometer/score.py'),
|
|
38
|
+
'slopometer.score.run_rules': ('score.html#run_rules', 'slopometer/score.py'),
|
|
39
|
+
'slopometer.score.score_many': ('score.html#score_many', 'slopometer/score.py'),
|
|
40
|
+
'slopometer.score.score_path': ('score.html#score_path', 'slopometer/score.py'),
|
|
41
|
+
'slopometer.score.score_text': ('score.html#score_text', 'slopometer/score.py')},
|
|
42
|
+
'slopometer.segment': { 'slopometer.segment.Block': ('segment.html#block', 'slopometer/segment.py'),
|
|
43
|
+
'slopometer.segment.Block.__init__': ('segment.html#block.__init__', 'slopometer/segment.py'),
|
|
44
|
+
'slopometer.segment.Block.__repr__': ('segment.html#block.__repr__', 'slopometer/segment.py'),
|
|
45
|
+
'slopometer.segment.n_headings': ('segment.html#n_headings', 'slopometer/segment.py'),
|
|
46
|
+
'slopometer.segment.prose_words': ('segment.html#prose_words', 'slopometer/segment.py'),
|
|
47
|
+
'slopometer.segment.scrub': ('segment.html#scrub', 'slopometer/segment.py'),
|
|
48
|
+
'slopometer.segment.segment': ('segment.html#segment', 'slopometer/segment.py')},
|
|
49
|
+
'slopometer.syntax': { 'slopometer.syntax._own_subj': ('syntax.html#_own_subj', 'slopometer/syntax.py'),
|
|
50
|
+
'slopometer.syntax._tok_find': ('syntax.html#_tok_find', 'slopometer/syntax.py'),
|
|
51
|
+
'slopometer.syntax.find_artifact_agent': ('syntax.html#find_artifact_agent', 'slopometer/syntax.py'),
|
|
52
|
+
'slopometer.syntax.find_clauses': ('syntax.html#find_clauses', 'slopometer/syntax.py'),
|
|
53
|
+
'slopometer.syntax.find_intensifiers': ('syntax.html#find_intensifiers', 'slopometer/syntax.py'),
|
|
54
|
+
'slopometer.syntax.find_nominalization': ('syntax.html#find_nominalization', 'slopometer/syntax.py'),
|
|
55
|
+
'slopometer.syntax.find_noun_cluster': ('syntax.html#find_noun_cluster', 'slopometer/syntax.py'),
|
|
56
|
+
'slopometer.syntax.find_passive': ('syntax.html#find_passive', 'slopometer/syntax.py'),
|
|
57
|
+
'slopometer.syntax.find_recipient_subject': ( 'syntax.html#find_recipient_subject',
|
|
58
|
+
'slopometer/syntax.py'),
|
|
59
|
+
'slopometer.syntax.find_rhetorical': ('syntax.html#find_rhetorical', 'slopometer/syntax.py'),
|
|
60
|
+
'slopometer.syntax.find_sent_len': ('syntax.html#find_sent_len', 'slopometer/syntax.py'),
|
|
61
|
+
'slopometer.syntax.find_verb_banned': ('syntax.html#find_verb_banned', 'slopometer/syntax.py'),
|
|
62
|
+
'slopometer.syntax.get_nlp': ('syntax.html#get_nlp', 'slopometer/syntax.py'),
|
|
63
|
+
'slopometer.syntax.model_path': ('syntax.html#model_path', 'slopometer/syntax.py'),
|
|
64
|
+
'slopometer.syntax.sent_rule': ('syntax.html#sent_rule', 'slopometer/syntax.py')}}}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""The command line: score a file or stdin, warm
|
|
2
|
+
|
|
3
|
+
`slopometer <file>` prints the worst-first report, `slopometer` alone reads stdin, and `--threshold` turns the density into an exit code for CI and hooks. Loading the model takes about a second and scoring takes milliseconds, so the command runs through [warmpy](https://github.com/AnswerDotAI/warmpy): the first call starts a background process that loads the model, later calls reuse it, and it exits after thirty idle minutes. The Claude Code stop hook runs this same command with the response text on stdin.
|
|
4
|
+
|
|
5
|
+
Docs: https://AnswerDotAI.github.io/slopometer/cli.html.md"""
|
|
6
|
+
|
|
7
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/06_cli.ipynb.
|
|
8
|
+
|
|
9
|
+
# %% auto #0
|
|
10
|
+
__all__ = ['main']
|
|
11
|
+
|
|
12
|
+
# %% ../nbs/06_cli.ipynb #01e3be12
|
|
13
|
+
import sys
|
|
14
|
+
from warmpy import warm_parse
|
|
15
|
+
|
|
16
|
+
# %% ../nbs/06_cli.ipynb #d21704e3
|
|
17
|
+
@warm_parse
|
|
18
|
+
def main(
|
|
19
|
+
path:str=None, # File to score; stdin when omitted
|
|
20
|
+
threshold:float=None, # Exit code 1 when density exceeds this
|
|
21
|
+
json:bool=False, # Emit the result as JSON instead of the report
|
|
22
|
+
):
|
|
23
|
+
"Score markdown against the aai reference-prose rules"
|
|
24
|
+
from json import dumps
|
|
25
|
+
from slopometer.score import score_path, score_text
|
|
26
|
+
res = score_path(path) if path else score_text(sys.stdin.read())
|
|
27
|
+
if json: print(dumps(dict(density=res.density, worst=res.worst, words=res.words,
|
|
28
|
+
findings=[{k: getattr(f, k) for k in ('rule', 'tell', 'start', 'end', 'text', 'weight', 'suggestion')} for f in res.findings])))
|
|
29
|
+
else: print(res)
|
|
30
|
+
if threshold is not None and res.density > threshold: return 1
|
|
31
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Tells, findings, the rule registry, and what the meter cannot see
|
|
2
|
+
|
|
3
|
+
slopometer measures prose against the reference-prose rules in `aai_coding.write_docs`: 26 numbered tells, the named ways reference prose goes wrong. This module defines what every rule shares: the table of tells, the `Finding` record every detector returns, the registry that rules join at import time, and the registry of tells no deterministic rule can detect.
|
|
4
|
+
|
|
5
|
+
Docs: https://AnswerDotAI.github.io/slopometer/core.html.md"""
|
|
6
|
+
|
|
7
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
|
|
8
|
+
|
|
9
|
+
# %% auto #0
|
|
10
|
+
__all__ = ['tells', 'KILL', 'SMELL', 'PRESSURE', 'rules', 'unscoreable', 'Finding', 'rule', 'find_decoration']
|
|
11
|
+
|
|
12
|
+
# %% ../nbs/00_core.ipynb #fa403df1
|
|
13
|
+
from fastcore.utils import *
|
|
14
|
+
|
|
15
|
+
# %% ../nbs/00_core.ipynb #5fecc627
|
|
16
|
+
tells = {
|
|
17
|
+
1: 'splices', 2: 'contract by aside', 3: 'emphasis devices',
|
|
18
|
+
4: 'elegant variation', 5: 'flourish over identifier', 6: 'consequence glue',
|
|
19
|
+
7: 'hedging', 8: 'noting fillers', 9: 'restatement',
|
|
20
|
+
10: 'justification rider', 11: 'decorative verbs', 12: 'audience misjudged',
|
|
21
|
+
13: 'throat-clearing', 14: "today's-world opener", 15: 'announce-then-deliver',
|
|
22
|
+
16: 'not-X-but-Y', 17: 'teaser pivot', 18: 'rhetorical questions',
|
|
23
|
+
19: 'filler transitions', 20: 'forced symmetry', 21: 'appraisal preamble',
|
|
24
|
+
22: 'artifact-as-agent', 23: 'recipient-as-subject', 24: 'decoration',
|
|
25
|
+
25: 'over-structuring', 26: 'false depth'}
|
|
26
|
+
|
|
27
|
+
# %% ../nbs/00_core.ipynb #94d1c18f
|
|
28
|
+
KILL,SMELL,PRESSURE = 10,3,1
|
|
29
|
+
|
|
30
|
+
# %% ../nbs/00_core.ipynb #705a0d27
|
|
31
|
+
class Finding:
|
|
32
|
+
def __init__(self,
|
|
33
|
+
rule, # Name of the rule that fired
|
|
34
|
+
tell, # `write_docs` tell number the rule detects
|
|
35
|
+
start, # Character offset where the span starts, within the text the detector received
|
|
36
|
+
end, # Character offset one past the span's end
|
|
37
|
+
text, # The offending span itself
|
|
38
|
+
weight, # The rule's tier, escalated where the rule escalates
|
|
39
|
+
suggestion=None, # A mechanical replacement, when one exists
|
|
40
|
+
): store_attr()
|
|
41
|
+
def __repr__(self):
|
|
42
|
+
sug = f' -> {self.suggestion!r}' if self.suggestion else ''
|
|
43
|
+
tl = '' if self.tell is None else f' (tell {self.tell}, {tells[self.tell]})'
|
|
44
|
+
return f'[{self.weight}] {self.rule}{tl}: {self.text!r}{sug}'
|
|
45
|
+
|
|
46
|
+
# %% ../nbs/00_core.ipynb #50e848c5
|
|
47
|
+
rules = {}
|
|
48
|
+
|
|
49
|
+
def rule(
|
|
50
|
+
name, # Rule name, unique within slopometer
|
|
51
|
+
tell, # `write_docs` tell number the rule detects
|
|
52
|
+
weight, # Tier the rule's findings carry
|
|
53
|
+
level, # The unit the detector reads: 'phrase', 'sentence', 'para', or 'doc'
|
|
54
|
+
):
|
|
55
|
+
"Register a detector, a function from its unit's text to the list of `Finding`s in it"
|
|
56
|
+
def _f(f):
|
|
57
|
+
f.tell,f.weight,f.level = tell,weight,level
|
|
58
|
+
rules[name] = f
|
|
59
|
+
return f
|
|
60
|
+
return _f
|
|
61
|
+
|
|
62
|
+
# %% ../nbs/00_core.ipynb #d45bdd74
|
|
63
|
+
_ornament = re.compile(r'[\u2190-\u2bff\ufe0f\U0001f000-\U0001faff]+')
|
|
64
|
+
_arrows = {'→':'->', '⇒':'=>', '←':'<-', '↔':'<->'}
|
|
65
|
+
|
|
66
|
+
@rule('decoration', tell=24, weight=KILL, level='phrase')
|
|
67
|
+
def find_decoration(txt):
|
|
68
|
+
"Flag emoji and ornamental unicode, suggesting ASCII for arrows"
|
|
69
|
+
return [Finding('decoration', 24, m.start(), m.end(), m.group(), KILL, _arrows.get(m.group()))
|
|
70
|
+
for m in _ornament.finditer(txt)]
|
|
71
|
+
|
|
72
|
+
# %% ../nbs/00_core.ipynb #1af3670a
|
|
73
|
+
unscoreable = {
|
|
74
|
+
2: 'knowing which fact is the contract takes judgment',
|
|
75
|
+
5: "telling a flourish from a real identifier takes the project's vocabulary",
|
|
76
|
+
9: 'lead-sentence restatement defeats averaged sentence vectors, and only the heading echo is detectable (measured in the para notebook)',
|
|
77
|
+
10: 'a justification rider reads like a stated consequence, and only the domain says which it is',
|
|
78
|
+
11: 'verb texture beyond the banned-verb lexicon is a whiteboard judgment',
|
|
79
|
+
12: 'matching prose to its audience takes the audience, and the coinage rule covers only the definable half',
|
|
80
|
+
26: 'depth is judged against what the reader already knows',}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Continuous measurements for learned scoring
|
|
2
|
+
|
|
3
|
+
The rules keep only what crosses a bar, and a learned scorer wants the bar removed. This module measures prose as continuous numbers: every rule's findings as a rate, the sentence and paragraph distributions the thresholds truncate, the parts-of-speech profile, specifics density, referential load, and burstiness. Three of these measures failed earlier as threshold rules, and the para and score notebooks record why. As features they need no threshold, because a learned combiner such as a random forest weighs them against labeled examples. The score stays rule-based and explainable. The feature vector exists for calibration experiments, and anything the experiments validate can graduate into a rule.
|
|
4
|
+
|
|
5
|
+
Docs: https://AnswerDotAI.github.io/slopometer/features.html.md"""
|
|
6
|
+
|
|
7
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/07_features.ipynb.
|
|
8
|
+
|
|
9
|
+
# %% auto #0
|
|
10
|
+
__all__ = ['burstiness', 'flattest_window', 'features']
|
|
11
|
+
|
|
12
|
+
# %% ../nbs/07_features.ipynb #e0f7d103
|
|
13
|
+
import statistics
|
|
14
|
+
from collections import Counter
|
|
15
|
+
from fastcore.utils import *
|
|
16
|
+
from .core import *
|
|
17
|
+
from .segment import *
|
|
18
|
+
from .lexicon import *
|
|
19
|
+
from .syntax import *
|
|
20
|
+
from .para import *
|
|
21
|
+
from .score import run_rules
|
|
22
|
+
|
|
23
|
+
# %% ../nbs/07_features.ipynb #bc8d7df9
|
|
24
|
+
def burstiness(xs):
|
|
25
|
+
"Goh-Barabasi B over `xs`: -1 uniform, 0 random, positive bursty"
|
|
26
|
+
if len(xs) < 2: return 0.0
|
|
27
|
+
m, s = statistics.mean(xs), statistics.stdev(xs)
|
|
28
|
+
return 0.0 if m + s == 0 else round((s - m) / (s + m), 3)
|
|
29
|
+
|
|
30
|
+
def flattest_window(
|
|
31
|
+
xs, # Sentence lengths, in document order
|
|
32
|
+
k=5, # Window size in sentences
|
|
33
|
+
):
|
|
34
|
+
"`(start, spread)` of the length-`k` run with the lowest variation, for localizing monotone stretches"
|
|
35
|
+
if len(xs) <= k: return 0, round(statistics.stdev(xs), 2) if len(xs) > 1 else 0.0
|
|
36
|
+
spans = [(i, round(statistics.stdev(xs[i:i+k]), 2)) for i in range(len(xs) - k + 1)]
|
|
37
|
+
return min(spans, key=lambda t: t[1])
|
|
38
|
+
|
|
39
|
+
# %% ../nbs/07_features.ipynb #b422bd19
|
|
40
|
+
_conn = dict(add={'also', 'furthermore', 'moreover', 'additionally'}, causal={'because', 'therefore', 'thus', 'hence'},
|
|
41
|
+
advers={'but', 'however', 'although', 'though', 'yet'})
|
|
42
|
+
|
|
43
|
+
def features(txt):
|
|
44
|
+
"Continuous measurements of markdown `txt`, one flat dict"
|
|
45
|
+
blocks = segment(txt)
|
|
46
|
+
docs = parse_blocks(blocks)
|
|
47
|
+
prose = [d for d in docs if d is not None]
|
|
48
|
+
sents = [s for d in prose for s in d.sents]
|
|
49
|
+
toks = [t for d in prose for t in d]
|
|
50
|
+
nw = max(sum(1 for t in toks if t.is_alpha), 1)
|
|
51
|
+
res = dict(words=nw, sents=len(sents), headings=n_headings(blocks))
|
|
52
|
+
agg = Counter()
|
|
53
|
+
for f in run_rules(txt): agg[f.rule] += f.weight
|
|
54
|
+
res |= {f'r_{k}': round(100*v/nw, 2) for k, v in agg.items()}
|
|
55
|
+
res['density'] = round(100*sum(agg.values())/nw, 1)
|
|
56
|
+
slens = [sum(1 for t in s if not t.is_punct) for s in sents]
|
|
57
|
+
if len(slens) > 1:
|
|
58
|
+
res |= dict(slen_mean=round(statistics.mean(slens), 1), slen_max=max(slens), slen_burst=burstiness(slens))
|
|
59
|
+
starts = [next((t.lemma_.lower() for t in s if t.is_alpha), '') for s in sents]
|
|
60
|
+
res['start_div'] = round(len(set(starts))/len(starts), 2)
|
|
61
|
+
plens = [sum(1 for _ in d.sents) for d in prose]
|
|
62
|
+
if plens: res |= dict(psents_mean=round(statistics.mean(plens), 1), psents_max=max(plens))
|
|
63
|
+
pos = Counter(t.pos_ for t in toks)
|
|
64
|
+
res |= dict(adv=round(100*pos['ADV']/nw, 1), adj=round(100*pos['ADJ']/nw, 1),
|
|
65
|
+
noun_verb=round(pos['NOUN']/max(pos['VERB'], 1), 2),
|
|
66
|
+
cop=round(sum(1 for s in sents if s.root.lemma_ == 'be')/max(len(sents), 1), 2))
|
|
67
|
+
ncode = sum(len(re.findall(r'X{2,}', scrub(b.txt))) for b in blocks)
|
|
68
|
+
res['specifics'] = round(100*(pos['NUM'] + pos['PROPN'] + ncode)/nw, 1)
|
|
69
|
+
res['pron_subj'] = round(sum(1 for s in sents if any(t.dep_ in ('nsubj', 'nsubjpass') and t.pos_ == 'PRON'
|
|
70
|
+
and t.head.dep_ == 'ROOT' for t in s))/max(len(sents), 1), 2)
|
|
71
|
+
seen, ndef, ncold = set(), 0, 0
|
|
72
|
+
for d in prose:
|
|
73
|
+
for t in d:
|
|
74
|
+
if t.pos_ not in ('NOUN', 'PROPN') or len(set(t.lower_)) == 1: continue
|
|
75
|
+
lem = t.lemma_.lower()
|
|
76
|
+
kids = [c.lower_ for c in t.children]
|
|
77
|
+
if 'the' in kids and 'same' not in kids:
|
|
78
|
+
ndef += 1
|
|
79
|
+
if lem not in seen: ncold += 1
|
|
80
|
+
seen.add(lem)
|
|
81
|
+
res |= dict(defs=ndef, cold=round(ncold/max(ndef, 1), 2))
|
|
82
|
+
res |= {f'conn_{k}': round(100*sum(1 for t in toks if t.lemma_.lower() in v)/nw, 2) for k, v in _conn.items()}
|
|
83
|
+
return res
|