File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Check wheather 3 strings located in a same sentence or not-Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Check wheather 3 strings located in a same sentence or not-Java" Watch "Check wheather 3 strings located in a same sentence or not-Java" New topic
Author

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

sarah sainy
Greenhorn

Joined: Oct 18, 2013
Posts: 23

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?
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Oct 18, 2013
Posts: 23
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.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1053
    
  10

I must be missing something. Surely the simplest approach is just to replace full stops with spaces then use String.contains(). e.g.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41823
    
  63
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?


Ping & DNS - my free Android networking tools app
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1053
    
  10

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

Joined: Oct 18, 2013
Posts: 23
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.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
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.
 
 
subject: Check wheather 3 strings located in a same sentence or not-Java