Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentence count suggestion #22

Open
jrfnl opened this issue Feb 27, 2014 · 3 comments
Open

Sentence count suggestion #22

jrfnl opened this issue Feb 27, 2014 · 3 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Feb 27, 2014

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
Copy link
Owner

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
Copy link
Contributor Author

jrfnl commented Feb 27, 2014

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
Copy link
Owner

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.

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

No branches or pull requests

2 participants