示例#1
0
        private MyWord[][] getWords(string txt, out int nRow)
        {
            var t   = new MyTimer("getWords");
            var cnn = new SQLiteConnection(sqliteCnnStr);

            cnn.Open();
            var cmd = new SQLiteCommand("select ID from keys where key = ?", cnn);

            cmd.Parameters.Add(new SQLiteParameter("", System.Data.DbType.String));

            var reg   = new Regex(@"[\w]+");
            var mc    = reg.Matches(txt);
            var tDict = new Dictionary <string, UInt64>();

            foreach (Match m in mc)
            {
                if (tDict.ContainsKey(m.Value))
                {
                    continue;
                }

                cmd.Parameters[0].Value = m.Value;
                var res = cmd.ExecuteScalar();
                if (res != null)
                {
                    tDict.Add(m.Value, Convert.ToUInt64(res));
                }
            }
            cmd.Dispose();

            var cmd2 = new SQLiteCommand("select titleId, paragraphId, pos, word from words where keyId = ?", cnn);

            cmd2.Parameters.Add(new SQLiteParameter("", System.Data.DbType.UInt64));
            var arr = new MyWord[tDict.Count][];

            nRow = 0;
            foreach (var keyId in tDict.Values)
            {
                var lst = new List <MyWord>();
                cmd2.Parameters[0].Value = keyId;
                var rd = cmd2.ExecuteReader();
                while (rd.Read())
                {
                    lst.Add(new MyWord()
                    {
                        titleId = Convert.ToUInt64(rd[0]),
                        parId   = Convert.ToUInt64(rd[1]),
                        pos     = Convert.ToInt32(rd[2]),
                        content = Convert.ToString(rd[3])
                    });
                }
                arr[nRow++] = lst.ToArray();
                rd.Close();
            }

            cnn.Close();
            cnn.Dispose();
            return(arr);
        }
示例#2
0
        int wordDiff(MyWord w1, MyWord w2)
        {
            var a1 = new int[] {
                Convert.ToInt32(w1.titleId),
                Convert.ToInt32(w1.parId),
                w1.pos
            };
            var a2 = new int[] {
                Convert.ToInt32(w2.titleId),
                Convert.ToInt32(w2.parId),
                w2.pos
            };
            var c    = new int[] { 1000, 100, 10 };
            int diff = 0;

            for (int i = 0; i < 3; i++)
            {
                diff += Math.Abs(a1[i] - a2[i]) * c[i];
            }
            return(diff);
        }