Skip to content

Fix paragraphs and full width spaces#17

Open
Zarxrax wants to merge 3 commits into
joshdavham:mainfrom
Zarxrax:fix_paragraphs
Open

Fix paragraphs and full width spaces#17
Zarxrax wants to merge 3 commits into
joshdavham:mainfrom
Zarxrax:fix_paragraphs

Conversation

@Zarxrax
Copy link
Copy Markdown

@Zarxrax Zarxrax commented May 12, 2026

This PR makes 2 changes which both bring the scores more in line with the official web implementation at https://jreadability.net/sys/en for certain types of content.

First, this better handles paragraphs/line breaks by splitting sentences whenever there are 2 or more line breaks. (for example, an html <p> tag will end a sentence, but a single <br> tag will not. )
In some types of text, its common to omit punctuation at the end of a sentence, which would cause sentences to appear much longer than they actually were, which in turn made the difficulty score much higher than it should be.

The second change is that full width spaces are stripped. (this has to be done both in the main doc, and within the split_japanese_sentences function)

This change makes the token count more closely match the token count on jreadability.net, and brings the score slightly closer to that score as well.

Here are the before and after results on the texts in test_jreadability.py
The line splitting does not effect any of these, though the full width space removal changes the first one.

upper_advanced_text - Original: 1.0664359061543713
upper_advanced_text - New: 1.0129233407648766
lower_advanced_text - Original: 2.3329023569023573
lower_advanced_text - New: 2.3329023569023573
upper_intermediate_text - Original: 3.0853157894736842
upper_intermediate_text - New: 3.0853157894736842
lower_intermediate_text - Original: 4.161580021715526
lower_intermediate_text - New: 4.161580021715526
upper_elementary_text - Original: 4.861306967984935
upper_elementary_text - New: 4.861306967984935
lower_elementary_text - Original: 5.613666666666667
lower_elementary_text - New: 5.613666666666667

Closes #16

@joshdavham
Copy link
Copy Markdown
Owner

@Zarxrax

Thanks for this PR! I’ll look into it this weekend (really busy this week)

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshdavham
Copy link
Copy Markdown
Owner

Hey apologies I haven't quite had time to look at this yet. I'll take a look and hopefully get this merged as soon as I have time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large difference in score from official site

2 participants