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

def pysqlitedb::PYSQLiteDB::select_words_by_pinyin_list (   self,
  pys,
  mohu = False 
)

select words from database by list that contains pyutil.PinYinWord objects

Definition at line 239 of file pysqlitedb.py.

00239                                                              :
        """select words from database by list that contains pyutil.PinYinWord objects"""

        pinyin_string = u"'".join (map (str, pys))
        result = self.select_cache [pinyin_string]
        if result != None:
            return result

        tables_union = """( SELECT * FROM main.py_phrase WHERE %(conditions)s UNION ALL
        SELECT * FROM user_db.py_phrase WHERE %(conditions)s )"""

        if mohu:
            sql_conditions = ["+ylen = %d" % len (pys) ]
        else:
            sql_conditions = ["ylen = %d" % len (pys) ]


        i = 0
        if mohu == False:
            for py in pys[:4]:
                if py.is_valid_pinyin ():
                    sql_conditions.append ("y%d = %d" % (i, py.get_pinyin_id ()))
                else:
                    sql_conditions.append ("s%d = %d" % (i, py.get_sheng_mu_id ()))
                i += 1
        else:
            for py in pys[:4]:
                if py.is_valid_pinyin ():
                    shengmu = py.get_shengmu ()
                    yunmu = py.get_pinyin ()[len (shengmu):]
                    if shengmu in pydict.MOHU_SHENGMU:
                        shengmu_list = pydict.MOHU_SHENGMU[shengmu]
                    else:
                        shengmu_list = [shengmu]

                    if yunmu in pydict.MOHU_YUNMU:
                        yunmu_list = pydict.MOHU_YUNMU[yunmu]
                    else:
                        yunmu_list = [yunmu]

                    pinyin_ids = []
                    for s in shengmu_list:
                        for y in yunmu_list:
                            pinyin = s + y
                            if pinyin in pydict.PINYIN_DICT:
                                pinyin_ids.append (str (pydict.PINYIN_DICT[pinyin]))
                    if len (pinyin_ids) > 1:
                        sql_conditions.append ("y%d in (%s)" % (i, ",".join (pinyin_ids)))
                    else:
                        sql_conditions.append ("y%d == %s" % (i, pinyin_ids[0]))

                else:
                    shengmu = py.get_shengmu ()
                    if shengmu in pydict.MOHU_SHENGMU:
                        shengmu_ids = []
                        for s in pydict.MOHU_SHENGMU[shengmu]:
                            shengmu_ids.append (str (pydict.SHENGMU_DICT[s]))
                        sql_conditions.append ("s%d in (%s)" % (i, ",".join (shengmu_ids)))
                    else:
                        sql_conditions.append ("s%d = %d" % (i, py.get_sheng_mu_id ()))
                i += 1

        if pys[4:]:
            pp = lambda (x): x.get_pattern (mohu)
            pattern = "'".join (map (pp, pys[4:]))
            sql_conditions.append ("yx LIKE \"" + pattern + "\"")


        tables_union = tables_union % { "conditions" : " AND ".join (sql_conditions) }
        sql_prefix = "SELECT * FROM " + tables_union

        sql_string = sql_prefix + " GROUP BY phrase ORDER BY user_freq DESC, freq DESC;"

        result = list (self.db.execute (sql_string).fetchall ())

        self.select_cache [pinyin_string] = result

        return result

    def select_words_by_pinyin_string (self, string, mohu = False):


Generated by  Doxygen 1.6.0   Back to index