Ejemplo n.º 1
0
        public HitWords(WORDS word)
        {
            this.KEY = word.KEY;
            int len = word.TREE_PATH.Length;

            this.TREE_PATH = new int[len + 1];
            Array.Copy(word.TREE_PATH, this.TREE_PATH, word.TREE_PATH.Length);
            this.TREE_PATH[len] = word.KEY;
            this.WORD           = word.WORD;
            this.SCORE          = word.RANK;
        }
Ejemplo n.º 2
0
        protected static void InitWords(string dicPath)
        {
            Assembly assembly = Assembly.GetAssembly(typeof(WordsUtility));

            using (Stream stream = assembly.GetManifestResourceStream(dicPath))
            {
                while (true)
                {
                    WORDS  w       = new WORDS();
                    byte[] intByte = new byte[4];
                    stream.Read(intByte, 0, 4);
                    w.KEY = BitConverter.ToInt32(intByte, 0);
                    if (w.KEY == 0)
                    {
                        return;
                    }
                    stream.Read(intByte, 0, 4);
                    int    len = BitConverter.ToInt32(intByte, 0);
                    byte[] str = new byte[len];
                    stream.Read(str, 0, len);
                    w.WORD = Encoding.Unicode.GetString(str);
                    stream.Read(intByte, 0, 4);
                    len         = BitConverter.ToInt32(intByte, 0);
                    w.TREE_PATH = new int[len];
                    for (int i = 0; i < len; i++)
                    {
                        stream.Read(intByte, 0, 4);
                        w.TREE_PATH[i] = BitConverter.ToInt32(intByte, 0);
                    }
                    stream.Read(intByte, 0, 4);
                    w.RANK = BitConverter.ToSingle(intByte, 0);
                    stream.Read(intByte, 0, 4);
                    w.FLAG_KEY = BitConverter.ToInt32(intByte, 0);
                    Words.Add(w);
                }
            }
        }