Measure Your Sentence Lengths With a Script You Can Run on Any Post, hostmy.blog

Measure Your Sentence Lengths With a Script You Can Run on Any Post

Updated

There is a measurable shape to the sentences in the Gemini sample, and most writing advice ignores it.

Daniel Shashko’s May 2026 analysis of 11,346 Gemini sentences found the mean extracted sentence ran 9.27 words. The median was 10. The 6 to 10 word band alone carried 45.2 percent of those sentences. The longest was 18 words in that sample.

Source: Daniel Shashko, Google Killed Text Fragments in AI Mode. Here Is What 153,425 Citations Say to Do About It., May 2026 (data and code on GitHub). Sentence-level figures come from the 11,346 Gemini citations that carry a text fragment. We did not collect this data. The study is self-published, not peer reviewed.

That last number is a property of one sample, not a rule. No sentence over 18 words appears in it, and it covers Gemini only. Our guide to short, single-claim sentences turns it into an editing habit, which is all we claim for it.

This post gives you a script that measures any page or draft against that distribution. It runs on stock Python 3.

What the script prints, against the citation record What the script prints, against the citation record Your post The benchmark Mean sentence length printed 9.27 words Longest sentence printed 18 words, longest Share in the 6 to 10 word band printed 45.2% Where cited sentences sit printed mean cited position: 37% of the page 11,346 cited Gemini sentences (Shashko, May 2026).
The script gives you four numbers. The right column is what those numbers are being compared against, so a result means something before you edit anything.

What the script measures, and what it deliberately does not

Four things, all mechanical.

Sentence count and word count per sentence. The share sitting in the 6 to 10 word band. The share running past 18 words. And the same two figures for the front 30 percent of the page. The 30 percent cut is my choice, not a number from the study. The study found the mean cited sentence 37 percent of the way down the page, with 74.9 percent of cited sentences in the first half.

What it does not do is judge your writing. A low band share on a technical reference page is fine. The script gives you a distribution, not a grade. Read it as a description of the shape of your prose, then decide whether that shape suits the page. Point it at your article pages, which is why the homepage is the wrong page to measure.

One more measured detail worth knowing before you start optimising for readability scores. Readability in that dataset was bimodal. Of 11,215 cited Gemini sentences, 22.9 percent scored very easy on Flesch Reading Ease, 20.5 percent scored very confusing, and only 2.6 percent sat in the 50 to 59 middle. The middle was the thinnest part of the distribution in that sample.

The script

Save this as quotable.py.

#!/usr/bin/env python3
"""Score how quotable a page is, by sentence length.

usage: python3 quotable.py https://example.com/post/
       python3 quotable.py draft.txt
       curl -sSL -H "Accept: text/markdown" URL | python3 quotable.py -
"""
import re, sys, urllib.request
from html.parser import HTMLParser

SHORT_LO, SHORT_HI, CEILING = 6, 10, 18
SKIP_TAGS = {"script", "style", "nav", "header", "footer", "aside", "noscript", "form"}
ABBREV = {"mr", "mrs", "ms", "dr", "prof", "sr", "jr", "st", "vs", "etc",
          "e.g", "i.e", "fig", "no", "inc", "ltd", "co", "approx"}

class TextGrab(HTMLParser):
    def __init__(self):
        super().__init__()
        self.parts, self.depth = [], 0
    def handle_starttag(self, tag, attrs):
        if tag.lower() in SKIP_TAGS:
            self.depth += 1
    def handle_endtag(self, tag):
        if tag.lower() in SKIP_TAGS and self.depth:
            self.depth -= 1
    def handle_data(self, data):
        if self.depth == 0 and data.strip():
            self.parts.append(data)
    def text(self):
        return re.sub(r"\s+", " ", " ".join(self.parts)).strip()

def load(src):
    if src == "-":
        html = sys.stdin.read()
    elif src.startswith(("http://", "https://")):
        req = urllib.request.Request(src, headers={
            "User-Agent": "Mozilla/5.0 (compatible; quotable/1.0)"})
        with urllib.request.urlopen(req, timeout=30) as r:
            raw = r.read()
            cs = r.headers.get_content_charset() or "utf-8"
        html = raw.decode(cs, "replace")
    else:
        with open(src, encoding="utf-8", errors="replace") as fh:
            html = fh.read()
    low = html.lower()
    if "" in low or "]{1,3}", "", md)
    return re.sub(r"\s+", " ", md).strip()

def sentences(text):
    out, buf = [], ""
    for chunk in re.split(r"(?<=[.!?])\s+", text):
        buf = (buf + " " + chunk).strip() if buf else chunk
        tail = buf.rstrip(".!?").split(" ")[-1].lower().strip("(),;:\"'")
        if tail in ABBREV or re.fullmatch(r"[a-z]", tail):
            continue                    # looks like an abbreviation, keep going
        out.append(buf)
        buf = ""
    if buf:
        out.append(buf)
    return [s for s in out if len(s.split()) >= 3]

def words(s):
    return len(re.findall(r"[A-Za-z0-9][A-Za-z0-9'/%.-]*", s))

