473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

retieving a sentence containing a particular phrase

12
hi
i want a program by which we can retrieve a sentence containing a a particular phrase in java.suppose we want to get the sentence out of the entire document that contains the phrase"as a result".how is it possible?plzz help me
Apr 5 '08 #1
10 2664
sukatoa
539 512MB
hi
i want a program by which we can retrieve a sentence containing a a particular phrase in java.suppose we want to get the sentence out of the entire document that contains the phrase"as a result".how is it possible?plzz help me
document like what? .doc file?

Could you also post the document?

Sorry, i couldn't get what you mean.....

sukatoa....
Apr 5 '08 #2
Laharl
849 Expert 512MB
He's got a file, presumably a bunch of sentences, so it's a text file. He wants a sentence that contains a given phrase, so...Open up the file, locate the phrase using a substring, and then go forward and back, using punctuation (!, ?, .) as the delimiting characters of your search.
Apr 5 '08 #3
litun
12
document like what? .doc file?

Could you also post the document?

Sorry, i couldn't get what you mean.....

sukatoa....
Suppose the document is a text document like this one:
The Indian industry and investment bankers gave a thumbs up to the Union Budget, saying Finance Minister P Chidambaram has done a "fantastic" job. "Budget is on the expected lines and the industry has not been penalised although we are disappointed that the corporate tax has not been changed," apex industry body CII's President Sunil Mittal said. "Corporate tax are at fair levels. An increase of five per cent on short-term capital gains will make people hold for medium term," Kotak Mahidra Bank Managing Director Uday Kotak said. As a result of this,there seems to be a rise in prices on all items. It becomes for a common man to make both ends meet.
then how can we get da sentence "As a result of this,there seems to be a rise in prices on all items. "As a reult may aslo be in the middle of the sentence and in that case also we ahve to retrieve that particular sentence.plzz heelp me
Apr 5 '08 #4
sukatoa
539 512MB
Ok.....

It is possible... You can use the Matcher and Pattern class....
Those class could point you to the exact nth number of the character on that string you want to have...

Or you could just manipulate it using arrays of character.....
Maybe there is a nice implementation than this....

nth number is your starting point. By having a loop until the end ( The limit of your choice ), you can copy it... and convert it in String again....

Only by having a copy of that nth number, and the last nth number... you can Convert it first into arrays of character... copy those elements from starting point to the end point ( nth numbers ) in a temp char array... and then convert it to String again....

Expand|Select|Wrap|Line Numbers
  1. The baby starts to smoke. As a result, his father jumped twice a day....  
you may want to cut the string "As the result, his father jumped twice a day".

Just have the nth number of 'A' in As and the 'y' in day.... ( nth element )....


correct me if im wrong,
sukatoa
Apr 5 '08 #5
litun
12
Ok.....

It is possible... You can use the Matcher and Pattern class....
Those class could point you to the exact nth number of the character on that string you want to have...

Or you could just manipulate it using arrays of character.....
Maybe there is a nice implementation than this....

nth number is your starting point. By having a loop until the end ( The limit of your choice ), you can copy it... and convert it in String again....

Only by having a copy of that nth number, and the last nth number... you can Convert it first into arrays of character... copy those elements from starting point to the end point ( nth numbers ) in a temp char array... and then convert it to String again....

Expand|Select|Wrap|Line Numbers
  1. The baby starts to smoke. As a result, his father jumped twice a day....  
you may want to cut the string "As the result, his father jumped twice a day".

Just have the nth number of 'A' in As and the 'y' in day.... ( nth element )....


correct me if im wrong,
sukatoa
thanks but i didn't get u.can u write da code for it.
Apr 5 '08 #6
sukatoa
539 512MB
thanks but i didn't get u.can u write da code for it.
I can't... it is restricted on this forum....

Just make some experiments on it, ask some questions about what you have done (your codes) and our experts here will help you out....
Apr 5 '08 #7
hsn
237 100+
m8 it is simple
you have the following text file

i went to the university today

you want to cut the word university
do the steps
1. find the position of u fro the word university.
2. by a loop start from the begining of the file and go until you reach the position of u for university. while u are in the loop every char you read add it to a string (for example str).
3. you know the size of the text that you need to remove. which here is 10 chars. the position of u for university is 14. 10+14=24.
4. start step 2 again but start from 24 not from 0.
5. then you will have your text. in a string
6. write that string in a text file and you will be happy.

good luck

hsn
Apr 5 '08 #8
JosAH
11,448 Expert 8TB
Why not simply read the file character by character until you've read a punctuation
character; store all of them in a StringBuilder. After you've read the punctuation
character you've read an entire sentence and perform your logic on it. Rinse and
repeat until the end of file condition is met. A simple 'indexOf()' method call can
find any phrase in the sentence.

kind regards,

Jos
Apr 5 '08 #9
litun
12
m8 it is simple
you have the following text file

i went to the university today

you want to cut the word university
do the steps
1. find the position of u fro the word university.
2. by a loop start from the begining of the file and go until you reach the position of u for university. while u are in the loop every char you read add it to a string (for example str).
3. you know the size of the text that you need to remove. which here is 10 chars. the position of u for university is 14. 10+14=24.
4. start step 2 again but start from 24 not from 0.
5. then you will have your text. in a string
6. write that string in a text file and you will be happy.

good luck

hsn
thanks a lot.it really works
Apr 6 '08 #10
litun
12
Why not simply read the file character by character until you've read a punctuation
character; store all of them in a StringBuilder. After you've read the punctuation
character you've read an entire sentence and perform your logic on it. Rinse and
repeat until the end of file condition is met. A simple 'indexOf()' method call can
find any phrase in the sentence.

kind regards,

Jos
thanks i did da program as u had said.it really works
thanks again
Apr 6 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ash | last post by:
I want search phrase in html file and mark (like Google when I click on "cached") it (phrase). Does somebody know any class, that can help me? Maybe somebody know how could I make this? thanks
0
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match...
6
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph...
3
by: dalearyous | last post by:
ok basically i need to write a program that will replace normal words in a sentence with pirate words. the trick is it needs to be able to take two word phrases. i went about this two different ways:...
2
by: cptuser | last post by:
Hi, I'm a novice and I have the following code, but I can't get it to work. All i want to be able to do is a simple form validation for a single field, so that if the user enters a particular...
11
by: John A Grandy | last post by:
I'm in a vigorous debate at my work regarding objects assuming knowledge of the type their containing object. This debate pertains specifically to ASP.NET, but I have decided to post in the C#...
12
by: Archanak | last post by:
Hi, I have a word like this: "Rna binding proteins" and i want to match this exact phrase. I have written code like this: $sentence="Overall, the participation of additional RNA binding...
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
1
by: chromis | last post by:
Hi, I've been trying to create a carousel class which takes an array of phrases and then creates a textfield for each one positioning it vertically based on the order it was added. The next stage...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.