単語頻度カウンター
テキストを分析し、各単語の出現頻度を順位付きで表示します。
単語頻度カウンターはテキストブロックを分析し、各単語が最も多いものから最も少ないものの順にランク付けして表示します。文書の語彙分布を理解したり、過度に使われた単語を特定したり、専門ソフトウェアなしで基本的なテキスト分析を行いたい作家、編集者、学生、データアナリストに役立つツールです。
テキストを貼り付けると、ツールが個々の単語にトークン化し、大文字小文字を正規化して("The"、"the"、"THE"は同じ単語としてカウント)、頻度表を表示します。一般的なストップワードをフィルタリングして、意味のある内容語に集中することができます。
単語頻度分析は文章作成を超えた応用があります:言語学では読みやすさのスコアの基礎となり、マーケティングでは顧客が最もよく使う用語を明らかにし、SEOではコンテンツの自然なキーワード密度を特定するのに役立ちます。
よくある質問
コード実装
from collections import Counter
import re
STOP_WORDS = {
"a", "an", "the", "and", "or", "but", "in", "on", "at", "to",
"for", "of", "with", "by", "from", "is", "are", "was", "were",
"it", "this", "that", "be", "as", "not", "i", "you", "he", "she",
}
def word_frequency(text: str, stop_words: bool = True, top_n: int = 10) -> list[tuple[str, int]]:
# Lowercase and extract words
words = re.findall(r"[a-z']+", text.lower())
if stop_words:
words = [w for w in words if w not in STOP_WORDS]
counter = Counter(words)
return counter.most_common(top_n)
text = """To be or not to be, that is the question.
Whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune."""
for word, count in word_frequency(text):
print(f"{word:<20} {count}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.