DaveChild / Text-Statistics

Generate information about text including syllable counts and Flesch-Kincaid, Gunning-Fog, Coleman-Liau, SMOG and Automated Readability scores.
https://readable.com/
BSD 2-Clause "Simplified" License
446 stars 107 forks source link

Sentence count suggestion #22

Open jrfnl opened 10 years ago

jrfnl commented 10 years ago

In the inline code comments you already note:

// Will be tripped up by "Mr." or "U.K.". Not a major concern at this point.

I found it is also tripped up by ... or ?!

Just wanted to show you the below suggestion for consideration as it will at least provide better count in ... and ?! situations:

$intSentences = max( 1, preg_match_all( '`[^\.!?]+[\.!?]+([\s]+|$)`u', $strText, $matches ) );
DaveChild commented 10 years ago

I've got something similar in the code for readability-score that I've been meaning to move over. This looks pretty similar, I think. I was having all sorts of trouble with HTML pages where I was forcing block-level elements to end sentences, so ending up with multiple terminators over multiple lines, but they were all ending the same sentence.

jrfnl commented 10 years ago

If you have a number of example sentences and such, I'd be quite willing to have a look at figuring out some smart regexes ;-)

DaveChild commented 10 years ago

I've pushed the latest version of the text cleaning method, which handles sentences better.

I don't have many good examples of tricky text, but will see if I can produce one from an HTML doc. The worst ones tend to end up with something like this, frequently (block elements replaced with periods, heading tend not to have sentence terminators):

Welcome

This is a list item...
. . . .

.

.. .And another
item..

After cleanup, that should look something like this:

Welcome. This is a list item. And another item.