Exemplo n.º 1
0
 def write_words_to_db(self, pmcid, words):
     try:
         self.mydb.get_cursor().execute("insert or replace into bagofwords (pmcid, words) values (?, ?)", 
                           (pmcid, words))
         self.mydb.free()
     except Exception, e:
         mylog.error(e)
Exemplo n.º 2
0
 def doctext_from_db(self, pmcid):
     response = ""
     try:
         self.mydb.get_cursor().execute("select words from bagofwords where pmcid=%s" % (pmcid))
         row = self.mydb.get_cursor().fetchone()
         if row:
             response = row[0]
         self.mydb.free()
     except Exception, e:
         mylog.error(e)
Exemplo n.º 3
0
 def all_doctext_words_from_db(self, pmcids):
     words = FreqDist()
     str_list_pmcids = "("
     for pmcid in pmcids:
         str_list_pmcids +=  pmcid + ","
     str_list_pmcids += "0)"
     try:
         self.mydb.get_cursor().execute("select words from bagofwords where pmcid in %s" % (str_list_pmcids))
         rows = self.mydb.get_cursor().fetchall()
         for row in rows:
             for word in row[0].split():
                 words.inc(word)
     except Exception, e:
         mylog.error(e)