//public static ParseResultCollection Parse(string text)
        //{
        //    return ParseResultCollection.InternalParse(text,new PlaceNameParser(text));
        //}

        public PlaceNameParser(ParserContext context)
        {
            this.context = context;
            if (placeNamesTrie == null)
            {
                placeNamesTrie = context.GetServerInstance();
            }

            placeNamesTrie.Connect(context.ServerEndPoint);
        }
Example #2
0
        public NameParser(ParserContext context)
        {
            this.context = context;
            client       = context.GetServerInstance();
            client.Connect(context.ServerEndPoint);

            prefixAndstandard.AddRange(prefixTitleList);
            prefixAndstandard.AddRange(titleList);
            suffixAndstandard.AddRange(suffixTitleList);
            suffixAndstandard.AddRange(titleList);
        }
Example #3
0
        public void TestServerCommand_MMFetch()
        {
            EndPoint serverAddress = new IPEndPoint(IPAddress.Parse(ip), port);

            using (DictionaryServiceClient dsc = new DictionaryServiceClient())
            {
                dsc.Connect(serverAddress);
                string responseText = dsc.SendCommand("MMFetch 测试" + Environment.NewLine);
                AssertServerResponse(responseText, true, "测试");

                responseText = dsc.SendCommand("MMFetch 我们一起去吧" + Environment.NewLine);
                AssertServerResponse(responseText, true, "我们");
            }
        }
Example #4
0
        public void TestRMMFetchWrapper()
        {
            EndPoint serverAddress = new IPEndPoint(IPAddress.Parse(ip), port);

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

                responseText = dsc.ReverseMaximumMatch("请你相信我们").Word;
                Assert.AreEqual("我们", responseText);
            }
        }
Example #5
0
        public ChineseAddressParser(ParserContext context)
        {
            if (context.Pattern != ParserPattern.China)
            {
                throw new ArgumentOutOfRangeException("中文地址仅对ParserPattern.China有效");
            }
            this.context = context;
            client       = context.GetServerInstance();

            client.Connect(context.ServerEndPoint);
            //MongoDatabase db = server.GetDatabase("nameResearch");
            //_cityNames = db.GetCollection<CityEntity>("cityNames");
            //_placeNames = db.GetCollection<NameEntity>("placeNames");
        }
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      = "未找到合适词";
                }
            }
        }
Example #7
0
 public OrgNameParser(ParserContext context)
 {
     this.context = context;
     orgNamesTrie = context.GetServerInstance();
     orgNamesTrie.Connect(context.ServerEndPoint);
 }