I have a piece of text which is in the following format: "1. Question blah blah blah. goes on blah blah blah blah. Answer: Answer blah, blah goes on like this blah blah. 2. One more question. blah blah goes on like this again. Answer: Again and again, over and over." Now taking a piece of text, I have to break it down to pairs of question and answer sets so that they can be saved in to question model - which has a question and answer attribute. A single piece of text saved in a Post model needs to be parsed into a number of question models. The problem is that the text is very idiosyncratic, with numerous line breaks and carriage returns inside each question and answer but the numbering and the "Answer:" segments are present accurately. From what I read through various sources, this can be accomplished through regular expressions but I am not able to figure out how to go about this. Could someone explain how this can be accomplished for this particular case?
On Jun 13, 9:40 pm, Hypnotizing Chickens <chickens....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a piece of text which is in the following format: > "1. Question blah blah blah. goes on blah blah > blah blah. > Answer: Answer blah, blah goes on like > this blah blah. > 2. One more question. blah blah goes > on like this again. > Answer: Again and again, over and over." > > Now taking a piece of text, I have to break it down to pairs of > question and answer sets so that they can be saved in to question > model - which has a question and answer attribute. A single piece of > text saved in a Post model needs to be parsed into a number of > question models. > The problem is that the text is very idiosyncratic, with numerous line > breaks and carriage returns inside each question and answer but the > numbering and the "Answer:" segments are present accurately. From what > I read through various sources, this can be accomplished through > regular expressions but I am not able to figure out how to go about > this. Could someone explain how this can be accomplished for this > particular case?you may find string scanner more appropriate in this case. In a nutshell you tell it to scan until it finds text matching a particular pattern (in your case the beginning of question and beginning of answer markers), and it tells you all the text it consumed in between. Fred
On 14 Jun, 03:20, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 13, 9:40 pm, Hypnotizing Chickens <chickens....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > I have a piece of text which is in the following format: > > "1. Question blah blah blah. goes on blah blah > > blah blah. > > Answer: Answer blah, blah goes on like > > this blah blah. > > 2. One more question. blah blah goes > > on like this again. > > Answer: Again and again, over and over." > > > Now taking a piece of text, I have to break it down to pairs of > > question and answer sets so that they can be saved in to question > > model - which has a question and answer attribute. A single piece of > > text saved in a Post model needs to be parsed into a number of > > question models. > > The problem is that the text is very idiosyncratic, with numerous line > > breaks and carriage returns inside each question and answer but the > > numbering and the "Answer:" segments are present accurately. From what > > I read through various sources, this can be accomplished through > > regular expressions but I am not able to figure out how to go about > > this. Could someone explain how this can be accomplished for this > > particular case? > > you may find string scanner more appropriate in this case. In a > nutshell you tell it to scan until it finds text matching a particular > pattern (in your case the beginning of question and beginning of > answer markers), and it tells you all the text it consumed in between. > > FredThanks! String scanner worked like a charm.
Hi there I m a starter in both linux and ruby on rails... is there any ruby gems or any other way to parse the text from open office and upload it to the database... Thanks in Advance -- Posted via http://www.ruby-forum.com/.
Hi, youc an use Faster Csv plugin for this. It''s very easy by this plugin. 2009/6/15 Anandh Kumar <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > Hi there > > > I m a starter in both linux and ruby on rails... is there any ruby > gems or any other way to parse the text from open office and upload it > to the database... > > > > > > > > > Thanks in Advance > -- > Posted via http://www.ruby-forum.com/. > > > >-- Regards, Amit Kumar Sr. Software Engrr +91 9890654102 +91 9373087399 Blogsite: http://amitbaraik.blog.co.in/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, You can use Faster csv plugin for this. On Jun 15, 5:09 am, Anandh Kumar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi there > > I m a starter in both linux and ruby on rails... is there any ruby > gems or any other way to parse the text from open office and upload it > to the database... > > Thanks in Advance > -- > Posted viahttp://www.ruby-forum.com/.
Anandh Kumar
2009-Jun-15 09:49 UTC
Re: parsing text in rails application in linux platform
hi amit Thanks for your reply... can i use string scanner class to accomplish the task... -- Posted via http://www.ruby-forum.com/.
Hi everybody Can i use stringscanner class to parse strings of an openoffice document and upload it to the datbase... If so can anyone there guide me in fixing this task... I want this task to be done in ruby on rails and in linux platform... Thanks in advance -- Posted via http://www.ruby-forum.com/.