温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

中文分词技术

发布时间:2020-04-11 00:28:02 来源:网络 阅读:420 作者:bIgVe 栏目:开发技术
//正向最大匹配分词算法 ,耗时长,这并不是一个很好的算法,我的这个输出是逆向输入的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClusterCharater
{
    public class SplitChineseCharacter
    {

        private String[] dictionary = { "今天", "是","星期" ,"六","星期六" }; //词典
        private String input = null;
        public List<String> Reslut = new List<string>();

        public SplitChineseCharacter(String input)
        {
            this.input = input;
        }

        public void start()
        {
            String temp = null;
            for (int i = 0; i < this.input.Length; i++)
            {
                temp = this.input.Substring(i); // 每次从字符串的首部截取一个字,并存到temp中
                // 如果该词在字典中, 则删除该词并在原始字符串中截取该词
                if (this.isInDictionary(temp))
                {
                    Reslut.Add(temp);
                    this.input = this.input.Replace(temp, "");
                    i = -1; // i=-1是因为要重新查找, 而要先执行循环中的i++
                }
            }

            // 当前循环完毕,词的末尾截去一个字,继续循环, 直到词变为空
            if (null != this.input && !"".Equals(this.input))
            {
                this.input = this.input.Substring(0, this.input.Length - 1);
                this.start();
            }
        }

        //判断当前词是否在字典中
        public Boolean isInDictionary(String temp)
        {
            for (int i = 0; i < this.dictionary.Length; i++)
            {
                if (temp.Equals(this.dictionary[i]))
                {
                    return true;
                }
            }
            return false;
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClusterCharater
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       private void button1_Click(object sender, EventArgs e)

        { 

            String s=inputtext.Text.Trim();

            SplitChineseCharacter scc = new SplitChineseCharacter(s);


            scc.start();

            foreach (String ss in scc.Reslut)

            {


                output.Text += ss+"/";

           }

        }

    }

}

中文分词技术

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI