Ejemplo n.º 1
0
 /// <summary>
 /// 汉译英词典查询
 /// </summary>
 /// <param name="word"></param>
 /// <returns></returns>
 public static DictRecord QueryC2EDict(string word)
 {
     using (DbCommander cmd = new DbCommander(DbConn.ReadDb, "SP_Material_Dict_QueryC2E", CommandType.StoredProcedure))
     {
         cmd.AddInputParameters("Word", word);
         DictRecord resultData = null;
         using (IDataReader reader = cmd.ExecuteReader())
         {
             if (reader.Read())
             {
                 resultData = new DictRecord
                 {
                     Word        = (string)reader["Word"],
                     TransBase   = (byte[])reader["Translation"],
                     AudioEn     = "",
                     AudioUs     = "",
                     PhonicsEn   = "",
                     PhonicsUs   = "",
                     Example     = new byte[0],
                     Explication = new byte[0]
                 };
             }
             reader.Close();
         }
         return(resultData);
     }
 }
Ejemplo n.º 2
0
        public override byte[] unpack(byte[] data, uint unpackedSize)
        {
            byte[] o        = new byte[unpackedSize];
            byte[] temp8    = new byte[8];
            int    op       = 0;
            int    bitsleft = data.Length * 8;

            data = data.Concat(new byte[8]).ToArray();
            int pos = 0;

            Array.Copy(data, pos, temp8, 0, 8);
            UInt64 x = BitConverter.ToUInt64(Functions.CheckBytes(temp8), 0);
            int    n = 32;

            while (true)
            {
                if (n <= 0)
                {
                    pos += 4;
                    Array.Copy(data, pos, temp8, 0, 8);
                    x  = BitConverter.ToUInt64(Functions.CheckBytes(temp8), 0);
                    n += 32;
                }
                UInt64     code    = ((x >> n) & ((1L << 32) - 1));
                DictRecord rec     = _dict1[(int)(code >> 24)];
                int        codelen = (int)rec.codelen;
                UInt64     maxcode = rec.maxcode;
                if (rec.term == 0)
                {
                    while (code < _mincode[codelen])
                    {
                        codelen++;
                    }
                    maxcode = _maxcode[codelen];
                }
                n        -= codelen;
                bitsleft -= codelen;
                if (bitsleft < 0)
                {
                    break;
                }
                int   r     = (int)((maxcode - code) >> (32 - codelen));
                Slice slice = dictionary[r];
                if (slice.flag == 0)
                {
                    byte[] newSlice = unpack(slice.slice, 4096);
                    slice         = new Slice(newSlice, 1);
                    dictionary[r] = slice;
                }
                Array.Copy(slice.slice, 0, o, op, slice.slice.Length);
                op += slice.slice.Length;
            }
            byte[] temp = new byte[op];
            Array.Copy(o, temp, op);
            return(temp);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 查询单词翻译结果
        /// </summary>
        /// <param name="context"></param>
        /// <param name="word"></param>
        /// <param name="isChinese"></param>
        /// <param name="part"></param>
        /// <param name="extendQuery"></param>
        private static void Query(DataContext context, string word, bool isChinese, DictQuery.ResultPart part, bool extendQuery)
        {
            DictRecord dictRecord = MaterialBiz.GetDictRecord(word, isChinese);

            #region 查询有结果

            if (null != dictRecord)
            {
                DictResultBasic resultBase = new DictResultBasic
                {
                    Text        = dictRecord.Word.Trim(),
                    PhonicsEn   = dictRecord.PhonicsEn.Trim(),
                    PhonicsUs   = dictRecord.PhonicsUs.Trim(),
                    AudioEn     = dictRecord.AudioEn.Trim().ImageUrlFixed(),
                    AudioUs     = dictRecord.AudioUs.Trim().ImageUrlFixed(),
                    Meaning     = new List <DictResultPackage>(0),
                    Explication = new List <DictResultPackage>(0),
                    Example     = new List <DictResultPackage>(0)
                };

                if ((part == DictQuery.ResultPart.All || part == DictQuery.ResultPart.Meaning) && dictRecord.TransBase != null && dictRecord.TransBase.Length > 0)
                {
                    resultBase.Meaning = dictRecord.TransBase.ProtoBufDeserialize <List <DictResultPackage> >();
                }

                if ((part == DictQuery.ResultPart.All || part == DictQuery.ResultPart.Explication) && dictRecord.Explication != null && dictRecord.Explication.Length > 0)
                {
                    resultBase.Explication = dictRecord.Explication.ProtoBufDeserialize <List <DictResultPackage> >();
                }

                if ((part == DictQuery.ResultPart.All || part == DictQuery.ResultPart.Example) && dictRecord.Example != null && dictRecord.Example.Length > 0)
                {
                    resultBase.Example = dictRecord.Example.ProtoBufDeserialize <List <DictResultPackage> >();
                }

                DictResult result = new DictResult {
                    Basic = resultBase
                };
                context.Flush <DictResult>(result);
                return;
            }

            #endregion

            #region  查询无结果,需要联想查询

            if (extendQuery)
            {
                if (isChinese)
                {
                    #region 中文查询

                    //分词
                    List <string> wordList = word.Participle(isChinese).ToList();
                    if (wordList.Count > 0)
                    {
                        List <DictRecord> extendWords  = MaterialBiz.DictC2eExtendQuery(wordList, 20).ToList();
                        DictResult        extendResult = GetExtendDictResult(extendWords);
                        if (null != extendResult)
                        {
                            context.Flush <DictResult>(extendResult);
                            return;
                        }
                    }

                    #endregion
                }
                else
                {
                    #region 英文查询

                    List <string> wordList = new List <string>(0);
                    if (!word.IsFullEnglish())
                    {
                        wordList = word.Participle(isChinese).ToList();
                    }
                    else
                    {
                        wordList = new List <string> {
                            word
                        }
                    };

                    if (wordList.Count > 0)
                    {
                        List <DictRecord> extendWords = MaterialBiz.DictE2cExtendQueryWithWords(wordList, 20).ToList();

                        if (extendWords.Count > 0)
                        {
                            DictResult extendResult = GetExtendDictResult(extendWords);
                            if (null != extendResult)
                            {
                                context.Flush <DictResult>(extendResult);
                                return;
                            }
                        }
                    }

                    #endregion
                }
            }

            #endregion

            #region 查询无结果,并且无需联想查询

            context.Flush();
            return;

            #endregion
        }