• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Check wheather 3 strings located in a same sentence or not-Java

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am checking wheather 3 strings located in a same sentence or not.

For example the sentence Barack obama born on November 4 1960. In this sentence

MY idea is if there is no fullstop in between string1 & string2 and string2 and string3. Then i can believe that 3 strings located in a same sentence.

But sometimes the sentence is like Mr.smith and mrs.smith both born on April 2 1970.

If i just check for fullstop my idea fails here.Can someone suggest me is there any other way to check for 3 strings located in a same sentence or not?
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can your sentences end with other characters as well like '?', or '!' ?
You have to read your question carefully to deduce what makes up a sentence and what doesn't. Maybe your question simplifies matters by stating that each sentence is in its own line?
 
sarah sainy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is sentence in a HTML file.It does not end with any character.They end with tags

More Details:I have 3 strings with start and end indexes.So i read a particular HTML page where these 3 strings located.And check whether they are located in a same sentence or not.
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I must be missing something. Surely the simplest approach is just to replace full stops with spaces then use String.contains(). e.g.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is something else. The problem is that "Barack Obama was born on November 4 1960. Michael Smith is not related to him." should yield a "yes" for containing all 3 phrases in a single sentence, whereas that "Michael Smith was born on November 4 1960. Barack Obama is not related to him." should yield "no".

Sarah, is that the problem you're trying to solve?
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was missing something! It seems to me now that the OP first needs to break the String into sentences and then test each sentence in the manner I proposed. Of course a sentence does not need to end in a full stop !
 
sarah sainy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me give clarification.



I want to check whether 3 strings located in a valid sentence.
To make sure that the 3 strings located in a same sentence i am just checking for period or fullstop.If there is no full stop in between i am believing that it is same sentence

But the Problem is the sentence Mr.smith and mrs.smith both born on April 2 1970 is also a valid sentence.But my assumption fails.There is a fullstop in between.But the 3 strings are located in same sentence.

The solution is i have to use BreakIterator.getSentenceInstance(Locale.GERMANY) to get a sentence validated.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarah sainy wrote:The solution is i have to use BreakIterator.getSentenceInstance(Locale.GERMANY) to get a sentence validated.


Nice find. Can't believe I've never heard of that class before.
reply
    Bookmark Topic Watch Topic
  • New Topic