Re: cx_Oracle cursor.var Example
"Solomon, Scott" <[email protected]>
| Newsgroups | gmane.comp.python.db.cx-oracle |
|---|---|
| Message-ID | <[email protected]> |
Ok, getting closer. Causes another error. I think I still need to convert variable 'line' to string somehow:
File "C:\Users\{redacted}\gensim\models\lsimodel.py", line 513, in show_topics
if i < len(self.projection.s):
TypeError: object of type 'NoneType' has no len()
----------
Scott S.
________________________________
From: Anthony Tuininga [[email protected]]
Sent: Thursday, October 23, 2014 3:57 PM
To: cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [cx-oracle-users] cx_Oracle cursor.var Example
You need to use this
line.lower().split() for line, in cur
Note the comma following the line variable. cx_Oracle returns a tuple and you need to unpack that tuple. That should solve it for you. You don't need to build a variable generally.
On Thu, Oct 23, 2014 at 1:53 PM, Solomon, Scott <[email protected]<mailto:[email protected]>> wrote:
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.
------------------------------------------------------------------------------
_______________________________________________
cx-oracle-users mailing list
cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users
------------------------------------------------------------------------------
_______________________________________________
cx-oracle-users mailing list
cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users