Swarmauri Tool · Sentence Complexity
A Swarmauri NLP tool that evaluates sentence complexity by measuring average sentence length and estimating clause counts. Use it to monitor writing style, enforce readability requirements, or trigger editorial suggestions in agents.
- Tokenizes text with NLTK to compute sentence and word counts.
- Approximates clause density via punctuation and coordinating/subordinating conjunctions.
- Returns structured metrics suitable for analytics dashboards or conversational feedback.
Requirements
- Python 3.10 – 3.13.
nltk(downloads thepunkt_tabtokenizer data on first import).- Core Swarmauri dependencies (
swarmauri_base,swarmauri_standard,pydantic).
Installation
Choose the packaging workflow that matches your project; each command resolves the dependencies.
pip
pip install swarmauri_tool_sentencecomplexity
Poetry
poetry add swarmauri_tool_sentencecomplexity
uv
# Add to the current project and update uv.lock
uv add swarmauri_tool_sentencecomplexity
# or install into the active environment without modifying pyproject.toml
uv pip install swarmauri_tool_sentencecomplexity
Tip: Pre-download the NLTK tokenizer resources in deployment images (
python -m nltk.downloader punkt_tab) to avoid runtime network calls.
Quick Start
from swarmauri_tool_sentencecomplexity import SentenceComplexityTool
text = "This is a simple sentence. This is another sentence, with a clause."
complexity_tool = SentenceComplexityTool()
result = complexity_tool(text)
print(result)
# {
# 'average_sentence_length': 7.5,
# 'average_clauses_per_sentence': 1.5
# }
The tool raises ValueError when the input text is empty or whitespace.
Usage Scenarios
Flag Long Sentences During Editing
from swarmauri_tool_sentencecomplexity import SentenceComplexityTool
complexity = SentenceComplexityTool()
article = Path("drafts/whitepaper.txt").read_text(encoding="utf-8")
metrics = complexity(article)
if metrics["average_sentence_length"] > 25:
print("Consider splitting long sentences to improve readability.")
Integrate With a Swarmauri Agent for Style Coaching
from swarmauri_core.agent.Agent import Agent
from swarmauri_core.messages.HumanMessage import HumanMessage
from swarmauri_standard.tools.registry import ToolRegistry
from swarmauri_tool_sentencecomplexity import SentenceComplexityTool
registry = ToolRegistry()
registry.register(SentenceComplexityTool())
agent = Agent(tool_registry=registry)
message = HumanMessage(content="Analyze the complexity of: 'While the system scales, it may introduce latency delays.'")
response = agent.run(message)
print(response)
Compare Versions of a Document Over Time
from swarmauri_tool_sentencecomplexity import SentenceComplexityTool
complexity = SentenceComplexityTool()
versions = {
"draft": open("draft.txt").read(),
"final": open("final.txt").read(),
}
for label, text in versions.items():
metrics = complexity(text)
print(f"{label}: {metrics['average_sentence_length']:.1f} words, {metrics['average_clauses_per_sentence']:.2f} clauses")
Track whether edits are making the writing clearer or more complex.
Troubleshooting
LookupError: Resource punkt_tab not found– Runpython -m nltk.downloader punkt_tabbefore executing the tool, especially in offline environments.- Low clause counts for technical prose – The heuristic relies on commas/semicolons and common conjunctions; adjust or extend the tool if you need domain-specific parsing.
- Non-English text – Tokenization models are optimized for English. Supply language-appropriate tokenizers before using the tool for other languages.
License
swarmauri_tool_sentencecomplexity is released under the Apache 2.0 License. See LICENSE for details.
Metadata
Release files for swarmauri_tool_sentencecomplexity 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_tool_sentencecomplexity-0.10.0.tar.gz | 8.2 kB | Without provenance | Details for swarmauri_tool_sentencecomplexity-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_tool_sentencecomplexity-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_tool_sentencecomplexity-0.10.0-py3-none-any.whl |
Total release size: 17.6 kB
Release files / swarmauri_tool_sentencecomplexity-0.10.0.tar.gz
| Download URL | swarmauri_tool_sentencecomplexity-0.10.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcdd26d89098d0449d05a398dda17baaf008d689e3ea9bfab69595e95f33fed0
|
|
BLAKE2b-256 checksum How to use checksums |
7ca8f362abb523ed91c7748fc3974e7d474db32b426497664de0f3e6f6401aa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_tool_sentencecomplexity-0.10.0-py3-none-any.whl
| Download URL | swarmauri_tool_sentencecomplexity-0.10.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
749acf7a10e515db0029a614aef5b1b2f919a632b4d3ab8efe0230d0823d056f
|
|
BLAKE2b-256 checksum How to use checksums |
83760220a78aa915a4620fe0d194930a85da60e661c39fbeb0b0dfc483f06aa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_tool_sentencecomplexity 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.