Connecting Tech Pros Worldwide Forums | Help | Site Map

Limiting no of sentences in a text area?

effendi@epitome.com.sg
Guest
 
Posts: n/a
#1: Jul 23 '05
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.


Randy Webb
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Limiting no of sentences in a text area?


effendi@epitome.com.sg wrote:[color=blue]
> 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.
>[/color]

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Lee
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Limiting no of sentences in a text area?


effendi@epitome.com.sg said:[color=blue]
>
>Hi can anyone tell me what is the best way to determine the number of
>sentences that someone enter into a text area?[/color]

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

effendi@epitome.com.sg
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Limiting no of sentences in a text area?


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.

Nate Pilkington
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Limiting no of sentences in a text area?


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.
<effendi@epitome.com.sg> wrote in message
news:1116095872.356774.125150@o13g2000cwo.googlegr oups.com...[color=blue]
> 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.
>[/color]


shlomi.schwartz@gmail.com
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Limiting no of sentences in a text area?


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

Randy Webb
Guest
 
Posts: n/a
#7: Jul 23 '05

re: Limiting no of sentences in a text area?


shlomi.schwartz@gmail.com wrote:[color=blue]
> 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);
> }
>[/color]

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
shlomi.schwartz@gmail.com
Guest
 
Posts: n/a
#8: Jul 23 '05

re: Limiting no of sentences in a text area?


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

Randy Webb
Guest
 
Posts: n/a
#9: Jul 23 '05

re: Limiting no of sentences in a text area?


shlomi.schwartz@gmail.com wrote:[color=blue]
> Maybe I missed something RaNdY.... what's your solution again?
>[/color]

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
shlomi.schwartz@gmail.com
Guest
 
Posts: n/a
#10: Jul 23 '05

re: Limiting no of sentences in a text area?



code Dude.... code

can you write somthing? or just "trash talk"

Lee
Guest
 
Posts: n/a
#11: Jul 23 '05

re: Limiting no of sentences in a text area?


shlomi.schwartz@gmail.com said:[color=blue]
>
>
>code Dude.... code
>
>can you write somthing? or just "trash talk"[/color]

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.

Randy Webb
Guest
 
Posts: n/a
#12: Jul 23 '05

re: Limiting no of sentences in a text area?


shlomi.schwartz@gmail.com wrote:[color=blue]
> code Dude.... code[/color]

Huh? Can you type intelligent sentences or have they failed to teach you
that in school?
[color=blue]
> can you write somthing?[/color]

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.

[color=blue]
> or just "trash talk"[/color]

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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
shlomi.schwartz@gmail.com
Guest
 
Posts: n/a
#13: Jul 23 '05

re: Limiting no of sentences in a text area?


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 effe...@epitome.com.sg :"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.

Closed Thread