Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(of': 0.07; 'data):': 0.07; 'next,': 0.07; 'omit': 0.07; 'parsing': 0.07; 'problem?': 0.07; 'eof': 0.09; 'loop.': 0.09; 'portions': 0.09; 'rules.': 0.09; 'slices': 0.09; 'splitting': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'suggest': 0.11; 'index': 0.13; '"import': 0.16; 'boundaries,': 0.16; 'btw': 0.16; 'combinations': 0.16; 'confusion': 0.16; 'enough.': 0.16; 'intrinsic': 0.16; 'length,': 0.16; 'looping': 0.16; 'mall': 0.16; 'perfect.': 0.16; 'pilot': 0.16; 'set,': 0.16; 'simplest': 0.16; 'slice.': 0.16; 'statement.': 0.16; 'subject:Discussion': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'detect': 0.17; 'issue.': 0.20; 'sort': 0.21; 'trying': 0.21; 'together.': 0.21; 'discovery': 0.22; 'parse': 0.22; 'subject:Code': 0.22; 'cc:2**0': 0.23; 'statement': 0.23; 'task': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'coding': 0.27; 'separate': 0.27; 'question': 0.27; 'document.': 0.27; 'lines': 0.28; 'appending': 0.29; 'issues.': 0.29; 'lightning': 0.29; 'separated': 0.29; 'subject:some': 0.29; 'convert': 0.29; 'words': 0.29; 'thursday,': 0.30; 'helpful': 0.30; 'code': 0.31; 'file': 0.32; 'room': 0.32; 'print': 0.32; 'achieving': 0.33; 'curious': 0.33; 'problem': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'list': 0.35; 'ahead': 0.35; 'city.': 0.35; 'text.': 0.35; 'so,': 0.35; 'board': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'data.': 0.36; 'indian': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'india': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'things': 0.38; 'end': 0.40; 'your': 0.60; 'group,': 0.60; 'july': 0.60; 'easy': 0.60; 'from:no real name:2**0': 0.60; 'skip:u 10': 0.60; 'you.': 0.61; 'high': 0.61; 'improved': 0.62; 'email addr:gmail.com': 0.63; 'more': 0.63; 'here': 0.65; 'charset:windows-1252': 0.65; 'taking': 0.65; 'learned': 0.65; 'dear': 0.66; 'agencies': 0.66; 'applying': 0.69; 'increase': 0.72; 'day': 0.73; 'power': 0.74; 'bag': 0.75; 'connection.': 0.75; 'fearing': 0.84; 'forced': 0.84; 'isn\x92t': 0.84; 'nicely.': 0.84; 'nigerian': 0.84; 'otten': 0.84; 'peter,': 0.84; 'spreads': 0.84; 'sri': 0.84; 'together,': 0.84; 'universe': 0.84; 'shopping': 0.87; 'aircraft': 0.91; 'evening': 0.91; 'received:209.85.220.184': 0.91; 'try.': 0.91; 'authorities': 0.95 Newsgroups: comp.lang.python Date: Thu, 5 Jul 2012 07:33:27 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=122.161.240.29; posting-account=6SonuQoAAACzSakS5dCECcJQe6ylLrzY References: <34484d3d-d4c2-463b-8f83-dba57ce0511d@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 122.161.240.29 MIME-Version: 1.0 Subject: Re: Discussion on some Code Issues From: subhabangalore@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 131 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341498810 news.xs4all.nl 6922 [2001:888:2000:d::a6]:35844 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24921 Dear Peter, That is a nice one. I am thinking if I can write "for lines in f" sort of c= ode that is easy but then how to find out the slices then, btw do you know = in any case may I convert the index position of file to the list position p= rovided I am writing the list for the same file we are reading.=20 Best Regards, Subhabrata.=20 On Thursday, July 5, 2012 1:00:12 PM UTC+5:30, Peter Otten wrote: > subhabangalore@gmail.com wrote: >=20 > > On Thursday, July 5, 2012 4:51:46 AM UTC+5:30, (unknown) wrote: > >> Dear Group, > >>=20 > >> I am Sri Subhabrata Banerjee trying to write from Gurgaon, India to > >> discuss some coding issues. If any one of this learned room can shower > >> some light I would be helpful enough. > >>=20 > >> I got to code a bunch of documents which are combined together. > >> Like, > >>=20 > >> 1)A Mumbai-bound aircraft with 99 passengers on board was struck by > >> lightning on Tuesday evening that led to complete communication failur= e > >> in mid-air and forced the pilot to make an emergency landing. 2) The > >> discovery of a new sub-atomic particle that is key to understanding ho= w > >> the universe is built has an intrinsic Indian connection. 3) A bomb > >> explosion outside a shopping mall here on Tuesday left no one injured, > >> but Nigerian authorities put security agencies on high alert fearing m= ore > >> such attacks in the city. > >>=20 > >> The task is to separate the documents on the fly and to parse each of = the > >> documents with a definite set of rules. > >>=20 > >> Now, the way I am processing is: > >> I am clubbing all the documents together, as, > >>=20 > >> A Mumbai-bound aircraft with 99 passengers on board was struck by > >> lightning on Tuesday evening that led to complete communication failur= e > >> in mid-air and forced the pilot to make an emergency landing.The > >> discovery of a new sub-atomic particle that is key to understanding ho= w > >> the universe is built has an intrinsic Indian connection. A bomb > >> explosion outside a shopping mall here on Tuesday left no one injured, > >> but Nigerian authorities put security agencies on high alert fearing m= ore > >> such attacks in the city. > >>=20 > >> But they are separated by a tag set, like, > >> A Mumbai-bound aircraft with 99 passengers on board was struck by > >> lightning on Tuesday evening that led to complete communication failur= e > >> in mid-air and forced the pilot to make an emergency landing.$ The > >> discovery of a new sub-atomic particle that is key to understanding ho= w > >> the universe is built has an intrinsic Indian connection.$ A bomb > >> explosion outside a shopping mall here on Tuesday left no one injured, > >> but Nigerian authorities put security agencies on high alert fearing m= ore > >> such attacks in the city. > >>=20 > >> To detect the document boundaries, I am splitting them into a bag of > >> words and using a simple for loop as, for i in range(len(bag_words)): > >> if bag_words[i]=3D=3D"$": > >> print (bag_words[i],i) > >>=20 > >> There is no issue. I am segmenting it nicely. I am using annotated cor= pus > >> so applying parse rules. > >>=20 > >> The confusion comes next, > >>=20 > >> As per my problem statement the size of the file (of documents combine= d > >> together) won=92t increase on the fly. So, just to support all kinds o= f > >> combinations I am appending in a list the =93I=94 values, taking its l= ength, > >> and using slice. Works perfect. Question is, is there a smarter way to > >> achieve this, and a curious question if the documents are on the fly w= ith > >> no preprocessed tag set like =93$=94 how may I do it? From a bunch wit= hout > >> EOF isn=92t it a classification problem? > >>=20 > >> There is no question on parsing it seems I am achieving it independent= of > >> length of the document. > >>=20 > >> If any one in the group can suggest how I am dealing with the problem = and > >> which portions should be improved and how? > >>=20 > >> Thanking You in Advance, > >>=20 > >> Best Regards, > >> Subhabrata Banerjee. > >=20 > >=20 > > Hi Steven, It is nice to see your post. They are nice and I learnt so m= any > > things from you. "I" is for index of the loop. Now my clarification I > > thought to do "import os" and process files in a loop but that is not m= y > > problem statement. I have to make a big lump of text and detect one chu= nk. > > Looping over the line number of file I am not using because I may not b= e > > able to take the slices-this I need. I thought to give re.findall a try > > but that is not giving me the slices. Slice spreads here. The power iss= ue > > of string! I would definitely give it a try. Happy Day Ahead Regards, > > Subhabrata Banerjee. >=20 > Then use re.finditer(): >=20 > start =3D 0 > for match in re.finditer(r"\$", data): > end =3D match.start() > print(start, end) > print(data[start:end]) > start =3D match.end() >=20 > This will omit the last text. The simplest fix is to put another "$"=20 > separator at the end of your data.