Exemple #1
0
 private ICTCLASSharp()
 {
     wordSegment = new WordSegment();
     string ErrMsg;
     if (!wordSegment.InitWordSegment(Path.Combine(RuntimeInfo.BaseDirectory, DataPath) + Path.DirectorySeparatorChar, out ErrMsg))
     {
         throw new Exception("SharpICTCLAS分词器初始化失败:" + ErrMsg);
     }
 }
Exemple #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dictPath"></param>
 /// <param name="nKind"></param>
 public WordSegmentApp(string dictPath, int nKind)
 {
     this.wordSegment = new WordSegment();
     //wordSegment.PersonRecognition = false;
     //wordSegment.PlaceRecognition = false;
     //wordSegment.TransPersonRecognition = false;
     //wordSegment.OnSegmentEvent += new SegmentEventHandler(this.OnSegmentEventHandler);
     wordSegment.InitWordSegment(dictPath);
     this.dictPath = dictPath;
     this.nKind    = nKind;
 }
Exemple #3
0
 public Segment(string dictpath)
 {
     if (wordSegment == null)
     {
         wordSegment = new WordSegment();
         dictPath    = dictpath;
         wordSegment.InitWordSegment(dictpath);
         wordSegment.PersonRecognition      = false;
         wordSegment.TransPersonRecognition = false;
         wordSegment.PlaceRecognition       = false;
     }
 }
Exemple #4
0
    //=======================================================
    // 构造函数
    //=======================================================
    public WordSegmentSample(string dictPath, int nKind)
    {
        this.nKind       = nKind;
        this.wordSegment = new WordSegment();
        //wordSegment.PersonRecognition = false;
        //wordSegment.PlaceRecognition = false;
        //wordSegment.TransPersonRecognition = false;

        //---------- 订阅分词过程中的事件 ----------
        wordSegment.OnSegmentEvent += new SegmentEventHandler(this.OnSegmentEventHandler);
        wordSegment.InitWordSegment(dictPath);
    }
Exemple #5
0
 public static WordSegment GetWordSegmentInstance()
 {
     if (wordSegment == null)
     {
         wordSegment = new WordSegment();
         wordSegment.InitWordSegment(ConfigurationManager.AppSettings["IctclasData"]);
         return(wordSegment);
     }
     else
     {
         return(wordSegment);
     }
 }
Exemple #6
0
        //线程的执行函数,for循环中线程根据自身的ID,加2取文本文件,保证两个线程的输入文件没有交集
        private static void AnalyFuc(object order)
        {
            int         num         = ((Para)order).Num;
            WordSegment wordSegment = new WordSegment();

            wordSegment.InitWordSegment(DictPath);
            StreamReader sr = null;
            StreamWriter sw = new StreamWriter(outDir + num + ".txt", false, System.Text.Encoding.Default);

            for (int i = num; i < fileList.Count; i += 2)
            {
                sr = new StreamReader(fileList[i], System.Text.Encoding.Default);
                string input = "";
                input = sr.ReadLine();
                List <WordResult[]> result = null;
                while (input != null)
                {
                    if (input == "")
                    {
                        input = sr.ReadLine();
                        continue;
                    }
                    try
                    {
                        result = wordSegment.Segment(input);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        continue;
                    }
                    for (int j = 1; j < result[0].Length - 1; ++j)
                    {
                        sw.Write(result[0][j].sWord + " ");
                    }
                    sw.WriteLine("");
                    input = sr.ReadLine();
                }
                sr.Close();
            }

            sw.Close();
        }
 private static WordSegment getWordSegmentInstance()
 {
     if (ms_wordSegment == null)
     {
         try
         {
             string dictPath = Path.Combine(Environment.CurrentDirectory, "SegmentDict") + Path.DirectorySeparatorChar;
             ms_wordSegment = new WordSegment();
             ms_wordSegment.InitWordSegment(dictPath);
             log.Debug("正在初始化字典库,请稍候...");
         }
         catch (Exception e)
         {
             System.Windows.Forms.MessageBox.Show("字典库初始化失败!", "错误", System.Windows.Forms.MessageBoxButtons.OK);
             log.Debug("字典库初始化失败");
         }
     }
     return(ms_wordSegment);
 }
Exemple #8
0
 public SearchMessage(string dictpath)
 {
     wordSegment = new WordSegment();
     wordSegment.InitWordSegment(dictpath);
 }
Exemple #9
0
        public static void TestNShortPath()
        {
            int          n = 2;
            List <int[]> result;

            int[] aPath;
            //--------------------------------------------------------------edie by SharpKey
            string dictPath = Path.Combine(Environment.CurrentDirectory, "Data") + Path.DirectorySeparatorChar;

            Console.WriteLine("正在初始化字典库,请稍候...");
            //WordSegmentSample sample = new WordSegmentSample(DictPath, 2);
            WordSegment wordSegment = new WordSegment();

            wordSegment.InitWordSegment(dictPath);
            Segment m_Seg = new Segment(wordSegment.m_dictBigram, wordSegment.m_dictCore);//Seg class
            //wordSegment.Segment("", 2);
            ColumnFirstDynamicArray <ChainContent> apCost = m_Seg.TestSegment("始##始这个人的确实在末##末", 0.1, 2);

            Console.WriteLine(apCost.ToString());
            //----------------------------------
            NShortPath.Calculate(apCost, n);
            NShortPath.printResultByIndex();

            //----------------------------------------------------
            // 所有路径
            //----------------------------------------------------
            Console.WriteLine("\r\n\r\n所有路径:");
            for (int i = 0; i < n; i++)
            {
                result = NShortPath.GetPaths(i);
                for (int j = 0; j < result.Count; j++)
                {
                    aPath = result[j];
                    for (int k = 0; k < aPath.Length; k++)
                    {
                        Console.Write("{0}, ", aPath[k]);
                    }

                    Console.WriteLine();
                }
                Console.WriteLine("========================");
            }

            //----------------------------------------------------
            // 最佳路径
            //----------------------------------------------------
            Console.WriteLine("\r\n最佳路径:");
            aPath = NShortPath.GetBestPath();
            for (int k = 0; k < aPath.Length; k++)
            {
                Console.Write("{0}, ", aPath[k]);
            }

            Console.WriteLine();

            //----------------------------------------------------
            // 最多 n 个路径
            //----------------------------------------------------
            Console.WriteLine("\r\n最多 {0} 条路径:", 5);
            result = NShortPath.GetNPaths(5);
            for (int j = 0; j < result.Count; j++)
            {
                aPath = result[j];
                for (int k = 0; k < aPath.Length; k++)
                {
                    Console.Write("{0}, ", aPath[k]);
                }

                Console.WriteLine();
            }
        }