NLTK-powered Swarmauri text-analysis tool for counting characters, words, and sentences.
Project description
Swarmauri Tool Text Length
swarmauri_tool_textlength is a Swarmauri text-analysis tool that measures
characters, words, and sentences using NLTK tokenization. It is useful for
content QA, moderation gates, prompt-budget checks, readability workflows, and
agentic text analytics.
Why Use Swarmauri Tool Text Length
- Measure content size with a Swarmauri-native tool interface.
- Track character, word, and sentence counts from a single call.
- Add length checks to moderation, documentation, or editorial pipelines.
- Reuse the same tool in agents, notebooks, scripts, and backend workflows.
FAQ
What does the tool return?
A dictionary withnum_characters,num_words, andnum_sentences.
Are spaces included in the character count?
No. The current implementation excludes space characters.
What tokenizer does it use?
It uses NLTK sentence and word tokenizers and downloadspunkt_tabat import time if needed.
Is it English-specific?
The default tokenization behavior is best suited to English text unless you swap in different tokenization logic.
Features
- Swarmauri
ToolBaseimplementation registered asTextLengthTool. - Character, word, and sentence counts in one structured response.
- NLTK-based tokenization for more useful word and sentence splitting.
- Works well in content governance, prompt analytics, and editorial checks.
- Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.
Installation
uv add swarmauri_tool_textlength
pip install swarmauri_tool_textlength
Usage
from swarmauri_tool_textlength import TextLengthTool
tool = TextLengthTool()
metrics = tool("This is a simple test sentence.")
print(metrics)
Examples
Measure prompt length before model submission
from swarmauri_tool_textlength import TextLengthTool
tool = TextLengthTool()
metrics = tool("Summarize the following release notes for an executive audience.")
print(metrics["num_words"])
Check documentation size in a content pipeline
from pathlib import Path
from swarmauri_tool_textlength import TextLengthTool
tool = TextLengthTool()
for path in Path("docs").rglob("*.md"):
metrics = tool(path.read_text(encoding="utf-8"))
print(path, metrics)
Register the tool inside a Swarmauri tool registry
from swarmauri_standard.tools.ToolCollection import ToolCollection
from swarmauri_tool_textlength import TextLengthTool
tools = ToolCollection(tools=[TextLengthTool()])
print(tools)
Related Packages
- swarmauri_tool_searchword
- swarmauri_tool_lexicaldensity
- swarmauri_tool_sentencecomplexity
- swarmauri_tool_smogindex
- swarmauri_tool_dalechallreadability
Swarmauri Foundations
More Documentation
Best Practices
- Pre-download
punkt_tabfor offline or containerized deployments. - Treat counts as language-sensitive when processing non-English corpora.
- Pair text-length checks with readability tools when enforcing content style.
- If you need whitespace-inclusive counts, extend the character-count logic downstream.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_tool_textlength-0.11.0.dev1.tar.gz.
File metadata
- Download URL: swarmauri_tool_textlength-0.11.0.dev1.tar.gz
- Upload date:
- Size: 8.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47d445685da9604d7b012d4227a48c0f31b4336f1981269fab82a07b629ab279
|
|
| MD5 |
8a83c108e19a1384635cf6f12d37c891
|
|
| BLAKE2b-256 |
2e66b3c6fd1ef0e007e9e759ae7107aca4a441459abf0aca51ee01d0c92615ea
|
File details
Details for the file swarmauri_tool_textlength-0.11.0.dev1-py3-none-any.whl.
File metadata
- Download URL: swarmauri_tool_textlength-0.11.0.dev1-py3-none-any.whl
- Upload date:
- Size: 9.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9d3060f130bda327d47e6153314b6964ebef74ae71ff7cdfb56198c062ae7cc
|
|
| MD5 |
2d70f52f988a23cbc8e8feb0ac6c8228
|
|
| BLAKE2b-256 |
fea6007fabe10bd93e7611ff7b2d82dd95d377b5dad43596603edc972c0468ed
|