Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions assayer/scorer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from assayer.models import ModelResult
import re

_model = None

Expand Down Expand Up @@ -40,11 +41,7 @@ def compute_similarity(results: list[ModelResult]) -> dict[tuple[str, str], floa


def readability_stats(text: str) -> dict[str, float]:
sentences = [
s
for s in text.replace("!", ".").replace("?", ".").split(".")
if s.strip()
]
sentences = [s for s in re.split(r"[.!?]+(?:\s|$)", text) if s.strip()]
words = text.split()
word_count = len(words)
sentence_count = len(sentences) or 1
Expand Down
18 changes: 18 additions & 0 deletions tests/test_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,21 @@ def test_readability_stats_empty():
assert stats["word_count"] == 0
assert stats["sentence_count"] == 1
assert stats["avg_sentence_length"] == 0.0


def test_readability_stats_abbreviations():
stats = readability_stats("Dr. Smith scored 3.5. Well done.")
assert stats["word_count"] == 6
assert stats["sentence_count"] == 2


def test_readability_stats_urls():
stats = readability_stats("Visit example.com for details.")
assert stats["word_count"] == 4
assert stats["sentence_count"] == 1


def test_readability_stats_exclamations():
stats = readability_stats("The price is $3.99. Cheap!")
assert stats["word_count"] == 5
assert stats["sentence_count"] == 2
Loading