Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104397
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Friedrich Rentsch <anthra.norell@bluewin.ch> |
| Newsgroups | comp.lang.python |
| Subject | Re: Review Request of Python Code |
| Date | Wed, 9 Mar 2016 10:06:24 +0100 |
| Lines | 86 |
| Message-ID | <mailman.74.1457514455.15725.python-list@python.org> (permalink) |
| References | <f0973a0d-62ba-402b-ab23-cb68bdd15323@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de D69GAkurwPPuJqggyv+qRQH0atZT2iUAQCbb0OrKpLXg== |
| Return-Path | <anthra.norell@bluewin.ch> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'subject:Python': 0.05; '#print': 0.09; 'of)': 0.09; 'okay': 0.09; 'received:192.168.1.101': 0.09; 'runtime': 0.09; 'slow.': 0.09; 'skip:# 20': 0.13; 'def': 0.13; 'backend': 0.15; '"none"': 0.16; 'lambda': 0.16; 'list1': 0.16; 'pulling': 0.16; 'range(0,': 0.16; 'received:195.186': 0.16; 'received:bluewin.ch': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'stages': 0.16; 'wrote:': 0.16; 'input': 0.18; 'windows': 0.20; 'do.': 0.22; 'subject:Code': 0.22; 'trying': 0.22; 'am,': 0.23; 'code.': 0.23; 'help.': 0.23; 'advance.': 0.23; 'performing': 0.23; 'sets': 0.23; 'split': 0.23; 'tried': 0.24; 'import': 0.24; 'words': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'skip:m 30': 0.27; 'error': 0.27; 'coding': 0.27; 'skip:# 10': 0.27; 'have,': 0.27; 'fine': 0.28; 'dictionary': 0.29; 'separated': 0.29; 'print': 0.30; 'code': 0.30; "i'd": 0.31; 'generally': 0.32; 'skip:d 40': 0.32; 'problem': 0.33; 'file': 0.34; 'skip:d 20': 0.34; 'running': 0.34; 'info': 0.34; 'so,': 0.35; 'but': 0.36; 'lines': 0.36; 'cases': 0.36; 'framework': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'say': 0.37; 'thanks': 0.37; 'missing': 0.37; 'skip:v 20': 0.38; 'end': 0.39; 'data': 0.39; 'takes': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'group,': 0.60; 'save': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'skip:n 10': 0.62; 'more': 0.63; 'limit': 0.65; 'real-world': 0.66; 'received:ch': 0.66; 'results': 0.66; 'articles': 0.67; 'dear': 0.67; 'news': 0.68; 'feeling': 0.72; 'completion': 0.79; 'sentences,': 0.84; 'minute.': 0.91 |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 |
| In-Reply-To | <f0973a0d-62ba-402b-ab23-cb68bdd15323@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:104397 |
Show key headers only | View raw
On 03/09/2016 05:18 AM, subhabangalore@gmail.com wrote:
> Dear Group,
>
> I am trying to write a code for pulling data from MySQL at the backend and annotating words and trying to put the results as separated sentences with each line. The code is generally running fine but I am feeling it may be better in the end of giving out sentences, and for small data sets it is okay but with 50,000 news articles it is performing dead slow. I am using Python2.7.11 on Windows 7 with 8GB RAM.
>
> I am trying to copy the code here, for your kind review.
>
> import MySQLdb
> import nltk
> def sql_connect_NewTest1():
> db = MySQLdb.connect(host="localhost",
> user="*****",
> passwd="*****",
> db="abcd_efgh")
> cur = db.cursor()
> #cur.execute("SELECT * FROM newsinput limit 0,50000;") #REPORTING RUNTIME ERROR
> cur.execute("SELECT * FROM newsinput limit 0,50;")
> dict_open=open("/python27/NewTotalTag.txt","r") #OPENING THE DICTIONARY FILE
> dict_read=dict_open.read()
> dict_word=dict_read.split()
> a4=dict_word #Assignment for code.
> list1=[]
> flist1=[]
> nlist=[]
> for row in cur.fetchall():
> #print row[2]
> var1=row[3]
> #print var1 #Printing lines
> #var2=len(var1) # Length of file
> var3=var1.split(".") #SPLITTING INTO LINES
> #print var3 #Printing The Lines
> #list1.append(var1)
> var4=len(var3) #Number of all lines
> #print "No",var4
> for line in var3:
> #print line
> #flist1.append(line)
> linew=line.split()
> for word in linew:
> if word in a4:
> windex=a4.index(word)
> windex1=windex+1
> word1=a4[windex1]
> word2=word+"/"+word1
> nlist.append(word2)
> #print list1
> #print nlist
> elif word not in a4:
> word3=word+"/"+"NA"
> nlist.append(word3)
> #print list1
> #print nlist
> else:
> print "None"
>
> #print "###",flist1
> #print len(flist1)
> #db.close()
> #print nlist
> lol = lambda lst, sz: [lst[i:i+sz] for i in range(0, len(lst), sz)] #TRYING TO SPLIT THE RESULTS AS SENTENCES
> nlist1=lol(nlist,7)
> #print nlist1
> for i in nlist1:
> string1=" ".join(i)
> print i
> #print string1
>
>
> Thanks in Advance.
>
>
I have a modular processing framework in its final stages of completion
whose purpose is to save (a lot of) time coding the kind of problem you
describe. I intend to upload the system and am currently interested in
real-world cases for the manual. I tried coding your problem, thinking
it would take no more than a minute. It wasn't that easy, because don't
say what input you have, nor what you expect your program to do.
Inferring the missing info from your code takes more time that I can
spare. So, if you would give a few lines of your input and explain your
purpose, I'd be happy to help.
Frederic
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Review Request of Python Code subhabangalore@gmail.com - 2016-03-08 20:18 -0800
Re: Review Request of Python Code Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-09 16:10 +1100
Re: Review Request of Python Code INADA Naoki <songofacandy@gmail.com> - 2016-03-09 16:52 +0900
Re: Review Request of Python Code Friedrich Rentsch <anthra.norell@bluewin.ch> - 2016-03-09 10:06 +0100
Re: Review Request of Python Code Matt Wheeler <m@funkyhat.org> - 2016-03-09 12:06 +0000
Re: Review Request of Python Code Matt Wheeler <m@funkyhat.org> - 2016-03-09 12:33 +0000
Re: Review Request of Python Code subhabangalore@gmail.com - 2016-03-10 10:12 -0800
Re: Review Request of Python Code BartC <bc@freeuk.com> - 2016-03-10 18:36 +0000
Re: Review Request of Python Code Matt Wheeler <m@funkyhat.org> - 2016-03-10 18:51 +0000
Re: Review Request of Python Code subhabangalore@gmail.com - 2016-03-10 12:14 -0800
RE: Review Request of Python Code Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-03-10 19:12 +0000
Re: Review Request of Python Code Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-10 19:56 +0000
csiph-web