Skip to content

NVIDIA/SkillEvaluator / src/skillevaluator/tier3/reference_skills/text-analyzer

text-analyzer

Verified

Analyze text content and produce statistics including word count, line count, character count, sentence count, average word length, and most frequent words. Use when asked to analyze, count, or summarize a text or a text file (inline text or a file path such as input.txt), or when a request names text-analyzer.

FileKindSize
SKILL.mdskill md1.9 KB
evals/evals.jsonconfig1.2 KB
evals/evals2.jsonconfig4.5 KB
scripts/analyze_text.pyexecutablescript2.5 KB

scripts/analyze_text.py

View on GitHub
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Text Analyzer — produce word/line/char statistics for any text input."""

import argparse
import json
import re
import sys
from collections import Counter
from pathlib import Path


def analyze(text: str) -> dict:
    lines = text.splitlines()
    words = text.split()
    chars = len(text)
    word_count = len(words)
    line_count = len(lines)

    sentences = [s.strip() for s in re.split(r"[.!?]+", text) if s.strip()]
    sentence_count = len(sentences)

    avg_word_len = round(sum(len(w) for w in words) / max(word_count, 1), 2)

    tokens = (w.lower().strip(".,;:!?\"'()[]{}") for w in words)
    freq = Counter(t for t in tokens if any(ch.isalnum() for ch in t))
    top_words = freq.most_common(5)

    return {
        "word_count": word_count,
        "line_count": line_count,
        "character_count": chars,
        "sentence_count": sentence_count,
        "average_word_length": avg_word_len,
        "top_words": [{"word": w, "count": c} for w, c in top_words],
    }


def format_report(stats: dict) -> str:
    lines = [
        "=== Text Analysis Report ===",
        f"  Words:              {stats['word_count']}",
        f"  Lines:              {stats['line_count']}",
        f"  Characters:         {stats['character_count']}",
        f"  Sentences:          {stats['sentence_count']}",
        f"  Avg word length:    {stats['average_word_length']}",
        "",
        "  Top words:",
    ]
    for entry in stats["top_words"]:
        lines.append(f"    {entry['word']:<20s} {entry['count']}")
    lines.append("=" * 28)
    return "\n".join(lines)


def main():
    parser = argparse.ArgumentParser(description="Analyze text content")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--text", help="Inline text to analyze")
    group.add_argument("--file", help="Path to a text file to analyze")
    parser.add_argument("--json", action="store_true", help="Output as JSON")
    args = parser.parse_args()

    if args.file:
        path = Path(args.file)
        if not path.exists():
            print(f"Error: file not found: {args.file}", file=sys.stderr)
            sys.exit(1)
        text = path.read_text(encoding="utf-8", errors="replace")
    else:
        text = args.text

    stats = analyze(text)

    if args.json:
        print(json.dumps(stats, indent=2))
    else:
        print(format_report(stats))


if __name__ == "__main__":
    main()
add-product-e2e-evalpaperclipai/paperclipAdd or extend a Paperclip full-stack runner E2E workflow, fixture, matcher, or report evidence path for local or Daytona execution.Stars: 115kUpdated Claude CodeCodexVerifiedInstall
add-runner-evalpaperclipai/paperclipAdd or extend a Paperclip Runner protocol evaluation definition, roster, assertion, or report fixture with provenance and narrow validation.Stars: 115kUpdated Claude CodeCodexVerifiedInstall
diagnose-why-work-stoppedpaperclipai/paperclipCompatibility entry point for failed, stalled, looping, or over-recovered Paperclip work. Use fix-failed-paperclip-run for the full diagnosis, regression, repair, real verification, and green-PR workflow; honor an explicitly requested diagnosis-only scope.Stars: 115kUpdated Claude CodeCodexVerifiedInstall
fix-failed-paperclip-runpaperclipai/paperclipDiagnose and fix failed, stuck, slow, or incorrectly blocked Paperclip tasks and runs. Use with a task/run URL or failure report to trace the root cause, prove a regression red then green, check second-order effects, verify the real workflow, and deliver a PR with passing checks.Stars: 115kUpdated Claude CodeCodexVerifiedInstall