| | |
extracting a sentence
![]() |
•
•
Join Date: Jan 2009
Posts: 7
Reputation:
Solved Threads: 0
Hello everybody,
I have a paragraph containing many sentences and I need to extract a certain sentence, which contains a certain. I have no problem finding the word with my code but my question is, how can I extract the whole sentence? The code should work, regardless of the position of the word in the sentence. Here I give an example:
A new crisis is emerging, a global food catastrophe that will reach further and be more crippling than anything the world has ever seen. The credit crunch and the reverberations of soaring oil prices around the world will pale in comparison to what is about to transpire, Donald Coxe, global portfolio strategist at BMO Financial Group said at the Empire Club's 14th annual investment outlook in Toronto on Thursday.
For instance, I search for the word catastrophe in this text and I find it. Now I need to extract the sentence:"A new crisis is emerging, a global food catastrophe that will reach further and be more crippling than anything the world has ever seen. "
I thought that I could use string.find until the characters ". " to get to the end of the sentence, but I also need to retrieve the part which comes before the word catastrophe. I would appreciate your ideas and help over this topic.
Thank you very much.
I have a paragraph containing many sentences and I need to extract a certain sentence, which contains a certain. I have no problem finding the word with my code but my question is, how can I extract the whole sentence? The code should work, regardless of the position of the word in the sentence. Here I give an example:
A new crisis is emerging, a global food catastrophe that will reach further and be more crippling than anything the world has ever seen. The credit crunch and the reverberations of soaring oil prices around the world will pale in comparison to what is about to transpire, Donald Coxe, global portfolio strategist at BMO Financial Group said at the Empire Club's 14th annual investment outlook in Toronto on Thursday.
For instance, I search for the word catastrophe in this text and I find it. Now I need to extract the sentence:"A new crisis is emerging, a global food catastrophe that will reach further and be more crippling than anything the world has ever seen. "
I thought that I could use string.find until the characters ". " to get to the end of the sentence, but I also need to retrieve the part which comes before the word catastrophe. I would appreciate your ideas and help over this topic.
Thank you very much.
•
•
Join Date: Jan 2009
Posts: 7
Reputation:
Solved Threads: 0
In a loop, I used this code to start from the found word and take until the first encounter with a dot. But I think there's something wrong with it, because in output there are some errors. I search in text files, which are actually source codes of some webpages, so they contain many HTML tags. They also interrupt. Is there any better algorithm to avoid that?
Thanks for help.
C++ Syntax (Toggle Plain Text)
size_t pos1,pos2; pos1=line.find(keyword_vector[i]); pos2=line.find(".",pos1); string sentence = line.substr(pos1,pos2);
Thanks for help.
Last edited by serhannn; Jan 11th, 2009 at 11:56 am.
Perhaps you should read the entire file in, strip out all html tags as you do so, that way you are left with just text. The go over and process what you have for sentences. But as ddanbe said, this isn't really a job for C++
The closest you will get to checking for the start and end of a sentence is [dot][space][capital] you will need to use that to check for both the beginning and end.
Chris
Chris
The closest you will get to checking for the start and end of a sentence is [dot][space][capital] you will need to use that to check for both the beginning and end.
Chris
Chris
Knowledge is power -- But experience is everything
![]() |
Similar Threads
- Detecting start of sentence. (Java)
- extracting info to another array (C++)
- How to extract words from char type string (C++)
- Selecting a directory instead of file (HTML and CSS)
- pascal word and letter counting (Pascal and Delphi)
Other Threads in the C++ Forum
- Previous Thread: Creating a dynamic 2D array
- Next Thread: while loop issue
| Thread Tools | Search this Thread |
addition api array base based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embed encryption error erroraftercompilation excel file forms fstream function functions game getline givemetehcodez gmail graph gui homework homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix matrix3d memory multiple news node output parameter pointer problem program programming project python random read recursion reference rpg std::coutwstring string strings temperature template test text text-file tree url variable vector video visualization win32 windows winsock word wordfrequency wxwidgets






