Skip to main content

NLTK-powered Swarmauri writing-analysis tool for estimating sentence length and clause complexity.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_tool_sentencecomplexity Discord

Swarmauri Tool Sentence Complexity

swarmauri_tool_sentencecomplexity is a Swarmauri NLP tool for estimating how complex a passage is by measuring average sentence length and average clauses per sentence. It is useful for editorial review, readability scoring, prompt inspection, educational feedback, and agent workflows that need quick writing complexity signals.

Why Use Swarmauri Tool Sentence Complexity

  • Quantify whether writing is becoming harder or easier to parse.
  • Detect long, clause-heavy sentences in documentation or prompts.
  • Add sentence-level style checks to agent or publishing workflows.
  • Pair structural complexity metrics with other readability measures.

FAQ

What does the tool return?
A dictionary with average_sentence_length and average_clauses_per_sentence.

How are clauses estimated?
The current heuristic uses punctuation and a list of common conjunctions.

What happens with empty input?
The tool raises ValueError if the input text is empty or whitespace only.

Does this replace full linguistic parsing?
No. It provides a lightweight heuristic, not a full syntactic analysis.

Features

  • Swarmauri ToolBase implementation registered as SentenceComplexityTool.
  • Calculates average sentence length in words.
  • Estimates average clause count per sentence using simple heuristics.
  • Useful for prompt QA, editorial review, and readability checks.
  • Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.

Installation

uv add swarmauri_tool_sentencecomplexity
pip install swarmauri_tool_sentencecomplexity

Usage

from swarmauri_tool_sentencecomplexity import SentenceComplexityTool

tool = SentenceComplexityTool()
metrics = tool("This is a simple sentence. This is another sentence, with a clause.")

print(metrics)

Examples

Flag overly complex prose

from swarmauri_tool_sentencecomplexity import SentenceComplexityTool

tool = SentenceComplexityTool()
metrics = tool("While the system scales across regions, it introduces queues, retries, and latency spikes.")

if metrics["average_sentence_length"] > 25:
    print("Sentence length is high.")

Compare two revisions of a document

from swarmauri_tool_sentencecomplexity import SentenceComplexityTool

tool = SentenceComplexityTool()

draft = "The system runs. It works."
final = "Although the system runs reliably, it requires careful coordination across services."

print("draft", tool(draft))
print("final", tool(final))

Register the tool in a Swarmauri collection

from swarmauri_standard.tools.ToolCollection import ToolCollection
from swarmauri_tool_sentencecomplexity import SentenceComplexityTool

tools = ToolCollection(tools=[SentenceComplexityTool()])
print(tools)

Related Packages

Swarmauri Foundations

More Documentation

Best Practices

  • Use this metric as a heuristic, not as a full grammar parser.
  • Compare results across texts of similar genre and purpose.
  • Pre-download NLTK tokenizer data in offline environments.
  • Pair sentence complexity with lexical density and readability scores for a broader text-quality view.

License

This project is licensed under the Apache-2.0 License.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_tool_sentencecomplexity-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_tool_sentencecomplexity-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}

File hashes

Hashes for swarmauri_tool_sentencecomplexity-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 4ee3c37961c613e8aa7a5a011de39b91b2619d65e977f19d5bd5726097d13432
MD5 7b07167425c3cb388d6a430654148edf
BLAKE2b-256 e5c3bf4b4753c871da662732cc61d43e7434eb056b7d72d587dbd131848d9c38

See more details on using hashes here.

File details

Details for the file swarmauri_tool_sentencecomplexity-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_tool_sentencecomplexity-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}

File hashes

Hashes for swarmauri_tool_sentencecomplexity-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ae56d21999fe9c7c30018f41a68b0ed171936facca981a9bc829b1dedf8b9a1
MD5 69da436937aae455b948aa57e8679822
BLAKE2b-256 f604dddc01b9e94ef6e3993629aaefff41a15743cbe995072aaf21eefe203e36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page