Haiku Checker
テキストが伝統的な俳句の5-7-5シラブル構造に従っているかを確認し、行ごとに分析します。
俳句について
俳句は日本の伝統的な詩で、5-7-5 の音数パターンに従う3行の形式です。音数カウンターは英語の母音グループ法則を使用し、すべての単語で 100% 正確ではない場合があります。
このツールについて
俳句チェッカーは、あなたのテキストが伝統的な5-7-5音数の俳句の構造に従っているかどうかを検証するユーティリティツールです。俳句は数百年前から続く日本の古い詩形で、その簡潔さと優雅さで知られており、音数はその構造の基本要素です。このツールは各行を独立して分析し、音数を数えて詳細なフィードバックを提供するため、あなたの作品が古典的な形式にどの程度適合しているかを正確に確認できます。
俳句チェッカーを使用するには、3行の詩をインプットフィールドに貼り付けて、分析ボタンをクリックするだけです。ツールは各行の音数を表示し、5-7-5のパターンと合致しているかどうかを示します。これは俳句の創作を学んでいるライター、文学の授業で日本の詩を研究している学生、または他の人と共有する前に作品を磨きたい人にとって特に役立ちます。
よくある質問
コード実装
import re
def count_syllables(word: str) -> int:
"""Count syllables in an English word using vowel-group heuristic."""
word = word.lower().strip()
word = re.sub(r"[^a-z]", "", word)
if not word:
return 0
# Count vowel groups
count = len(re.findall(r"[aeiouy]+", word))
# Adjust for silent-e ending
if word.endswith("e") and count > 1:
count -= 1
return max(1, count)
def count_line_syllables(line: str) -> int:
words = re.findall(r"[a-zA-Z'-]+", line)
return sum(count_syllables(w) for w in words)
def check_haiku(text: str) -> dict:
lines = [l.strip() for l in text.strip().split("\n") if l.strip()]
if len(lines) != 3:
return {"valid": False, "error": f"Expected 3 lines, got {len(lines)}"}
counts = [count_line_syllables(line) for line in lines]
expected = [5, 7, 5]
valid = counts == expected
return {
"valid": valid,
"lines": [
{"text": lines[i], "syllables": counts[i], "expected": expected[i]}
for i in range(3)
],
}
haiku = """
An old silent pond
A frog jumps into the pond
Splash! Silence again
"""
result = check_haiku(haiku)
print(f"Valid haiku: {result['valid']}")
for line in result["lines"]:
status = "✓" if line["syllables"] == line["expected"] else "✗"
print(f" {status} {line['syllables']}/{line['expected']} syllables: {line['text']}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.