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

def pysqlitedb::PYSQLiteDB::new_phrase (   self,
  phrases,
  freq = None,
  user_freq = 1 
)

this function create a new phrase from a phrase list and put it into user database.

Definition at line 347 of file pysqlitedb.py.

00347                                                               :
        """this function create a new phrase from a phrase list and put it into user database."""
        pinyin_ids = []
        shengmu_ids = []
        phrase = u""
        phrase_length = 0
        for p in phrases:
            if phrase_length + p[YLEN] > 8:
                break
            phrase += p[PHRASE]
            phrase_length += p[YLEN]
            if p[YLEN] > 4:
                ys = p[YX].split ("'")
            for i in range (0, p[YLEN]):
                if i < 4:
                    pinyin_ids.append (p[Y0 + i])
                    shengmu_ids.append (p[S0 + i])
                else:
                    w = pyutil.PinYinWord (ys[i - 4])
                    pinyin_ids.append (w.get_pinyin_id ())
                    shengmu_ids.append (w.get_sheng_mu_id ())

        sql = """INSERT INTO user_db.py_phrase
            (ylen, y0, y1, y2, y3, yx, s0, s1, s2, s3, phrase, freq, user_freq)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""

        values = [phrase_length, None, None, None, None, None, None, None, None, None, phrase, freq, user_freq]

        if phrase_length <=4:
            values[1: 1 + phrase_length] = pinyin_ids [:phrase_length]
            values[6: 6 + phrase_length] = shengmu_ids [:phrase_length]
        else:
            values[1: 5] = pinyin_ids [:4]
            values[6: 10] = shengmu_ids [:4]
            get_pinyin = lambda id: pydict.ID_PINYIN_DICT[id]
            values[5] = "'".join (map (get_pinyin, pinyin_ids[4:]))

        self.db.execute (sql, values)

        self.flush ()
        self.select_cache.clear ()

    def remove_phrase (self, record):


Generated by  Doxygen 1.6.0   Back to index