Word Letter Frequency
Quick start
- 1. Identify the input text (typically one word or a short phrase). Default behavior lowercases the text and ignores non-letters so repeated letters like
a/A are merged. - Run
scripts/count_letters.py "<text>" to get a frequency table. Use the optional flags when needed:
-
--case-sensitive keeps uppercase and lowercase separate.
-
--include-non-alpha counts digits/punctuation as-is.
-
--json returns machine-friendly JSON for downstream processing.
- 3. Summarize the counts for the user. Include clarifying notes (e.g., whether you ignored punctuation) when relevant.
Script reference
scripts/count_letters.py
Lightweight CLI/utility that powers this skill. It exposes two layers:
- - CLI usage: INLINECODE6
- Import usage:
from scripts.count_letters import count_letters and call count_letters(text, case_sensitive=False, include_non_alpha=False) to get a collections.Counter.
Sample CLI output (default options):
CODEBLOCK0
Sample JSON output (good for embedding directly into responses):
CODEBLOCK1
Response patterns
- - Concise summary: “
balloon contains b×1, a×1, l×2, o×2, n×1 (case-insensitive, punctuation ignored).” - Tabular snippet: Mirror the script’s table for readability. Mention any options you used.
- JSON / dict: When the user wants structured data, reuse the script’s
--json flag.
Edge cases & tips
- - Make sure to state how you treated uppercase letters and punctuation, especially when the counts differ depending on options.
- If the input contains no alphabetic characters and
--include-non-alpha is not set, the script intentionally reports “(no characters were counted)”. Explain why in the response. - For multiple words, either run the script once on the full phrase (default) or note that the skill focuses on short strings; if the request expands to full documents, escalate to a general text-analysis workflow instead.
单词字母频率
快速入门
- 1. 识别输入文本(通常为一个单词或短句)。默认行为会将文本转换为小写并忽略非字母字符,因此像a/A这样的重复字母会被合并。
- 运行scripts/count_letters.py <文本>获取频率表。需要时可使用可选标志:
- --case-sensitive 区分大小写。
- --include-non-alpha 按原样统计数字/标点符号。
- --json 返回机器可读的JSON格式,便于后续处理。
- 3. 向用户汇总统计结果。必要时添加说明性注释(例如是否忽略了标点符号)。
脚本参考
scripts/count_letters.py
支撑此技能的轻量级CLI/工具。它提供两个层级:
- - CLI使用方式:python3 scripts/countletters.py balloon --json
- 导入使用方式:from scripts.countletters import countletters 并调用countletters(text, casesensitive=False, includenon_alpha=False)获取collections.Counter对象。
CLI输出示例(默认选项):
$ python3 scripts/count_letters.py balloon
字符 计数
---- ----
a 1
b 1
l 2
o 2
n 1
JSON输出示例(适合直接嵌入响应):
$ python3 scripts/count_letters.py AaB! --case-sensitive --include-non-alpha --json
{A: 1, a: 1, B: 1, !: 1}
响应模式
- - 简洁摘要:balloon包含b×1, a×1, l×2, o×2, n×1(不区分大小写,忽略标点符号)。
- 表格片段:镜像脚本的表格以提高可读性。注明使用的任何选项。
- JSON/字典:当用户需要结构化数据时,复用脚本的--json标志。
边界情况与提示
- - 务必说明如何处理大写字母和标点符号,尤其是在不同选项下统计结果不同时。
- 如果输入不包含字母字符且未设置--include-non-alpha,脚本会明确报告(未统计任何字符)。在响应中解释原因。
- 对于多个单词,要么对整个短语运行一次脚本(默认方式),要么说明该技能专注于短字符串;如果请求扩展到完整文档,应升级到通用文本分析工作流程。