Ejemplo n.º 1
0
        private void keyWords_Click(object sender, EventArgs e)
        {
            string fileName = "";
            string path     = "";
            String allTxt   = "";
            int    num      = 0;

            if (filePath.Text == "")
            {
                MessageBox.Show("请选择文件!");
            }
            else
            {
                path     = filePath.Text;
                fileName = System.IO.Path.GetFileName(path);
            }
            if (NLPIR.Init(@"F:/Project/Visual Studio 2012/Projects/TextProcess/TextProcess/", 0))
            {
                string keywords = NLPIR.GetFileKeyWords(path, 6, false);
                keyword.Text = keywords;
                //string sql = string.Format("insert into KeyWords(filename,keywords) values('{0}','{1}')", fileName, keywords);
                // num = DbHelperSQL.ExecuteSql(sql);
            }
        }
Ejemplo n.º 2
0
        private void openFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofp      = new OpenFileDialog();
            string         keywords = "";

            if (ofp.ShowDialog() == DialogResult.OK)
            {
                if (NLPIR.Init(@"F:/Project/Visual Studio 2012/Projects/TextProcess/TextProcess/", 0))
                {
                    keywords = NLPIR.GetFileKeyWords(ofp.FileName, 6, false);
                }
                string fileName = System.IO.Path.GetFileName(ofp.FileName);
                filePath.Text = ofp.FileName;
                //string sql = string.Format("select * from KeyWords");
                //DataTable keyWords = DbHelperSQL.Query(sql).Tables[0];
                //var dataRows = keyWords.AsEnumerable().Where<DataRow>(C => C["filename"].ToString() == fileName && C["keywords"].ToString() == keywords);
                //int row = dataRows.Count<DataRow>();
                //if (row==1)
                //{
                //    MessageBox.Show("该文章记录已存在,您可以从历史记录中查找!");
                //}
                keyword.Text = keywords;
            }
        }
Ejemplo n.º 3
0
        List <String> resultList = new List <String>(); //接收最后结果

        //#region 分词数相等
        //public List<String> preSetence(String allTxt)
        //{
        //    String[] setenceArray = allTxt.Split(new char[] { ',', '。', '?','r' });
        //    int n = 1;
        //    for (int m = 0; m < setenceArray.Length; m++)
        //    {
        //        if (m == 0)
        //        {
        //            continue;
        //        }
        //        if (setenceArray[m] == "\r" || setenceArray[m] == " ")
        //        {
        //            continue;
        //        }
        //        string words1 = setenceArray[m].ToString();
        //        words1 = words1.Trim();
        //        if (NLPIR.Init(@"F:/Project/Visual Studio 2012/Projects/TextProcess/TextProcess/", 0))
        //        {
        //                string words2 = setenceArray[m-1].ToString();
        //                words2 = words2.Trim();
        //                    string s1 = NLPIR.ParagraphProcess(words1, true);
        //                    string s2 = NLPIR.ParagraphProcess(words2, true);
        //                    String[] splitDic1 = s1.Split(' ');
        //                    String[] splitDic2 = s2.Split(' ');
        //                    if (splitDic1.Length == splitDic2.Length)
        //                    {
        //                        s1 += "    " + splitDic1.Length;
        //                        s2 += "    " + splitDic2.Length;
        //                        if (resultList.Contains(setenceArray[m]))
        //                        {
        //                            int index = resultList.IndexOf(words1);
        //                            resultList.Insert(index, words2);
        //                        }
        //                        else
        //                        {
        //                            resultList.Add(words1);
        //                            resultList.Add(words2);
        //                        }
        //                    }
        //            n++;
        //        }
        //    }
        //    return resultList;
        //}
        //#endregion

        #region 分词数相等,对应词性相近
        public List <String> preSetence(String allTxt)
        {
            String[] setenceArray = allTxt.Split(new char[] { ',', '。', '?', 'r', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int      n            = 1;

            for (int m = 0; m < setenceArray.Length - 1; m++)
            {
                if (setenceArray[m] == "\r" || setenceArray[m] == " " || setenceArray[m] == "\r\n")
                {
                    continue;
                }
                string words1 = setenceArray[m].ToString();
                words1 = words1.Trim();
                if (NLPIR.Init(@"F:/Project/Visual Studio 2012/Projects/TextProcess/TextProcess/", 0))
                {
                    string words2 = setenceArray[m + 1].ToString();
                    words2 = words2.Trim();
                    string   s1        = NLPIR.ParagraphProcess(words1, true);
                    string   s2        = NLPIR.ParagraphProcess(words2, true);
                    String[] splitDic1 = s1.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    String[] splitDic2 = s2.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (splitDic1.Length == splitDic2.Length)
                    {
                        int count = 0;
                        for (int p = 0; p < splitDic1.Length; p++)
                        {
                            if (splitDic1[p] == "" && splitDic2[p] == "")
                            {
                                continue;
                            }
                            string[] everysplitDic1 = splitDic1[p].ToString().Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                            string[] everysplitDic2 = splitDic2[p].ToString().Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                            if (everysplitDic1[1].Contains(everysplitDic2[1]) || everysplitDic2[1].Contains(everysplitDic1[1]))
                            {
                                count++;
                            }
                        }
                        if (count == splitDic1.Length)
                        {
                            if (resultList.Contains(setenceArray[m]))
                            {
                                int index = resultList.IndexOf(words1);
                                while (resultList[index + 1] != "")
                                {
                                    index++;
                                }
                                resultList.Insert(index + 1, words2);
                            }
                            else
                            {
                                resultList.Add(words1);
                                resultList.Add(words2);
                                resultList.Add("");
                            }
                        }
                    }
                    n++;
                }
            }
            return(resultList);
        }