Logo Search packages:      
Sourcecode: ibus-pinyin version File versions

def pysqlitedb::PYSQLiteDB::add_phrases (   self,
  phrases,
  database = "main" 
)

add phrases to database, phrases is a iterable object
Like: [(phrase, pinyin, freq), (phrase, pinyin, freq), ...]

Definition at line 185 of file pysqlitedb.py.

00185                                                       :
        """ add phrases to database, phrases is a iterable object
        Like: [(phrase, pinyin, freq), (phrase, pinyin, freq), ...]
        """
        sqlstring = """INSERT INTO %s.py_phrase (ylen, y0, y1, y2, y3, yx, s0, s1, s2, s3, phrase, freq, user_freq)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""
        line = 1
        for  phrase, pinyin, freq in phrases:
            try:
                py = self.parser.parse (pinyin)
                if len (py) != len (phrase):
                    error_message = u"%s %s: Can not parse pinyin." % (phrase, pinyin)
                    raise Exception (error_message.encode ("utf8"))
                record = [None, None, None, None, None, None, None, None, None, None, None, None, None]
                record [YLEN] = len (py)
                i = 0
                for p in py[:4]:
                    record[Y0 + i] = p.get_pinyin_id ()
                    record[S0 + i] = p.get_sheng_mu_id ()
                    i += 1
                if len (py) > 4:
                    record[YX] = "'".join (map (str, py[4:]))
                record[PHRASE] = phrase
                record[FREQ] = freq
                record[USER_FREQ] = None
                self.db.execute (sqlstring % database, record)
            except Exception, e:
                print line, ":", phrase.encode ("utf-8"), pinyin, freq
                import traceback
                traceback.print_exc ()
                # print e
            line += 1

        self.flush (True)

    def get_pinyin_table (self):


Generated by  Doxygen 1.6.0   Back to index