Limiting no of sentences in a text area?

E

effendi

Hi can anyone tell me what is the best way to determine the number of
sentences that someone enter into a text area?

Thanks in advanced.
 
L

Lee

(e-mail address removed) said:
Hi can anyone tell me what is the best way to determine the number of
sentences that someone enter into a text area?

That depends on how you define a sentence, doesn't it???

Some might say to count "." characters, but that can throw you
off by a few ... maybe a lot!!

And, of course, you can't count on people to use punctuation
consistently
 
R

Randy Webb

Hi can anyone tell me what is the best way to determine the number of
sentences that someone enter into a text area?

Thanks in advanced.

You determine what ends a sentence and then you check for that character
sequence, and you hope that someone does not put one in the middle of a
sentence lest you get incorrect results as a Dr. would not end a
sentence but it would appear to be since a .<space> might be a good
indicator of a sentence ending, but then, how would you propose to deal
with run-on sentences such as the one I just typed that is extremely
long but has no technical sentence ending punctuation in it although any
attempt to determine a sentence end would (or should) find them.

!?. followed by a space. Good job for a RegEx except for the inherent
flaw in the approach.
 
E

effendi

Randy

Thanks for the suggestion,. Its not a perfect check I guess but some
would be necessary as a baseline. I already have in place check for
"returns" but how do i do a regular expression checking for "1?.".Lets
say 5 times?

Thanks again.
 
N

Nate Pilkington

Count the words. If there are an average of 25 words (or something) in a
sentence, you would divide the number of words in the sentence by 25, and
you have your number of sentences. Might work, might not.
 
S

shlomi.schwartz

try this:

function countSentence(){
var str = "this is the first sentance, i'm sure. is this the second
one? yes!";
alert("Number of sentences = "+str.match(/[?!.]/g).length);
}
 
R

Randy Webb

try this:

function countSentence(){
var str = "this is the first sentance, i'm sure. is this the second
one? yes!";
alert("Number of sentences = "+str.match(/[?!.]/g).length);
}

Then, try reading the FAQ with regards to posting here.
Then, try this one:

var str = "The possible sentence ending punctuation marks" +
"are ? ! and . but not necessarily in that order.";
alert("Number of sentences = "+str.match(/[?!.]/g).length);

Which incorrectly gives 4 when there is only one sentence.

A good scripter does not look for a short answer to an immediate
question, s/he also looks for the potential shortfalls of that solution.
 
R

Randy Webb

Maybe I missed something RaNdY.... what's your solution again?

Learn to read, grow some brains, do a little research, and you will find
my answer to the question. I am sure you can manage it.
 
L

Lee

(e-mail address removed) said:
code Dude.... code

can you write somthing? or just "trash talk"

Please read the FAQ and learn to post.
Then you'll want to consider whether posting useless code
is better or worse than posting an explanation of why it's
not really possible to code a good solution.
 
R

Randy Webb

code Dude.... code

Huh? Can you type intelligent sentences or have they failed to teach you
that in school?
can you write somthing?

Yep, sure can. I can even spell it properly - something.

As for code that solves the original question, no. Because NOBODY can
write code that will *reliably* do what was asked. If you had bothered
to read my first reply to this thread - and comprehended it - you would
realize that. But, just for clarity, let me explain it to you once again.

The problem is not in "counting sentences" as that is nothing more than
counting occurences of punctuation. There are several ways to do that,
but they all have problems.

Step 1: What defines the "end of a sentence"? Typically an occurence of
.. ? or ! signifies the end of a sentence.

So, lets count the occurences of . ? or ! within a string of text. As
the RegExp you gave does that:

str.match(/[?!.]/g).length)

The problem is not counting them, its differentiating them from other
forms of use of those punctuation marks. Consider the following sentence:

"The Dr. went to Mr. and Mrs. Jones' house."

Now, how many sentences is that? Its one. But the pattern you gave gives
4. Thats a flaw. The only way around that flaw is to create a list of
all possible abbreviations and either remove them prior to matching, or,
replace them with the non-abbreviated word. It would also be a better
test to check for one of the marks followed by a space.

It is that very flaw that you cannot - reasonably - get around that
prevents one from being able to *reliably* count sentences.

or just "trash talk"

I can do both, you decide which we shall do.
 
S

shlomi.schwartz

Dear Randy and Lee.

If we all cool down for just a second, maybe we could understand why
this thread is so long and not very helpful.

1) my first reply was not a solution for the question. it was just a
starting point for the solution you suggested.
2) I replied (e-mail address removed) :"how do I do a regular expression
checking for "1?.""

Why did you had to write "A good scripter does not look for a short
answer to an immediate
question, s/he also looks for the potential shortfalls of that
solution." ?

I just tried to help. Sometimes it is good to have a starting point in
order to get something done.

so .... relax, have a great day and think positive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top