swarmauri_evaluatorpool_accessibility 0.3.0.dev16__tar.gz → 0.11.0.dev1__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.
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/PKG-INFO +23 -25
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/README.md +16 -20
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/pyproject.toml +9 -7
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/AccessibilityEvaluatorPool.py +20 -7
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/AutomatedReadabilityIndexEvaluator.py +26 -8
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/ColemanLiauIndexEvaluator.py +16 -6
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/FleschKincaidGradeEvaluator.py +45 -18
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/FleschReadingEaseEvaluator.py +20 -9
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/GunningFogEvaluator.py +15 -6
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/swarmauri_evaluatorpool_accessibility/__init__.py +3 -1
- {swarmauri_evaluatorpool_accessibility-0.3.0.dev16 → swarmauri_evaluatorpool_accessibility-0.11.0.dev1}/LICENSE +0 -0
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: swarmauri_evaluatorpool_accessibility
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
4
|
Summary: A package providing accessibility and readability evaluators for SwarmAuri
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Keywords: accessibility,readability,evaluator,swarmauri,flesch-kincaid,gunning-fog,coleman-liau,automated-readability-index,flesch-reading-ease,text-analysis,nlp,sdk,standards,evaluatorpool,evaluation
|
|
8
8
|
Author: Jacob Stewart
|
|
9
9
|
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.
|
|
10
|
+
Requires-Python: >=3.10,<3.15
|
|
11
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
13
|
Classifier: Intended Audience :: Developers
|
|
17
14
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
15
|
Classifier: Topic :: Text Processing :: Linguistic
|
|
@@ -20,6 +17,11 @@ Classifier: Topic :: Software Development :: Quality Assurance
|
|
|
20
17
|
Classifier: Programming Language :: Python
|
|
21
18
|
Classifier: Programming Language :: Python :: 3
|
|
22
19
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
25
|
Requires-Dist: beautifulsoup4
|
|
24
26
|
Requires-Dist: markdown
|
|
25
27
|
Requires-Dist: nltk
|
|
@@ -29,34 +31,28 @@ Requires-Dist: swarmauri_core
|
|
|
29
31
|
Requires-Dist: swarmauri_standard
|
|
30
32
|
Description-Content-Type: text/markdown
|
|
31
33
|
|
|
32
|
-

