Skip to main content

NLTK-powered Swarmauri NLP tool for measuring lexical density across prompts, documents, and corpora.

Project description

Swarmauri Logo

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

Swarmauri Tool Lexical Density

swarmauri_tool_lexicaldensity is a Swarmauri NLP tool for estimating lexical density, the ratio of content words to total word count. It helps quantify how information-dense a passage is, which makes it useful for readability reviews, editorial QA, prompt analysis, educational tools, and agent-based writing assistance.

Why Use Swarmauri Tool Lexical Density

  • Measure how content-heavy or function-word-heavy a text is.
  • Compare drafts, prompts, or knowledge articles with a simple numeric signal.
  • Feed lexical-density metrics into Swarmauri quality or moderation workflows.
  • Pair lexical density with readability metrics for more complete text review.

FAQ

What does lexical density measure?
It estimates the percentage of content words such as nouns, verbs, adjectives, and adverbs relative to all words in the text.

What does the tool return?
A dictionary with one key: lexical_density.

Does it rely on NLTK models?
Yes. It uses NLTK tokenization and POS tagging resources.

Is it best suited for English text?
Yes. The current POS-tagging setup is English-oriented.

Features

  • Swarmauri ToolBase implementation registered as LexicalDensityTool.
  • Computes lexical density as a percentage value.
  • Uses NLTK POS tagging to isolate content words.
  • Useful for editorial, educational, prompt, and corpus-analysis workflows.
  • Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.

Installation

uv add swarmauri_tool_lexicaldensity
pip install swarmauri_tool_lexicaldensity

Usage

from swarmauri_tool_lexicaldensity import LexicalDensityTool

tool = LexicalDensityTool()
result = tool("This report summarizes quarterly revenue growth across segments.")

print(result["lexical_density"])

Examples

Compare lexical density across drafts

from swarmauri_tool_lexicaldensity import LexicalDensityTool

tool = LexicalDensityTool()

for label, text in {
    "draft": "We made a thing and it does stuff for users.",
    "final": "The platform automates retrieval, classification, and policy enforcement.",
}.items():
    print(label, tool(text))

Score a prompt before sending it to an LLM

from swarmauri_tool_lexicaldensity import LexicalDensityTool

tool = LexicalDensityTool()
metrics = tool("Summarize operational risks, mitigation plans, and release dependencies.")

print(metrics)

Register the tool in a Swarmauri collection

from swarmauri_standard.tools.ToolCollection import ToolCollection
from swarmauri_tool_lexicaldensity import LexicalDensityTool

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

Related Packages

Swarmauri Foundations

More Documentation

Best Practices

  • Pre-download NLTK models in offline or containerized deployments.
  • Compare lexical-density values across similar content types, not unrelated genres.
  • Use lexical density alongside readability scores rather than as a sole quality metric.
  • Expect shorter texts to produce noisier percentages.

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

swarmauri_tool_lexicaldensity-0.11.0.dev1.tar.gz (8.5 kB view details)

Uploaded Source

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_lexicaldensity-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_tool_lexicaldensity-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 8.5 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_lexicaldensity-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 e4f7f4d27169c5b64738090eb930f86e57013d6864b26dfffc2cd0e6ee049eb8
MD5 2f0975f0b1c6fc91b082186bf21795b2
BLAKE2b-256 0c9d9a6a128bcbfc4ef70c9b8b9a0842db1c34490347489a079fa3c1d493be03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_tool_lexicaldensity-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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_lexicaldensity-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 72754c7a437dc0c3b464650c2fd59cc484d789e29e17ab581b61b1b4ec06db78
MD5 0d889e4084ccacc9550cd609d3c3cadf
BLAKE2b-256 791107c08eb5b0df02a6fa2f16bfcdbda9afef25fb05ddae64817514615860c8

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