# Text Metrics (counts, readability, frequency, warnings) (`draeg82/text-metrics-probe`) Actor

Deterministic text quality metrics: word/sentence counts, Flesch readability, top-N word frequency, and style warnings. Pure local computation, no external APIs, no secrets.

- **URL**: https://apify.com/draeg82/text-metrics-probe.md
- **Developed by:** [Andy Mitchell](https://apify.com/draeg82) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Text Metrics

**Deterministic text quality metrics — counts, readability, word frequency, and style warnings. Pure local computation: no external APIs, no scraping, no secrets, no proxy usage.**

Run any text through and get reproducible, machine-readable quality signals — useful for content QA pipelines, LLM output validation, and editorial tooling.

### Why this Actor

Most text-quality tools are either opaque (LLM-scored, non-reproducible) or scattered across a dozen npm packages. This Actor wraps one deterministic metrics engine: the same input always produces the same output, byte for byte. Zero network calls inside the run, so results are fast (~1s), cheap, and auditable.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `tool` | string | `analyze-text` | One of: `analyze-text` (everything), `count-text`, `word-frequency`, `readability`, `text-warnings` |
| `text` | string | — | **Required.** The text to analyze |
| `top_n` | number | `20` | How many top tokens to return in frequency analysis |
| `include_stopwords` | boolean | `false` | Whether frequency analysis includes common stopwords |

### Output

Each run pushes one dataset record (and stores the same object under the `OUTPUT` key-value record):

- **`counts`** — characters, words, unique words, sentences, paragraphs, lines, bullet items, headings, average words per sentence/paragraph.
- **`frequency`** — total/unique tokens and a top-N list of `{token, count, share}`.
- **`readability`** — Flesch Reading Ease and Flesch–Kincaid grade level, average sentence length, syllable stats. *(Heuristic English syllable counting: directional, not authoritative.)*
- **`warnings`** — style/quality flags with `code`, `severity` (`caution`/`warning`) and a human-readable `message` (e.g. `short_text`, `passive_voice`, `repetition`).

### Example

Input:

```json
{ "tool": "analyze-text", "text": "The quick brown fox jumps over the lazy dog. It was a very nice day." }
```

Output (abridged):

```json
{
  "metric": "aggregate",
  "counts": { "words": 21, "sentences": 2, "average_words_per_sentence": 10.5 },
  "readability": { "flesch_reading_ease": 67.26, "flesch_kincaid_grade": 6.49 },
  "warnings": [{ "code": "short_text", "severity": "caution", "message": "Readability and frequency metrics are unstable below about 100 words." }]
}
```

### Pricing (pay-per-event)

- `$0.005` per run start + `$0.01` per completed analysis. A typical single-text analysis costs ~$0.015.
- Free-plan users can run it within their free usage allowance.

### Notes & limits

- English-optimised (Flesch formulas, stopword list, syllable heuristic).
- Deterministic by design: no randomness, no network, no model inference.
- Memory capped at 256 MB; typical run ≈1 second.

### Integration

Works with the Apify API, `apify run-actor`, and MCP-based agent toolchains — the Actor exposes an output schema so agents can discover and chain results programmatically.

# Actor input Schema

## `tool` (type: `string`):

Which metric tool to run.

## `text` (type: `string`):

Text to measure.

## `top_n` (type: `integer`):

Number of top tokens to return.

## `include_stopwords` (type: `boolean`):

Whether frequency counts include common stopwords.

## Actor input object example

```json
{
  "tool": "analyze-text",
  "text": "The quick brown fox jumps over the lazy dog. Sample text for automated quality checks — replace with your own.",
  "top_n": 20,
  "include_stopwords": false
}
```

# Actor output Schema

## `dataset` (type: `string`):

One record per analyzed text: metric kind, counts (characters, words, sentences, paragraphs, lines, bullets, headings, averages), frequency (top-N tokens with count and share), readability (Flesch reading ease, Flesch-Kincaid grade, syllable stats), warnings (code, severity, message).

## `output` (type: `string`):

The full metrics result object stored under the OUTPUT key in the run's default key-value store.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "text": "The quick brown fox jumps over the lazy dog. Sample text for automated quality checks — replace with your own."
};

// Run the Actor and wait for it to finish
const run = await client.actor("draeg82/text-metrics-probe").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "text": "The quick brown fox jumps over the lazy dog. Sample text for automated quality checks — replace with your own." }

# Run the Actor and wait for it to finish
run = client.actor("draeg82/text-metrics-probe").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "text": "The quick brown fox jumps over the lazy dog. Sample text for automated quality checks — replace with your own."
}' |
apify call draeg82/text-metrics-probe --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,draeg82/text-metrics-probe"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/S0DAR6t9ypXemeh5T/builds/8AdVoFwx5h8vBjW55/openapi.json