|
|
33
35
|
|
|
34
36
|
<p align="center">
|
|
35
|
-
<a href="https://
|
|
36
|
-
<img src="https://
|
|
37
|
-
</a>
|
|
37
|
+
<a href="https://pepy.tech/project/swarmauri_evaluatorpool_accessibility/">
|
|
38
|
+
<img src="https://static.pepy.tech/badge/swarmauri_evaluatorpool_accessibility/month" alt="PyPI - Downloads"/></a>
|
|
38
39
|
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluatorpool_accessibility/">
|
|
39
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluatorpool_accessibility.svg"
|
|
40
|
-
</a>
|
|
40
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluatorpool_accessibility.svg"/></a>
|
|
41
41
|
<a href="https://pypi.org/project/swarmauri_evaluatorpool_accessibility/">
|
|
42
|
-
<img src="https://img.shields.io/
|
|
43
|
-
</a>
|
|
42
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
44
43
|
<a href="https://pypi.org/project/swarmauri_evaluatorpool_accessibility/">
|
|
45
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_evaluatorpool_accessibility" alt="PyPI - License"
|
|
46
|
-
</a>
|
|
44
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_evaluatorpool_accessibility" alt="PyPI - License"/></a>
|
|
47
45
|
<a href="https://pypi.org/project/swarmauri_evaluatorpool_accessibility/">
|
|
48
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_evaluatorpool_accessibility?label=swarmauri_evaluatorpool_accessibility&color=green" alt="PyPI - swarmauri_evaluatorpool_accessibility"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
---
|
|
46
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_evaluatorpool_accessibility?label=swarmauri_evaluatorpool_accessibility&color=green" alt="PyPI - swarmauri_evaluatorpool_accessibility"/></a>
|
|
47
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
48
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
53
49
|
|
|
54
50
|
# Swarmauri Evaluatorpool Accessibility
|
|
55
51
|
|
|
56
52
|
Accessibility-focused evaluator pool for Swarmauri programs. The pool bundles a
|
|
57
|
-
set of classic readability metrics (Automated Readability Index, Coleman
|
|
58
|
-
Flesch
|
|
59
|
-
scores onto a single 0
|
|
53
|
+
set of classic readability metrics (Automated Readability Index, Coleman?Liau,
|
|
54
|
+
Flesch?Kincaid Grade, Flesch Reading Ease, and Gunning Fog) and normalises their
|
|
55
|
+
scores onto a single 0?1 scale where higher values mean easier-to-read content.
|
|
60
56
|
|
|
61
57
|
## Installation
|
|
62
58
|
|
|
@@ -120,14 +116,14 @@ pool.shutdown() # release resources when finished
|
|
|
120
116
|
|
|
121
117
|
Each entry returned from `evaluate` is an `EvalResultBase` with:
|
|
122
118
|
|
|
123
|
-
- `score`: the weighted mean of the evaluator scores mapped to the 0
|
|
119
|
+
- `score`: the weighted mean of the evaluator scores mapped to the 0?1 range.
|
|
124
120
|
- `metadata["evaluator_scores"]`: raw scores keyed by evaluator name.
|
|
125
121
|
- `metadata["evaluator_metadata"]`: evaluator-specific metadata (e.g. sentence
|
|
126
122
|
counts, syllable estimates, interpretation strings).
|
|
127
123
|
- `metadata["aggregate_score"]`: mirrors `.score` for convenience.
|
|
128
124
|
|
|
129
125
|
You can customise the weighting of each evaluator by passing a `weights`
|
|
130
|
-
dictionary (name
|
|
126
|
+
dictionary (name ? float) when constructing the pool.
|
|
131
127
|
|
|
132
128
|
### Notes
|
|
133
129
|
|
|
@@ -145,3 +141,5 @@ dictionary (name → float) when constructing the pool.
|
|
|
145
141
|
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
146
142
|
|
|
147
143
|
|
|
144
|
+
|
|
145
|
+
|
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<a href="https://
|
|
5
|
-
<img src="https://
|
|
6
|
-
</a>
|
|
4
|
+
<a href="https://pepy.tech/project/swarmauri_evaluatorpool_accessibility/">
|
|
5
|
+
<img src="https://static.pepy.tech/badge/swarmauri_evaluatorpool_accessibility/month" alt="PyPI - Downloads"/></a>
|
|
7
6
|
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluatorpool_accessibility/">
|
|
8
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluatorpool_accessibility.svg"
|
|
9
|
-
</a>
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_evaluatorpool_accessibility.svg"/></a>
|
|
10
8
|
<a href="https://pypi.org/project/swarmauri_evaluatorpool_accessibility/">
|
|
11
|
-
<img src="https://img.shields.io/
|
|
12
|
-
</a>
|
|
9
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
13
10
|
<a href="https://pypi.org/project/swarmauri_evaluatorpool_accessibility/">
|
|
14
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_evaluatorpool_accessibility" alt="PyPI - License"
|
|
15
|
-
</a>
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_evaluatorpool_accessibility" alt="PyPI - License"/></a>
|
|
16
12
|
<a href="https://pypi.org/project/swarmauri_evaluatorpool_accessibility/">
|
|
17
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_evaluatorpool_accessibility?label=swarmauri_evaluatorpool_accessibility&color=green" alt="PyPI - swarmauri_evaluatorpool_accessibility"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
---
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_evaluatorpool_accessibility?label=swarmauri_evaluatorpool_accessibility&color=green" alt="PyPI - swarmauri_evaluatorpool_accessibility"/></a>
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
22
16
|
|
|
23
17
|
# Swarmauri Evaluatorpool Accessibility
|
|
24
18
|
|
|
25
19
|
Accessibility-focused evaluator pool for Swarmauri programs. The pool bundles a
|
|
26
|
-
set of classic readability metrics (Automated Readability Index, Coleman
|
|
27
|
-
Flesch
|
|
28
|
-
scores onto a single 0
|
|
20
|
+
set of classic readability metrics (Automated Readability Index, Coleman?Liau,
|
|
21
|
+
Flesch?Kincaid Grade, Flesch Reading Ease, and Gunning Fog) and normalises their
|
|
22
|
+
scores onto a single 0?1 scale where higher values mean easier-to-read content.
|
|
29
23
|
|
|
30
24
|
## Installation
|
|
31
25
|
|
|
@@ -89,14 +83,14 @@ pool.shutdown() # release resources when finished
|
|
|
89
83
|
|
|
90
84
|
Each entry returned from `evaluate` is an `EvalResultBase` with:
|
|
91
85
|
|
|
92
|
-
- `score`: the weighted mean of the evaluator scores mapped to the 0
|
|
86
|
+
- `score`: the weighted mean of the evaluator scores mapped to the 0?1 range.
|
|
93
87
|
- `metadata["evaluator_scores"]`: raw scores keyed by evaluator name.
|
|
94
88
|
- `metadata["evaluator_metadata"]`: evaluator-specific metadata (e.g. sentence
|
|
95
89
|
counts, syllable estimates, interpretation strings).
|
|
96
90
|
- `metadata["aggregate_score"]`: mirrors `.score` for convenience.
|
|
97
91
|
|
|
98
92
|
You can customise the weighting of each evaluator by passing a `weights`
|
|
99
|
-
dictionary (name
|
|
93
|
+
dictionary (name ? float) when constructing the pool.
|
|
100
94
|
|
|
101
95
|
### Notes
|
|
102
96
|
|
|
@@ -113,3 +107,5 @@ dictionary (name → float) when constructing the pool.
|
|
|
113
107
|
|
|
114
108
|
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
115
109
|
|
|
110
|
+
|
|
111
|
+
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_evaluatorpool_accessibility"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
4
|
description = "A package providing accessibility and readability evaluators for SwarmAuri"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
repository = "https://github.com/swarmauri/swarmauri-sdk/pkgs/standards/swarmauri_evaluatorpool_accessibility/"
|
|
8
|
-
requires-python = ">=3.10,<3.
|
|
8
|
+
requires-python = ">=3.10,<3.15"
|
|
9
9
|
classifiers = [
|
|
10
10
|
"License :: OSI Approved :: Apache Software License",
|
|
11
11
|
"Natural Language :: English",
|
|
12
|
-
"Programming Language :: Python :: 3.10",
|
|
13
|
-
"Programming Language :: Python :: 3.11",
|
|
14
|
-
"Programming Language :: Python :: 3.12",
|
|
15
12
|
"Intended Audience :: Developers",
|
|
16
13
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
17
14
|
"Topic :: Text Processing :: Linguistic",
|
|
18
15
|
"Topic :: Software Development :: Quality Assurance",
|
|
19
16
|
"Programming Language :: Python",
|
|
20
17
|
"Programming Language :: Python :: 3",
|
|
21
|
-
"Programming Language :: Python :: 3 :: Only"
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
22
24
|
]
|
|
23
25
|
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
24
26
|
keywords = [
|
|
@@ -95,7 +97,7 @@ dev = [
|
|
|
95
97
|
"pytest-xdist>=3.6.1",
|
|
96
98
|
"pytest-json-report>=1.5.0",
|
|
97
99
|
"python-dotenv",
|
|
98
|
-
"
|
|
100
|
+
"httpx>=0.27",
|
|
99
101
|
"flake8>=7.0",
|
|
100
102
|
"pytest-timeout>=2.3.1",
|
|
101
103
|
"ruff>=0.9.9",
|
|
@@ -55,7 +55,8 @@ class AccessibilityEvaluatorPool(EvaluatorPoolBase):
|
|
|
55
55
|
self.evaluators = self._EvaluatorRegistry()
|
|
56
56
|
self._allow_add = True
|
|
57
57
|
|
|
58
|
-
# The pool’s registry is a Dict[str, IEvaluate] coming from the
|
|
58
|
+
# The pool’s registry is a Dict[str, IEvaluate] coming from the
|
|
59
|
+
# base-class
|
|
59
60
|
self.weights: Dict[str, float] = weights or {}
|
|
60
61
|
|
|
61
62
|
# ------------------------------------------------------------------ #
|
|
@@ -98,16 +99,23 @@ class AccessibilityEvaluatorPool(EvaluatorPoolBase):
|
|
|
98
99
|
self.weights.setdefault(cls.__name__, 1.0)
|
|
99
100
|
except Exception as exc: # pragma: no cover
|
|
100
101
|
if self.logger:
|
|
101
|
-
self.logger.error(
|
|
102
|
+
self.logger.error(
|
|
103
|
+
"Failed to instantiate %s: %s", cls.__name__, exc
|
|
104
|
+
)
|
|
102
105
|
|
|
103
|
-
def _register_evaluator_internal(
|
|
106
|
+
def _register_evaluator_internal(
|
|
107
|
+
self, evaluator: IEvaluate, name: str
|
|
108
|
+
) -> None:
|
|
104
109
|
super().add_evaluator(evaluator, name)
|
|
105
110
|
|
|
106
111
|
def add_evaluator(self, evaluator: IEvaluate, name: Any = None) -> str: # type: ignore[override]
|
|
107
112
|
"""Legacy behavior: disallow runtime add after initialization."""
|
|
108
113
|
if not self._allow_add:
|
|
109
114
|
raise RuntimeError(
|
|
110
|
-
|
|
115
|
+
(
|
|
116
|
+
"AccessibilityEvaluatorPool manages evaluator registration " # noqa: E501
|
|
117
|
+
"internally"
|
|
118
|
+
)
|
|
111
119
|
)
|
|
112
120
|
if not isinstance(name, str) and name is not None:
|
|
113
121
|
name = evaluator.__class__.__name__
|
|
@@ -169,7 +177,9 @@ class AccessibilityEvaluatorPool(EvaluatorPoolBase):
|
|
|
169
177
|
|
|
170
178
|
def _legacy_evaluate(self, program: Program) -> Dict[str, Any]:
|
|
171
179
|
source_files = (
|
|
172
|
-
program.get_source_files()
|
|
180
|
+
program.get_source_files()
|
|
181
|
+
if hasattr(program, "get_source_files")
|
|
182
|
+
else {}
|
|
173
183
|
)
|
|
174
184
|
file_scores = {
|
|
175
185
|
path: self._evaluate_file(path, content)
|
|
@@ -202,7 +212,9 @@ class AccessibilityEvaluatorPool(EvaluatorPoolBase):
|
|
|
202
212
|
|
|
203
213
|
def evaluate(self, programs: Any, **kwargs: Any) -> Any: # type: ignore[override]
|
|
204
214
|
# Backward-compatible single-program mode used in unit tests.
|
|
205
|
-
if not isinstance(programs, Sequence) or isinstance(
|
|
215
|
+
if not isinstance(programs, Sequence) or isinstance(
|
|
216
|
+
programs, (str, bytes)
|
|
217
|
+
):
|
|
206
218
|
return self._legacy_evaluate(programs)
|
|
207
219
|
return super().evaluate(programs, **kwargs)
|
|
208
220
|
|
|
@@ -225,7 +237,8 @@ class AccessibilityEvaluatorPool(EvaluatorPoolBase):
|
|
|
225
237
|
better” and return a weighted mean.
|
|
226
238
|
|
|
227
239
|
* FleschReadingEase already gives “higher == easier” → scale to 0-1.
|
|
228
|
-
* All other metrics are “grade-level” indices (lower == easier) →
|
|
240
|
+
* All other metrics are “grade-level” indices (lower == easier) →
|
|
241
|
+
invert.
|
|
229
242
|
"""
|
|
230
243
|
names = self.get_evaluator_names()
|
|
231
244
|
if not names:
|
|
@@ -12,10 +12,13 @@ from swarmauri_base.evaluators.EvaluatorBase import EvaluatorBase
|
|
|
12
12
|
from swarmauri_standard.programs.Program import Program
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
@ComponentBase.register_type(
|
|
15
|
+
@ComponentBase.register_type(
|
|
16
|
+
EvaluatorBase, "AutomatedReadabilityIndexEvaluator"
|
|
17
|
+
)
|
|
16
18
|
class AutomatedReadabilityIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
17
19
|
"""
|
|
18
|
-
Computes the Automated Readability Index (ARI) for a Program’s textual
|
|
20
|
+
Computes the Automated Readability Index (ARI) for a Program’s textual
|
|
21
|
+
sources.
|
|
19
22
|
|
|
20
23
|
Conforms to the IEvaluate interface by returning a dict:
|
|
21
24
|
{ "score": <float>, "metadata": <dict> }
|
|
@@ -29,7 +32,9 @@ class AutomatedReadabilityIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
|
29
32
|
# ────────────────────────────────────────────────────────────────────
|
|
30
33
|
# public IEvaluate API
|
|
31
34
|
# ────────────────────────────────────────────────────────────────────
|
|
32
|
-
def evaluate(
|
|
35
|
+
def evaluate(
|
|
36
|
+
self, program: Program, **kwargs
|
|
37
|
+
) -> Dict[str, Any]: # IEvaluate
|
|
33
38
|
score, meta = self._compute_score(program, **kwargs)
|
|
34
39
|
return {"score": score, "metadata": meta}
|
|
35
40
|
|
|
@@ -47,7 +52,12 @@ class AutomatedReadabilityIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
|
47
52
|
text = self._extract_text_from_program(program)
|
|
48
53
|
|
|
49
54
|
if not text.strip():
|
|
50
|
-
return 0.0, {
|
|
55
|
+
return 0.0, {
|
|
56
|
+
"error": "no_text",
|
|
57
|
+
"chars": 0,
|
|
58
|
+
"words": 0,
|
|
59
|
+
"sentences": 0,
|
|
60
|
+
}
|
|
51
61
|
|
|
52
62
|
chars = len(text)
|
|
53
63
|
words_list = self._count_words(text)
|
|
@@ -87,9 +97,13 @@ class AutomatedReadabilityIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
|
87
97
|
raw = f.read()
|
|
88
98
|
if ext in (".md", ".markdown"):
|
|
89
99
|
html = markdown.markdown(raw)
|
|
90
|
-
segments.append(
|
|
100
|
+
segments.append(
|
|
101
|
+
BeautifulSoup(html, "html.parser").get_text()
|
|
102
|
+
)
|
|
91
103
|
elif ext in (".html", ".htm"):
|
|
92
|
-
segments.append(
|
|
104
|
+
segments.append(
|
|
105
|
+
BeautifulSoup(raw, "html.parser").get_text()
|
|
106
|
+
)
|
|
93
107
|
else:
|
|
94
108
|
segments.append(raw)
|
|
95
109
|
except Exception as exc:
|
|
@@ -110,9 +124,13 @@ class AutomatedReadabilityIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
|
110
124
|
try:
|
|
111
125
|
if ext in (".md", ".markdown"):
|
|
112
126
|
html = markdown.markdown(data)
|
|
113
|
-
segments.append(
|
|
127
|
+
segments.append(
|
|
128
|
+
BeautifulSoup(html, "html.parser").get_text()
|
|
129
|
+
)
|
|
114
130
|
elif ext in (".html", ".htm"):
|
|
115
|
-
segments.append(
|
|
131
|
+
segments.append(
|
|
132
|
+
BeautifulSoup(data, "html.parser").get_text()
|
|
133
|
+
)
|
|
116
134
|
else:
|
|
117
135
|
segments.append(data)
|
|
118
136
|
except Exception as exc:
|
|
@@ -11,10 +11,12 @@ from swarmauri_standard.programs.Program import Program
|
|
|
11
11
|
@ComponentBase.register_type(EvaluatorBase, "ColemanLiauIndexEvaluator")
|
|
12
12
|
class ColemanLiauIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
13
13
|
"""
|
|
14
|
-
Coleman–Liau Index evaluator compliant with the Program/Evaluator
|
|
14
|
+
Coleman–Liau Index evaluator compliant with the Program/Evaluator
|
|
15
|
+
contracts.
|
|
15
16
|
|
|
16
17
|
• ``evaluate()`` returns ``{"score": float, "metadata": dict}``.
|
|
17
|
-
• ``_compute_score()`` returns ``Tuple[float, Dict[str, Any]]`` for
|
|
18
|
+
• ``_compute_score()`` returns ``Tuple[float, Dict[str, Any]]`` for
|
|
19
|
+
internal use.
|
|
18
20
|
"""
|
|
19
21
|
|
|
20
22
|
type: Literal["ColemanLiauIndexEvaluator"] = "ColemanLiauIndexEvaluator"
|
|
@@ -27,14 +29,18 @@ class ColemanLiauIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
|
27
29
|
# Public API – called by the pool / runner
|
|
28
30
|
# ──────────────────────────────────────────────────────────────────────
|
|
29
31
|
def evaluate(self, program: Program, **kwargs) -> Dict[str, Any]:
|
|
30
|
-
"""
|
|
32
|
+
"""
|
|
33
|
+
Return ``{"score": float, "metadata": dict}`` for the given program.
|
|
34
|
+
"""
|
|
31
35
|
score, meta = self._compute_score(program, **kwargs)
|
|
32
36
|
return {"score": score, "metadata": meta}
|
|
33
37
|
|
|
34
38
|
# ──────────────────────────────────────────────────────────────────────
|
|
35
39
|
# Core scoring logic
|
|
36
40
|
# ──────────────────────────────────────────────────────────────────────
|
|
37
|
-
def _compute_score(
|
|
41
|
+
def _compute_score(
|
|
42
|
+
self, program: Program, **__
|
|
43
|
+
) -> Tuple[float, Dict[str, Any]]:
|
|
38
44
|
text = self._get_text_from_program(program)
|
|
39
45
|
|
|
40
46
|
if not text.strip():
|
|
@@ -110,14 +116,18 @@ class ColemanLiauIndexEvaluator(EvaluatorBase, ComponentBase):
|
|
|
110
116
|
if isinstance(val, str):
|
|
111
117
|
return val
|
|
112
118
|
if isinstance(val, dict):
|
|
113
|
-
joined = "\n".join(
|
|
119
|
+
joined = "\n".join(
|
|
120
|
+
v for v in val.values() if isinstance(v, str)
|
|
121
|
+
)
|
|
114
122
|
if joined.strip():
|
|
115
123
|
return joined
|
|
116
124
|
|
|
117
125
|
if hasattr(program, "get_source_files"):
|
|
118
126
|
files = program.get_source_files()
|
|
119
127
|
if isinstance(files, dict):
|
|
120
|
-
joined = "\n".join(
|
|
128
|
+
joined = "\n".join(
|
|
129
|
+
v for v in files.values() if isinstance(v, str)
|
|
130
|
+
)
|
|
121
131
|
if joined.strip():
|
|
122
132
|
return joined
|
|
123
133
|
|
|
@@ -14,7 +14,8 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
14
14
|
|
|
15
15
|
This evaluator analyzes text to determine its readability according to the
|
|
16
16
|
Flesch-Kincaid Grade Level formula, which estimates the U.S. grade level
|
|
17
|
-
required to understand the text. The formula considers average sentence
|
|
17
|
+
required to understand the text. The formula considers average sentence
|
|
18
|
+
length
|
|
18
19
|
and average syllables per word.
|
|
19
20
|
|
|
20
21
|
Formula: FKGL = 0.39*(words/sentences) + 11.8*(syllables/words) - 15.59
|
|
@@ -23,13 +24,17 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
23
24
|
type: The type identifier for this evaluator
|
|
24
25
|
"""
|
|
25
26
|
|
|
26
|
-
type: Literal["FleschKincaidGradeEvaluator"] =
|
|
27
|
+
type: Literal["FleschKincaidGradeEvaluator"] = (
|
|
28
|
+
"FleschKincaidGradeEvaluator"
|
|
29
|
+
)
|
|
27
30
|
|
|
28
31
|
# ------------------------------------------------------------------
|
|
29
32
|
# public API
|
|
30
33
|
# ------------------------------------------------------------------
|
|
31
34
|
def evaluate(self, program: Program, **kwargs) -> Dict[str, Any]:
|
|
32
|
-
"""
|
|
35
|
+
"""
|
|
36
|
+
Return ``{"score": float, "metadata": dict}`` for the given program.
|
|
37
|
+
"""
|
|
33
38
|
score, meta = self._compute_score(program, **kwargs)
|
|
34
39
|
return {"score": score, "metadata": meta}
|
|
35
40
|
|
|
@@ -37,9 +42,11 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
37
42
|
self, program: Program, **kwargs
|
|
38
43
|
) -> Tuple[float, Dict[str, Any]]:
|
|
39
44
|
"""
|
|
40
|
-
Compute the Flesch-Kincaid Grade Level score for a program's text
|
|
45
|
+
Compute the Flesch-Kincaid Grade Level score for a program's text
|
|
46
|
+
output.
|
|
41
47
|
|
|
42
|
-
This method analyzes the text produced by a program, counting
|
|
48
|
+
This method analyzes the text produced by a program, counting
|
|
49
|
+
sentences,
|
|
43
50
|
words, and syllables to calculate the FKGL score.
|
|
44
51
|
|
|
45
52
|
Args:
|
|
@@ -49,11 +56,14 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
49
56
|
Returns:
|
|
50
57
|
A tuple containing:
|
|
51
58
|
- float: The Flesch-Kincaid Grade Level score
|
|
52
|
-
- Dict[str, Any]: Metadata including sentence count, word
|
|
53
|
-
|
|
59
|
+
- Dict[str, Any]: Metadata including sentence count, word
|
|
60
|
+
count,
|
|
61
|
+
syllable count, and the breakdown of the
|
|
62
|
+
calculation
|
|
54
63
|
|
|
55
64
|
Raises:
|
|
56
|
-
ValueError: If the program has no text output or if text analysis
|
|
65
|
+
ValueError: If the program has no text output or if text analysis
|
|
66
|
+
fails
|
|
57
67
|
"""
|
|
58
68
|
# Get the text from the program's output
|
|
59
69
|
text = self._get_program_text(program)
|
|
@@ -70,7 +80,10 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
70
80
|
|
|
71
81
|
if self.logger:
|
|
72
82
|
self.logger.debug(
|
|
73
|
-
|
|
83
|
+
(
|
|
84
|
+
f"Text analysis: {sentences} sentences, {words} words, "
|
|
85
|
+
f"{syllables} syllables"
|
|
86
|
+
)
|
|
74
87
|
)
|
|
75
88
|
|
|
76
89
|
# Calculate the Flesch-Kincaid Grade Level
|
|
@@ -90,10 +103,14 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
90
103
|
avg_sentence_length = words / sentences
|
|
91
104
|
avg_syllables_per_word = syllables / words
|
|
92
105
|
|
|
93
|
-
# Apply the FKGL formula: 0.39*(words/sentences) +
|
|
94
|
-
|
|
106
|
+
# Apply the FKGL formula: 0.39*(words/sentences) +
|
|
107
|
+
# 11.8*(syllables/words) - 15.59
|
|
108
|
+
fkgl_score = (
|
|
109
|
+
0.39 * avg_sentence_length + 11.8 * avg_syllables_per_word - 15.59
|
|
110
|
+
)
|
|
95
111
|
|
|
96
|
-
# Ensure the score is not negative (which would be meaningless for
|
|
112
|
+
# Ensure the score is not negative (which would be meaningless for
|
|
113
|
+
# grade levels)
|
|
97
114
|
fkgl_score = float(max(0, fkgl_score))
|
|
98
115
|
|
|
99
116
|
# Prepare detailed metadata
|
|
@@ -103,7 +120,9 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
103
120
|
"syllables": syllables,
|
|
104
121
|
"avg_sentence_length": avg_sentence_length,
|
|
105
122
|
"avg_syllables_per_word": avg_syllables_per_word,
|
|
106
|
-
"formula":
|
|
123
|
+
"formula": (
|
|
124
|
+
"0.39*(words/sentences) + 11.8*(syllables/words) - 15.59"
|
|
125
|
+
),
|
|
107
126
|
"formula_calculation": {
|
|
108
127
|
"term1": 0.39 * avg_sentence_length,
|
|
109
128
|
"term2": 11.8 * avg_syllables_per_word,
|
|
@@ -128,7 +147,9 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
128
147
|
try:
|
|
129
148
|
source_files = program.get_source_files()
|
|
130
149
|
if isinstance(source_files, dict):
|
|
131
|
-
return " ".join(
|
|
150
|
+
return " ".join(
|
|
151
|
+
self._stringify_value(v) for v in source_files.values()
|
|
152
|
+
)
|
|
132
153
|
except Exception as exc:
|
|
133
154
|
if self.logger:
|
|
134
155
|
self.logger.debug(f"Failed to obtain program text: {exc}")
|
|
@@ -227,7 +248,8 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
227
248
|
|
|
228
249
|
This uses a combination of rules to estimate syllable count:
|
|
229
250
|
1. Count groups of vowels (a, e, i, o, u, y) as potential syllables
|
|
230
|
-
2. Apply adjustments for common patterns like silent 'e' at end of
|
|
251
|
+
2. Apply adjustments for common patterns like silent 'e' at end of
|
|
252
|
+
words
|
|
231
253
|
3. Ensure every word has at least one syllable
|
|
232
254
|
|
|
233
255
|
Args:
|
|
@@ -256,7 +278,8 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
256
278
|
for i, char in enumerate(word):
|
|
257
279
|
is_vowel = char in vowels
|
|
258
280
|
|
|
259
|
-
# Count syllable when we find a vowel that doesn't immediately
|
|
281
|
+
# Count syllable when we find a vowel that doesn't immediately
|
|
282
|
+
# follow another vowel
|
|
260
283
|
if is_vowel and not prev_is_vowel:
|
|
261
284
|
count += 1
|
|
262
285
|
|
|
@@ -267,11 +290,15 @@ class FleschKincaidGradeEvaluator(EvaluatorBase, ComponentBase):
|
|
|
267
290
|
|
|
268
291
|
# Silent 'e' at the end of words
|
|
269
292
|
if word.endswith("e") and len(word) > 2 and word[-2] not in vowels:
|
|
270
|
-
count = max(
|
|
293
|
+
count = max(
|
|
294
|
+
1, count - 1
|
|
295
|
+
) # Reduce count but ensure at least 1 syllable
|
|
271
296
|
|
|
272
297
|
# Words ending in 'le' where the 'l' follows a consonant
|
|
273
298
|
if len(word) > 2 and word.endswith("le") and word[-3] not in vowels:
|
|
274
|
-
count = max(
|
|
299
|
+
count = max(
|
|
300
|
+
1, count
|
|
301
|
+
) # Ensure proper counting for words like "simple"
|
|
275
302
|
|
|
276
303
|
# Words ending in 'ed' often have a silent 'e'
|
|
277
304
|
if word.endswith("ed") and len(word) > 2 and word[-3] not in vowels:
|
|
@@ -21,11 +21,13 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
21
21
|
"""
|
|
22
22
|
Evaluator that computes the Flesch Reading Ease score for text content.
|
|
23
23
|
|
|
24
|
-
The Flesch Reading Ease score is a readability metric that uses sentence
|
|
24
|
+
The Flesch Reading Ease score is a readability metric that uses sentence
|
|
25
|
+
length
|
|
25
26
|
and syllable count to determine how easy a text is to read. The formula is:
|
|
26
27
|
FRE = 206.835 - 1.015*(words/sentences) - 84.6*(syllables/words)
|
|
27
28
|
|
|
28
|
-
Higher scores (closer to 100) indicate text that is easier to read, while
|
|
29
|
+
Higher scores (closer to 100) indicate text that is easier to read, while
|
|
30
|
+
lower
|
|
29
31
|
scores indicate more complex text.
|
|
30
32
|
|
|
31
33
|
Attributes:
|
|
@@ -39,7 +41,9 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
39
41
|
# public API
|
|
40
42
|
# ------------------------------------------------------------------
|
|
41
43
|
def evaluate(self, program: Program, **kwargs) -> Dict[str, Any]:
|
|
42
|
-
"""
|
|
44
|
+
"""
|
|
45
|
+
Return ``{"score": float, "metadata": dict}`` for the given program.
|
|
46
|
+
"""
|
|
43
47
|
score, meta = self._compute_score(program, **kwargs)
|
|
44
48
|
return {"score": score, "metadata": meta}
|
|
45
49
|
|
|
@@ -82,8 +86,10 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
82
86
|
|
|
83
87
|
Returns:
|
|
84
88
|
A tuple containing:
|
|
85
|
-
- float: The Flesch Reading Ease score (0-100, higher is easier
|
|
86
|
-
|
|
89
|
+
- float: The Flesch Reading Ease score (0-100, higher is easier
|
|
90
|
+
to read)
|
|
91
|
+
- Dict[str, Any]: Metadata including sentence and syllable
|
|
92
|
+
statistics
|
|
87
93
|
|
|
88
94
|
Raises:
|
|
89
95
|
ValueError: If the text cannot be processed
|
|
@@ -121,7 +127,9 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
121
127
|
# Calculate Flesch Reading Ease score
|
|
122
128
|
# FRE = 206.835 - 1.015*(words/sentences) - 84.6*(syllables/words)
|
|
123
129
|
fre_score = (
|
|
124
|
-
206.835
|
|
130
|
+
206.835
|
|
131
|
+
- (1.015 * avg_sentence_length)
|
|
132
|
+
- (84.6 * avg_syllables_per_word)
|
|
125
133
|
)
|
|
126
134
|
|
|
127
135
|
# Ensure score is within 0-100 range
|
|
@@ -139,7 +147,7 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
139
147
|
|
|
140
148
|
if self.logger:
|
|
141
149
|
self.logger.info(
|
|
142
|
-
f"Flesch Reading Ease score: {fre_score:.2f} ({metadata['readability_interpretation']})"
|
|
150
|
+
f"Flesch Reading Ease score: {fre_score:.2f} ({metadata['readability_interpretation']})" # noqa: E501
|
|
143
151
|
)
|
|
144
152
|
return fre_score, metadata
|
|
145
153
|
|
|
@@ -148,7 +156,9 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
148
156
|
try:
|
|
149
157
|
source_files = program.get_source_files()
|
|
150
158
|
if isinstance(source_files, dict):
|
|
151
|
-
return " ".join(
|
|
159
|
+
return " ".join(
|
|
160
|
+
v for v in source_files.values() if isinstance(v, str)
|
|
161
|
+
)
|
|
152
162
|
except Exception as exc:
|
|
153
163
|
if self.logger:
|
|
154
164
|
self.logger.debug(f"Failed to obtain program text: {exc}")
|
|
@@ -233,7 +243,8 @@ class FleschReadingEaseEvaluator(EvaluatorBase, ComponentBase):
|
|
|
233
243
|
|
|
234
244
|
def _interpret_score(self, score: float) -> str:
|
|
235
245
|
"""
|
|
236
|
-
Provide a human-readable interpretation of the Flesch Reading Ease
|
|
246
|
+
Provide a human-readable interpretation of the Flesch Reading Ease
|
|
247
|
+
score.
|
|
237
248
|
|
|
238
249
|
Args:
|
|
239
250
|
score: The Flesch Reading Ease score (0-100)
|
|
@@ -14,7 +14,8 @@ class GunningFogEvaluator(EvaluatorBase, ComponentBase):
|
|
|
14
14
|
Evaluator that computes the Gunning Fog Index (GFI) for text readability.
|
|
15
15
|
|
|
16
16
|
The Gunning Fog Index estimates the years of formal education needed to
|
|
17
|
-
understand text on a first reading. Higher scores indicate more complex
|
|
17
|
+
understand text on a first reading. Higher scores indicate more complex
|
|
18
|
+
text.
|
|
18
19
|
The formula is: 0.4 * ((words/sentences) + 100 * (complex_words/words))
|
|
19
20
|
|
|
20
21
|
A complex word is defined as having three or more syllables.
|
|
@@ -29,7 +30,9 @@ class GunningFogEvaluator(EvaluatorBase, ComponentBase):
|
|
|
29
30
|
# public API
|
|
30
31
|
# ------------------------------------------------------------------
|
|
31
32
|
def evaluate(self, program: Program, **kwargs) -> Dict[str, Any]:
|
|
32
|
-
"""
|
|
33
|
+
"""
|
|
34
|
+
Return ``{"score": float, "metadata": dict}`` for the given program.
|
|
35
|
+
"""
|
|
33
36
|
score, meta = self._compute_score(program, **kwargs)
|
|
34
37
|
return {"score": score, "metadata": meta}
|
|
35
38
|
|
|
@@ -45,14 +48,18 @@ class GunningFogEvaluator(EvaluatorBase, ComponentBase):
|
|
|
45
48
|
|
|
46
49
|
Returns:
|
|
47
50
|
A tuple containing:
|
|
48
|
-
- float: The Gunning Fog Index score (lower is better for
|
|
49
|
-
|
|
51
|
+
- float: The Gunning Fog Index score (lower is better for
|
|
52
|
+
readability)
|
|
53
|
+
- Dict[str, Any]: Metadata including sentence count, word
|
|
54
|
+
count, and complex word count
|
|
50
55
|
"""
|
|
51
56
|
text = self._get_program_text(program)
|
|
52
57
|
if not text or not isinstance(text, str):
|
|
53
58
|
if self.logger:
|
|
54
59
|
self.logger.warning("Program text is empty or not a string")
|
|
55
|
-
logging.getLogger(__name__).warning(
|
|
60
|
+
logging.getLogger(__name__).warning(
|
|
61
|
+
"Program text is empty or not a string"
|
|
62
|
+
)
|
|
56
63
|
return 0.0, {"error": "No valid text to analyze"}
|
|
57
64
|
|
|
58
65
|
# Count sentences, words, and complex words
|
|
@@ -92,7 +99,9 @@ class GunningFogEvaluator(EvaluatorBase, ComponentBase):
|
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
if self.logger:
|
|
95
|
-
self.logger.debug(
|
|
102
|
+
self.logger.debug(
|
|
103
|
+
f"Computed Gunning Fog Index: {gunning_fog_index:.2f}"
|
|
104
|
+
)
|
|
96
105
|
logging.getLogger(__name__).debug(
|
|
97
106
|
"Computed Gunning Fog Index: %.2f", gunning_fog_index
|
|
98
107
|
)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
from .AutomatedReadabilityIndexEvaluator import
|
|
1
|
+
from .AutomatedReadabilityIndexEvaluator import (
|
|
2
|
+
AutomatedReadabilityIndexEvaluator,
|
|
3
|
+
)
|
|
2
4
|
from .ColemanLiauIndexEvaluator import ColemanLiauIndexEvaluator
|
|
3
5
|
from .FleschKincaidGradeEvaluator import FleschKincaidGradeEvaluator
|
|
4
6
|
from .FleschReadingEaseEvaluator import FleschReadingEaseEvaluator
|
|
File without changes
|