Detecting start of sentence.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2006
Posts: 7,626
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Detecting start of sentence.

 
0
  #11
Dec 12th, 2008
At least post your attempt in terms of indexOf and substring indicating the problem you are facing.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 53
Reputation: neilcoffey will become famous soon enough neilcoffey will become famous soon enough 
Solved Threads: 6
neilcoffey neilcoffey is offline Offline
Junior Poster in Training

Re: Detecting start of sentence.

 
0
  #12
Dec 12th, 2008
String.split() really can help you out, I think. If I understand rightly, the thing you're dissatisfied with is that the suggestion strips off the terminating punctuation from the strings. The expression's a bit more involved, but you can do something such as the following:

  1. String[] sentences = str.split("(?<=[\\.!?]+)(?![\\.!?]+) *");

See the documentation of Pattern to understand how this works. Although the expression's a bit nasty, this really is more succinct than tying yourself in knots with indexOf() and the like.

I leave it as an exercise to the reader to amend the expression to correctly split sentences such as "I asked Dr. Smith to come." :-)
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 52
Reputation: clueless101 is an unknown quantity at this point 
Solved Threads: 0
clueless101 clueless101 is offline Offline
Junior Poster in Training

Re: Detecting start of sentence.

 
0
  #13
Dec 13th, 2008
Thank you for your suggestion. Can you direct to me to a good source where I find out how to use this expression? I'd like to finish this and move on to another project involving a JSlider.

Again, thanks for taking the time!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Detecting start of sentence.

 
0
  #14
Dec 13th, 2008
Originally Posted by clueless101 View Post
Thank you for your suggestion. Can you direct to me to a good source where I find out how to use this expression? I'd like to finish this and move on to another project involving a JSlider.

Again, thanks for taking the time!
What he has used are called Regular Expressions and in my very first post, if you had cared to see properly, would have found the tutorial for them. But then here it is again:-

http://java.sun.com/docs/books/tutor...sential/regex/
Last edited by stephen84s; Dec 13th, 2008 at 1:49 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,626
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Detecting start of sentence.

 
0
  #15
Dec 13th, 2008
> String[] sentences = str.split("(?<=[\\.!?]+)(?![\\.!?]+) *");

Like previously mentioned, you don't need to escape regular expression meta characters inside bracketed character classes. Hence [.!?]+ to be used instead of [\\.!?]+ .
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC