Re: [cx-oracle-users] cx_Oracle cursor.var Example
Brought to you by:
atuining
From: Solomon, S. <Sco...@sr...> - 2014-10-23 19:53:52
|
Anthony Tuininga, et al, I am trying to run the following code (with DB connection information intentionally redacted: import logging, gensim, bz2, cx_Oracle logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) from gensim import corpora, models, similarities dsnStr = cx_Oracle.makedsn("{redacted}", "{redacted}", "{redacted}") con = cx_Oracle.connect(user="{redacted}", password="{redacted}", dsn=dsnStr) cur = con.cursor() cur.execute('select project_title from doj_collab_award_dim where project_title is not null and rownum < 101') stoplist = set('for a of the and to in is'.split()) dictionarywiki = corpora.Dictionary(line.lower().split() for line in cur) stop_ids = [dictionarywiki.token2id[stopword] for stopword in stoplist if stopword in dictionarywiki.token2id] once_ids = [tokenid for tokenid, docfreq in dictionarywiki.dfs.iteritems() if docfreq == 1] dictionarywiki.filter_tokens(stop_ids + once_ids) dictionarywiki.compactify() print(dictionarywiki) print(dictionarywiki.token2id) which returns the error: AttributeError: 'tuple' object has no attribute 'lower' in bolded, yellow highlighted line ('dictionarywiki...) I am trying to convert the variable line to string using Cursor.var(dataType[, size, arraysize, inconverter, outconverter, typename]) from http://cx-oracle.readthedocs.org/en/latest/cursor.html I tried: import logging, gensim, bz2, cx_Oracle logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) from gensim import corpora, models, similarities dsnStr = cx_Oracle.makedsn("{redacted}", "{redacted}", "{redacted}") con = cx_Oracle.connect(user="{redacted}", password="{redacted}", dsn=dsnStr) cur = con.cursor() cur.execute('select project_title from doj_collab_award_dim where project_title is not null and rownum < 101') stoplist = set('for a of the and to in is'.split()) dictionarywiki = corpora.Dictionary(line.lower().split() for line.cursor.var(string) in cur) stop_ids = [dictionarywiki.token2id[stopword] for stopword in stoplist if stopword in dictionarywiki.token2id] once_ids = [tokenid for tokenid, docfreq in dictionarywiki.dfs.iteritems() if docfreq == 1] dictionarywiki.filter_tokens(stop_ids + once_ids) dictionarywiki.compactify() print(dictionarywiki) print(dictionarywiki.token2id) I guess I am doing it wrong. Can someone provide me an example of how to change my variable to a string? Maybe is it this: dictionarywiki = corpora.Dictionary(line.lower().split() for cursor.line(string) in cur) ? ---------- Scott S. |