Re: [cx-oracle-users] cx_Oracle cursor.var Example
Brought to you by:
atuining
|
From: Anthony T. <ant...@gm...> - 2014-10-23 19:57:59
|
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 <Sco...@sr...>
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-...@li...
> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users
>
>
|