コード例 #1
0
ファイル: ICTCLAS.cs プロジェクト: ziyunhx/thrinax
 private ICTCLAS()
 {
     wordSegment = new WordSegment();
     string ErrMsg;
     if (!wordSegment.InitWordSegment(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DataPath) + Path.DirectorySeparatorChar, out ErrMsg))
     {
         throw new Exception("SharpICTCLAS分词器初始化失败:" + ErrMsg);
     }
 }
コード例 #2
0
        internal StockFooTokenizer(TextReader reader, string dictPath)
        {
            this.input = reader;
            this.txt = this.input.ReadToEnd();

            if (StockFooTokenizer.wordSegment == null)
            {
                StockFooTokenizer.wordSegment = new WordSegment();
                StockFooTokenizer.wordSegment.InitWordSegment(dictPath);
            }
        }
コード例 #3
0
ファイル: IctclasSegment.cs プロジェクト: 89sos98/iveely
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="dictPath"></param>
        /// <param name="nKind"></param>
        private IctclasSegment(string dictPath, int nKind = 1)
        {
            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);
        }
コード例 #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);
    }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: Markingmelody/SharpICTCLAS
        //线程的执行函数,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();

        }
コード例 #7
0
ファイル: Program.cs プロジェクト: haojian/word_segmentation
        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();
             }
        }