Exemple #1
0
        //public void analysisTest3()
        //{
        //    string path = @"D:\文档\人工智能\语料\聊天机器人词库\纯化\";
        //    string[] files = Directory.GetFiles(path);
        //    string outfile = path + @"result.txt";
        //    Dictionary<string, string> dir = new Dictionary<string, string>();
        //    foreach(string file in files)
        //    {
        //        string[] res = File.ReadAllLines(file,Encoding.Default);
        //        List<string> reslist = new List<string>();
        //        for(int i = 0; i < res.Length; i++)
        //        {

        //            if (!string.IsNullOrWhiteSpace(res[i]))
        //            {
        //                reslist.Add(res[i]);
        //            }
        //            else
        //            {
        //                if (reslist.Count >= 2)
        //                {
        //                    if (reslist[0].Contains("[") && reslist[0].Contains("]")) { reslist.Clear(); continue; }
        //                    reslist[0] = reslist[0].Replace("[name]", "你").Replace("[cqname]", "我").Replace("[enter]"," ");
        //                    reslist[1] = reslist[1].Replace("[name]", "你").Replace("[cqname]", "我").Replace("[enter]", " ");
        //                    reslist[1] = Regex.Replace(reslist[1], @"\[.*?\]", "");
        //                    if (dir.ContainsKey(reslist[0]))
        //                    {
        //                        //have it
        //                        if (reslist[0].Length > dir[reslist[0]].Length)
        //                        {
        //                            if (reslist[1].Contains("http")) { reslist.Clear(); continue; }
        //                            //change
        //                            dir[reslist[0]] = reslist[1];
        //                        }
        //                    }
        //                    else
        //                    {
        //                        //dont have
        //                        dir[reslist[0]] = reslist[1];
        //                    }

        //                }
        //                reslist.Clear();

        //            }

        //        }
        //    }
        //    using(FileStream fs=new FileStream(outfile, FileMode.Create))
        //    {
        //        using(StreamWriter sw=new StreamWriter(fs,Encoding.UTF8))
        //        {
        //            foreach (var k in dir)
        //            {
        //                sw.WriteLine(string.Format("{0}\r\n{1}\r\n",k.Key,k.Value));
        //            }
        //        }
        //    }

        //}

        //private void analysisTest4()
        //{
        //    string file = @"D:\文档\人工智能\语料\聊天机器人词库\纯化\result.txt";
        //    //Dictionary<string, List<Pair>> dir = new Dictionary<string, List<Pair>>();
        //    string[] res = File.ReadAllLines(file, Encoding.UTF8);


        //    string resstr = "";
        //    for (int i = 0; i < res.Length; i++)
        //    {
        //        string key = res[i++];
        //        string value = res[i++];
        //        List<Pair> valueWords = WordCutTool.cut(value);

        //        resstr += string.Format("{0}\t{1}\t{2}\r\n", key, value, 1);
        //        foreach (var p in valueWords)
        //        {
        //            if (p.Flag.StartsWith("n") || p.Flag.StartsWith("v") || p.Flag.StartsWith("a"))
        //            {
        //                resstr += string.Format("{0}\t{1}\t{2}\r\n", value, p.Word, 2);
        //            }
        //        }
        //        //dir[key] = valueWords;
        //        if (i > 1000) break;
        //    }

        //    printChangeResult(resstr);

        //}

        private void analysis5()
        {
            var    res    = WordCutTool.cutSentence(textBox1.Text);
            string output = "";

            foreach (var sen in res)
            {
                foreach (var w in sen)
                {
                    if (w.Flag.ToUpper().StartsWith("N") || w.Flag.ToUpper().StartsWith("R"))
                    {
                        output += "[" + w.Word + "]";
                    }
                    else if (w.Flag.ToUpper().StartsWith("V"))
                    {
                        output += "" + w.Word + "";
                    }
                    else if (w.Flag.ToUpper().StartsWith("U"))
                    {
                        ;
                    }
                    else
                    {
                        output += w.Word + w.Flag;
                    }
                }
                output += "\r\n\r\n";
            }

            printChangeResult(output);
        }
