Exemple #1
0
        /// <exception cref="System.Exception"/>
        public static void Main(string[] args)
        {
            Runtime.SetOut(new TextWriter(System.Console.Out, true, "utf-8"));
            Properties props = new Properties();

            props.SetProperty("sighanCorporaDict", basedir);
            // props.setProperty("NormalizationTable", "data/norm.simp.utf8");
            // props.setProperty("normTableEncoding", "UTF-8");
            // below is needed because CTBSegDocumentIteratorFactory accesses it
            props.SetProperty("serDictionary", basedir + "/dict-chris6.ser.gz");
            if (args.Length > 0)
            {
                props.SetProperty("testFile", args[0]);
            }
            props.SetProperty("inputEncoding", "UTF-8");
            props.SetProperty("sighanPostProcessing", "true");
            CRFClassifier <CoreLabel> segmenter = new CRFClassifier <CoreLabel>(props);

            segmenter.LoadClassifierNoExceptions(basedir + "/ctb.gz", props);
            foreach (string filename in args)
            {
                segmenter.ClassifyAndWriteAnswers(filename);
            }
            string         sample    = "我住在美国。";
            IList <string> segmented = segmenter.SegmentString(sample);

            System.Console.Out.WriteLine(segmented);
        }