Skip to content
πŸ› οΈToolsShed

Haiku Checker

Check if your text follows the traditional haiku 5-7-5 syllable structure with per-line analysis.

About Haiku

A haiku is a form of Japanese poetry with three lines following a 5-7-5 syllable pattern. The syllable counter uses English vowel-group heuristics and may not be 100% accurate for all words.

About this tool

A haiku checker is a utility tool that validates whether your text follows the traditional 5-7-5 syllable structure of haiku poetry. Haiku is a centuries-old Japanese verse form known for its brevity and elegance, and the syllable count is fundamental to its structure. This tool analyzes each line independently, counting syllables and providing detailed feedback so you can see exactly where your composition meets or deviates from the classical format.

To use the haiku checker, simply paste your three-line poem into the input field and click the analyze button. The tool will display the syllable count for each line and indicate whether they match the 5-7-5 pattern. This is especially useful for writers learning haiku composition, students studying Japanese poetry in literature classes, or anyone refining their work before sharing it with others.

Frequently Asked Questions

Code Implementation

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.