Exemple #2
0
        public void analysisTest2()
        {
            string text1 = textBox1.Text;


            var res = WordCutTool.cut(text1);

            List <WordPair> out1  = new List <WordPair>();
            List <WordPair> verbs = WordCutTool.sumPair(res, "V");

            foreach (var v in verbs)
            {
                for (int i = 1; i < res.Count - 1; i++)
                {
                    if (res[i].Flag == v.Flag && res[i].Word == v.Word)
                    {
                        //verb
                        out1.Add(new WordPair(string.Format("{0}\t{1}\t{2}\r\n", res[i - 1].Flag, res[i].Word, res[i + 1].Flag), ""));
                    }
                }
            }


            printChangeResult(WordCutTool.getString(out1));
        }
Exemple #3
0
        public void analysisTest1()
        {
            string text1 = textBox1.Text;
            var    res   = WordCutTool.cut(text1);

            List <WordPair> out1 = new List <WordPair>();

            foreach (var w in res)
            {
                //if (w.Flag.ToUpper().StartsWith("V")) out1.Add(new Pair("[ V " + w.Word + " ]", "v"));
                //else if (w.Flag.ToUpper().StartsWith("N")) out1.Add(new Pair("[ N " + w.Word + " ]", "n"));
                //else if (w.Flag.ToUpper().StartsWith("A")) out1.Add(new Pair("[ A " + w.Word + " ]", "a"));
                // else if (w.Flag.ToUpper().StartsWith("D")) out1.Add(new Pair("[D" + w.Word + "]", "d"));
                if (w.Flag == "x" && (",。?!…—;,.?!()()“”‘’\r\n\t ".Contains(w.Word) || w.Word.Length <= 0))
                {
                    out1.Add(new WordPair(" [" + w.Word + "/" + w.Flag + "]\r\n\r\n", ""));
                }
                else
                {
                    out1.Add(new WordPair(" [" + w.Word + "/" + w.Flag + "]", ""));
                }
            }
            printChangeResult(WordCutTool.getString(out1));
        }
Exemple #4
0
        private void workChangeWords()
        {
            string text1 = textBox1.Text;
            string text2 = textBox3.Text;

            print("开始分析文本1");
            var res   = WordCutTool.cut(text1);
            var verbs = WordCutTool.sumPair(res, "V");
            var nones = WordCutTool.sumPair(res, "N");
            var adjs  = WordCutTool.sumPair(res, "A");

            print("开始分析文本2");
            var res2   = WordCutTool.cut(text2);
            var verbs2 = WordCutTool.sumPair(res2, "V");
            var nones2 = WordCutTool.sumPair(res2, "N");
            var adjs2  = WordCutTool.sumPair(res2, "A");

            List <WordPair[]> changeres = new List <WordPair[]>();

            for (int i = 0; i < verbs.Count; i++)
            {
                WordPair[] c = new WordPair[2];
                c[0] = verbs[i];
                if (verbs2.Count > i)
                {
                    c[1] = verbs2[i];
                }
                else
                {
                    c[1] = c[0];
                }
                changeres.Add(c);
            }
            for (int i = 0; i < nones.Count; i++)
            {
                WordPair[] c = new WordPair[2];
                c[0] = nones[i];
                if (nones2.Count > i)
                {
                    c[1] = nones2[i];
                }
                else
                {
                    c[1] = c[0];
                }
                changeres.Add(c);
            }
            for (int i = 0; i < adjs.Count; i++)
            {
                WordPair[] c = new WordPair[2];
                c[0] = adjs[i];
                if (adjs2.Count > i)
                {
                    c[1] = adjs2[i];
                }
                else
                {
                    c[1] = c[0];
                }
                changeres.Add(c);
            }

            List <WordPair> respair = new List <WordPair>();

            foreach (var w in res)
            {
                bool change = false;
                foreach (var wp in changeres)
                {
                    if (w.Flag == wp[0].Flag && w.Word == wp[0].Word)
                    {
                        respair.Add(new WordPair(wp[1].Word, wp[1].Flag));
                        change = true;
                        break;
                    }
                }
                if (!change)
                {
                    respair.Add(w);
                }
            }
            printChangeResult(WordCutTool.getString(respair));
            //print();
            print("分析结束");
        }