Text-Statistics icon indicating copy to clipboard operation
Text-Statistics copied to clipboard

Sentence count suggestion

Open jrfnl opened this issue 11 years ago • 3 comments

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 ) );

jrfnl avatar Feb 27 '14 12:02 jrfnl

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.

DaveChild avatar Feb 27 '14 14:02 DaveChild

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 ;-)

jrfnl avatar Feb 27 '14 15:02 jrfnl

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.

DaveChild avatar Feb 28 '14 11:02 DaveChild