Example #1
0
        string MatchSurname(string text, int startIndex)
        {
            string temp   = text.Substring(startIndex, startIndex + 2 > text.Length?text.Length - startIndex:2);
            var    result = client.MaximumMatch(temp, (int)POSType.A_NR);

            if (result == null)
            {
                return(null);
            }

            return(result.Word);
        }
Example #2
0
        public void TestMMFetchWrapper()
        {
            EndPoint serverAddress = new IPEndPoint(IPAddress.Parse(ip), port);

            using (DictionaryServiceClient dsc = new DictionaryServiceClient())
            {
                dsc.Connect(serverAddress);
                string responseText = dsc.MaximumMatch("测试").Word;
                Assert.AreEqual("测试", responseText);

                responseText = dsc.MaximumMatch("我们一起去吧").Word;
                Assert.AreEqual("我们", responseText);
            }
        }
Example #3
0
        //internal static string GetMaximumMatch(string text, int startIndex, int maxlength, string fieldname, MongoCollection<CityEntity> dbcol, IMongoQuery query)
        //{
        //    string word = null;
        //    int j;
        //    string temp = null;
        //    for (j = maxlength; j > 0; j--)
        //    {
        //        temp = text.Substring(startIndex, j + startIndex > text.Length ? text.Length - startIndex : j);
        //        long c2 = 0;
        //        if (query == null)
        //        {
        //            if (fieldname == "city")
        //            {
        //                c2 = dbcol.Count(Query.Or(Query.EQ(fieldname, temp), Query.EQ(fieldname, temp + '市')));
        //            }
        //            else
        //            {
        //                c2 = dbcol.Count(Query.EQ(fieldname, temp));
        //            }
        //        }
        //        else
        //        {
        //            c2 = dbcol.Count(Query.And(Query.EQ(fieldname, temp), query));
        //        }
        //        if (c2 > 0)
        //        {
        //            word = temp;
        //            //if (fieldname == "city" && !temp.EndsWith("市"))
        //            //{
        //            //    word += '市';
        //            //}
        //            return word;
        //        }
        //    }
        //    return null;
        //}

        internal string GetMaximumMatch(string text, int startIndex, int maxlength)
        {
            string temp   = text.Substring(startIndex, Math.Min(text.Length - startIndex, maxlength));
            var    result = client.MaximumMatch(temp, (int)POSType.A_NS);

            if (result == null)
            {
                return(null);
            }
            return(result.Word);
        }
        internal string MatchPlaceName(string text, int startIndex)
        {
            int    maxlength = maxChinesePlaceNameLength;
            string temp      = text.Substring(startIndex, Math.Min(text.Length - startIndex, maxlength));

            var result = placeNamesTrie.MaximumMatch(temp, (int)POSType.A_NS);

            if (result == null)
            {
                return(null);
            }
            return(result.Word);
        }
Example #5
0
        string MatchOrgName(string text, int startIndex)
        {
            int    maxlength = 10;
            string temp      = text.Substring(startIndex, Math.Min(text.Length - startIndex, maxlength));

            var result = orgNamesTrie.MaximumMatch(temp, (int)POSType.A_NT);

            if (result == null)
            {
                return(null);
            }
            return(result.Word);
            //for (int j = Math.Min(text.Length - startIndex, maxlength); j > 1; j--)
            //{
            //    string temp = text.Substring(startIndex, j);
            //    int freq = orgNamesTrie.GetFrequency(temp);
            //    if (freq <= 0)
            //        continue;
            //    else
            //        return temp;
            //}
            //return null;
        }
Example #6
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            Regex    regex         = new Regex("dict://([\\d\\.]+):(\\d{3,5})", RegexOptions.Compiled);
            string   addr          = tbDictAddress.Text.Trim();
            var      matches       = regex.Matches(addr);
            string   serverAddr    = matches[0].Groups[1].Value;
            int      port          = Int32.Parse(matches[0].Groups[2].Value);
            EndPoint serverAddress = new IPEndPoint(IPAddress.Parse(serverAddr), port);


            int posValue = 0;

            foreach (var selectedObject in checkedListBox1.CheckedItems)
            {
                string value  = (string)selectedObject;
                var    values = Enum.GetValues(typeof(POSType));
                foreach (var v in values)
                {
                    if (((System.Enum)v).Description() == value)
                    {
                        POSType pos = (POSType)v;
                        posValue |= ((int)pos);
                        break;
                    }
                }
            }
            using (DictionaryServiceClient dsc = new DictionaryServiceClient())
            {
                dsc.Connect(serverAddress);
                TrieTreeResult result = null;
                if (radioButton1.Checked)
                {
                    result = dsc.MaximumMatch(tbWord.Text.Trim(), posValue);
                }
                else if (radioButton2.Checked)
                {
                    result = dsc.ReverseMaximumMatch(tbWord.Text.Trim(), posValue);
                }
                else
                {
                    result = dsc.ExactMatch(tbWord.Text.Trim(), posValue);
                }

                if (result != null)
                {
                    string resultText = result.Word;
                    int    originalLength1 = 0, originalLength2 = 0;

                    if (result.Frequency != 0)
                    {
                        originalLength1 = resultText.Length;
                        resultText     += ", 频率:" + result.Frequency;
                    }
                    if (result.POS > 0)
                    {
                        originalLength2 = resultText.Length;
                        resultText     += ", 类型:" + ConvertPOSTypesToString(ConvertValueToPOS(result.POS));
                    }
                    richTextBox1.Text      = resultText;
                    richTextBox1.ForeColor = System.Drawing.Color.Black;
                    if (originalLength1 > 0)
                    {
                        richTextBox1.Select(originalLength1 + 1, 4);
                        richTextBox1.SelectionColor = System.Drawing.Color.Blue;
                    }
                    if (originalLength2 > 0)
                    {
                        richTextBox1.Select(originalLength2 + 1, 4);
                        richTextBox1.SelectionColor = System.Drawing.Color.Blue;
                    }
                }
                else
                {
                    richTextBox1.ForeColor = System.Drawing.Color.Red;
                    richTextBox1.Text      = "未找到合适词";
                }
            }
        }