def main(src):
    sents = sentences(load(src))
    if not sents:
        print("no sentences found in", src)
        return 2
    lens = [words(s) for s in sents]
    n = len(lens)
    short = sum(1 for L in lens if SHORT_LO <= L <= SHORT_HI)
    over = [i for i, L in enumerate(lens) if L > CEILING]
    front = max(1, int(n * 0.30))
    front_short = sum(1 for L in lens[:front] if SHORT_LO <= L <= SHORT_HI)

    print("source          %s" % src)
    print("sentences       %d" % n)
    print("mean words      %.2f" % (sum(lens) / n))
    print("median words    %d" % sorted(lens)[n // 2])
    print("in 6-10 band    %d  (%.1f%%)" % (short, 100 * short / n))
    print("over 18 words   %d  (%.1f%%)" % (len(over), 100 * len(over) / n))
    print("front 30%%       %d sentences, %d in band (%.1f%%)"
          % (front, front_short, 100 * front_short / front))

    if over:
        print("\nlongest sentences, shorten these first:")
        for i in sorted(over, key=lambda i: -lens[i])[:8]:
            s = sents[i]
            print("  %3d words  [pos %d/%d]  %s" % (
                lens[i], i + 1, n, s[:96] + ("..." if len(s) > 96 else "")))
    return 0

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print(__doc__)
        sys.exit(2)
    sys.exit(main(sys.argv[1]))

Running it three ways

Against a live URL:

python3 quotable.py https://yoursite.com/your-post/

Real output from a run against a live page, September 2026:

source          https://yoast.com/wordpress-seo/
sentences       604
mean words      17.38
median words    16
in 6-10 band    106  (17.5%)
over 18 words   228  (37.7%)
front 30%       181 sentences, 35 in band (19.3%)

Against a plain text draft, before you publish it:

python3 quotable.py draft.txt
source          draft.txt
sentences       5
mean words      10.80
median words    5
in 6-10 band    1  (20.0%)
over 18 words   1  (20.0%)
front 30%       1 sentences, 1 in band (100.0%)

longest sentences, shorten these first:
   36 words  [pos 3/5]  This one, by contrast, is a deliberately long sentence written to run well past the eighteen wor...

And piped from a Markdown endpoint, which gives a much cleaner read because the theme is not in the way:

curl -sSL -H "Accept: text/markdown" https://yoursite.com/your-post/ \
  | python3 quotable.py -

The -L is not optional there. Without it a redirect hands you an empty body and the script reports no sentences found.

Reading the numbers honestly

The URL mode measures whatever the theme renders, and themes add navigation, share links and footers. The script skips nav, header, footer and aside, which removes most of it, but not all. Sites that build navigation out of plain div elements will still leak menu text into the count.

That is why the pipe from a Markdown endpoint is the better measurement when it is available. Failing that, run it on the draft text before it ever touches a theme. The draft is the thing you can change anyway.

Watch the front 30% line specifically. A page can look healthy overall and still open with six consecutive long sentences. The study found 74.9 percent of cited sentences in the first half of the page, so the opening is the first place to look. To see which of your sentences were actually taken rather than which could be, Gemini’s text fragment readout is the only source available.

What to do with a bad result

The longest sentences list is the whole action item. Work down it.

Most sentences past 18 words are two sentences joined by a comma or an “and”. Splitting them costs nothing and usually improves the writing for humans too.

Resist the urge to chop everything to seven words. A page of uniformly short sentences reads like a ransom note, and the dataset shows a distribution, not a target. Aim for the claims to be short and self contained, and let the explanation around them run longer. The four rewrite moves that fix most long sentences repeat.

The other thing worth fixing is where the claim sits. Put the answer in the sentence, not two sentences after it. A sentence that reads “this is why it matters” is not extractable, because it carries no content on its own.

The structural half of the same problem

Sentence length is one half. Structure is the other, but the study does not measure heading order, so this part is practice, not a finding.

Few headings, in order, no skipped levels. The script that measures text-to-HTML ratio across your whole sitemap is in the HTML to text ratio check.

It is also worth knowing what this measure is not. Across all six platforms in the same study, only 23.05 percent of cited URLs ranked in the organic top 10 (Gemini 41.14 percent, ChatGPT 4.19 percent). Ranking and being quoted overlap only in part.

If you would rather not run scripts

Running this on a draft takes ten seconds and changes how you write the next one, which is the real point. Writing is one layer, and the four layers underneath it decide whether anything reaches a crawler at all.

If you want it as a check rather than a habit, RankReady is a WordPress plugin that handles the machine access work: Markdown endpoints, per-crawler robots.txt controls, and FAQ and Speakable schema. It does not score your sentences, so the script above stays the sentence check.

It runs alongside Rank Math, Yoast, AIOSEO and SEOPress. Those cover titles, meta and sitemaps; this covers whether a machine can reach and parse what you wrote. Setup takes about five minutes.

Be clear about the limit of the claim. Shorter, self contained sentences are easier to extract, and the plugin makes your pages reachable and parseable. Nobody can promise citations from that, and the honest version is more useful than the confident one. It is on WordPress.org. Sentences also go stale, which is a separate measurement covered in finding your stale posts.

Run it on the last thing you published. What percentage of your sentences ran past 18 words, and were the worst offenders in your opening third?