Re: cx_Oracle cursor.var Example

"Solomon, Scott" <[email protected]>
Newsgroups gmane.comp.python.db.cx-oracle
Message-ID <[email protected]>
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
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.