Exemple #1
0
        public void setUp()
        {
            DetectorFactory.clear();

            LangProfile profile_en = new LangProfile("en");

            foreach (string w in TRAINING_EN.Split(' '))
            {
                profile_en.add(w);
            }
            DetectorFactory.addProfile(profile_en, 0, 3);

            LangProfile profile_fr = new LangProfile("fr");

            foreach (string w in TRAINING_FR.Split(' '))
            {
                profile_fr.add(w);
            }

            DetectorFactory.addProfile(profile_fr, 1, 3);

            LangProfile profile_ja = new LangProfile("ja");

            foreach (string w in TRAINING_JA.Split(' '))
            {
                profile_ja.add(w);
            }
            DetectorFactory.addProfile(profile_ja, 2, 3);
        }
Exemple #2
0
        public void testDetector4()
        {
            Detector detect = DetectorFactory.create();

            detect.append("\u3042\u3042\u3042\u3042a");
            Assert.AreEqual(detect.detect(), "ja");
        }
Exemple #3
0
        public void testDetector3()
        {
            Detector detect = DetectorFactory.create();

            detect.append("d e");
            Assert.AreEqual(detect.detect(), "en");
        }
Exemple #4
0
        public void testDetector1()
        {
            Detector detect = DetectorFactory.Create();

            detect.Append("a");
            Assert.AreEqual(detect.Detect(), "en");
        }
Exemple #5
0
        public void testLangListException()
        {
            IList <string> langList = DetectorFactory.getLangList();

            langList.Add("hoge");
            //langList.add(1, "hoge");
        }
Exemple #6
0
        /// <summary>
        /// load profiles
        /// </summary>
        /// <returns>false if load success</returns>
        private bool LoadProfile()
        {
            string profileDirectory = Get("directory");

            try
            {
                if (profileDirectory != null)
                {
                    DetectorFactory.LoadProfile(profileDirectory);
                }
                else
                {
                    DetectorFactory.LoadProfile();
                }

                long?seed = GetLong("seed");
                if (seed != null)
                {
                    DetectorFactory.SetSeed((int)seed);
                }

                return(false);
            }
            catch (LangDetectException e)
            {
                Console.Error.WriteLine("ERROR: " + e);
                return(true);
            }
        }
Exemple #7
0
        public void testDetector2()
        {
            Detector detect = DetectorFactory.create();

            detect.append("b d");
            Assert.AreEqual(detect.detect(), "fr");
        }
Exemple #8
0
        public void testLangListException()
        {
            IList <string> langList = DetectorFactory.GetLangList();

            Assert.Throws <NotSupportedException>(() => langList.Add("hoge"));
            //langList.Add(1, "hoge");
        }
Exemple #9
0
        public void testLangList()
        {
            IList <string> langList = DetectorFactory.getLangList();

            Assert.AreEqual(langList.Count, 3);
            Assert.AreEqual(langList[0], "en");
            Assert.AreEqual(langList[1], "fr");
            Assert.AreEqual(langList[2], "ja");
        }
        public void LoadProfile(string profilesDirectoryPath)
        {
            if (!System.IO.Directory.Exists(profilesDirectoryPath))
            {
                throw new System.IO.DirectoryNotFoundException(string.Format("The directory {0} does not exist.", profilesDirectoryPath));
            }

            lock (syncLock)
            {
                DetectorFactory.loadProfile(profilesDirectoryPath);
                detector = DetectorFactory.create();
            }
        }
Exemple #11
0
        public void testFactoryFromJsonString()
        {
            DetectorFactory.clear();
            IList <string> profiles = new List <string>();

            profiles.Add(JSON_LANG1);
            profiles.Add(JSON_LANG2);
            DetectorFactory.loadProfile(profiles);
            IList <string> langList = DetectorFactory.getLangList();

            Assert.AreEqual(langList.Count, 2);
            Assert.AreEqual(langList[0], "lang1");
            Assert.AreEqual(langList[1], "lang2");
        }
Exemple #12
0
        private void setDetector(int detectorIndex)
        {
            switch (detectorIndex)
            {
            case 0:
                this.detectorFactory = new MarkerBasedDetectorFactory();
                break;

            case 1:
                this.detectorFactory = new ColorBasedDetectorFactory();
                break;
            }

            this.detector = this.detectorFactory.CreateDetector();
        }
Exemple #13
0
        static void Main(string[] args)
        {
            DetectorFactory.loadProfile("./profiles/");
            foreach (string input in inputTexts)
            {
                Detector detector = DetectorFactory.create();
                detector.append(input);
                Console.WriteLine("Lang: {0}", detector.detect());
                foreach (var prob in detector.getProbabilities())
                {
                    Console.WriteLine("Other: {0} at P({1})", prob.lang, prob.prob);
                }
                Console.WriteLine();
            }

            Console.WriteLine("Done");
            Console.ReadKey();
        }
Exemple #14
0
        /// <summary>
        /// Language detection test for each file (--detectlang option)
        /// <pre>
        /// usage: --detectlang -d [profile directory] -a [alpha] -s [seed] [test file(s)]
        /// </pre>
        public void DetectLang()
        {
            if (LoadProfile())
            {
                return;
            }
            foreach (string filename in arglist)
            {
                StreamReader strm = null;
                try
                {
                    strm = new StreamReader(File.OpenRead(filename));

                    Detector detector = DetectorFactory.Create(GetDouble("alpha", DEFAULT_ALPHA));
                    if (HasOpt("--debug"))
                    {
                        detector.SetVerbose();
                    }
                    detector.Append(strm);
                    var probs = string.Join(" ", detector.GetProbabilities().Select((lang) => lang.ToString()));
                    Console.WriteLine("{0}: {1}", filename, probs);
                }
                catch (IOException e)
                {
                    Debug.WriteLine(e);
                }
                catch (LangDetectException e)
                {
                    Debug.WriteLine(e);
                }
                finally
                {
                    try
                    {
                        if (strm != null)
                        {
                            strm.Close();
                        }
                    }
                    catch (IOException e) { }
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// Shared constructor for both pMC and standard (photon) databases
        /// </summary>
        /// <param name="virtualBoundaryType"></param>
        /// <param name="detectorInputs">List of IDetectorInputs designating binning</param>
        /// <param name="databaseInput">Database information needed for post-processing</param>
        private PhotonDatabasePostProcessor(
            VirtualBoundaryType virtualBoundaryType,
            IList <IDetectorInput> detectorInputs,
            SimulationInput databaseInput)
        {
            _rng = RandomNumberGeneratorFactory.GetRandomNumberGenerator(
                RandomNumberGeneratorType.MersenneTwister, -1); // -1 = random seed

            _virtualBoundaryType = virtualBoundaryType;

            _databaseInput = databaseInput;

            _tissue = Factories.TissueFactory.GetTissue(
                databaseInput.TissueInput,
                databaseInput.Options.AbsorptionWeightingType,
                databaseInput.Options.PhaseFunctionType,
                databaseInput.Options.RussianRouletteWeightThreshold);

            _detectors = DetectorFactory.GetDetectors(detectorInputs, _tissue, _rng);

            _detectorController = new DetectorController(_detectors);
        }
Exemple #16
0
        public void demonstrate_user_defined_detector_usage()
        {
            DetectorFactory.RegisterDetector(typeof(ROfXDetectorInput), typeof(ROfXDetector));

            var detectorInput = new ROfXDetectorInput
            {
                TallyType         = "ROfX",
                Name              = "My First R(x) Detector",
                TallySecondMoment = true,
                X = new DoubleRange(0, 10, 101),
            };

            var simInput = new SimulationInput
            {
                DetectorInputs = new[] { detectorInput },
                N = 100,
            };

            var sim = simInput.CreateSimulation();

            var results = sim.Run();

            IDetector detector;

            var detectorExists = results.ResultsDictionary.TryGetValue(detectorInput.Name, out detector);

            Assert.IsTrue(detectorExists);

            var firstValue = ((ROfXDetector)detector).Mean.FirstOrDefault();

            Assert.IsTrue(firstValue != 0);

            DetectorIO.WriteDetectorToFile(detector, "user_defined_detector");

            var deserializedDetector = DetectorIO.ReadDetectorFromFile("user_defined_detector", "");
        }
Exemple #17
0
        /// <summary>
        /// 新建自动分类窗口
        /// </summary>
        /// <param name="type">分类标准</param>
        /// <param name="select">窗口对象</param>
        /// <param name="lv">被分类列表</param>
        /// <param name="protect">最小分类数量</param>
        public void NewList(BuildListType type, select select, ListView lv, int protect)
        {
            int num = 0;

            switch (type)
            {
            case BuildListType.Artist: num = 3; break;

            case BuildListType.FileType: num = 2; break;

            case BuildListType.Path: num = 6; break;

            case BuildListType.Country:
            {
                select.Show();
                Dictionary <int, ListViewItem> selectdic2 = new Dictionary <int, ListViewItem>();
                Dictionary <int, string>       langdic    = new Dictionary <int, string>();
                int j = 0;
                foreach (ListViewItem lvi in lv.Items)
                {
                    Detector detector = DetectorFactory.create();
                    try
                    {
                        detector.append(lvi.SubItems[0].Text);
                        langdic.Add(j, detector.detect());
                    }
                    catch (LanguageDetect.LangDetectException) { }
                    selectdic2.Add(j, lvi);
                    j++;
                }
                for (int x = 0; x < lv.Items.Count; x++)
                {
                    int    tempnum  = 0;
                    string tempname = null;
                    Dictionary <int, ListViewItem> itemdic = new Dictionary <int, ListViewItem>();
                    if (langdic.ContainsKey(x))
                    {
                        int selectindex = 0;
                        for (int y = x; y < lv.Items.Count; y++)
                        {
                            if (langdic.ContainsKey(y))
                            {
                                if (langdic[x] == langdic[y])
                                {
                                    tempnum++;
                                    tempname = langdic[x];
                                    itemdic.Add(selectindex, selectdic2[y]);
                                    if (x != y)
                                    {
                                        langdic.Remove(y);
                                    }
                                    selectindex++;
                                }
                            }
                        }
                    }
                    if (tempnum > 0)
                    {
                        switch (tempname)
                        {
                        case "th": tempname = "泰语"; break;

                        case "fi": tempname = "芬兰语"; break;

                        case "fr": tempname = "法语"; break;

                        case "it": tempname = "意大利语"; break;

                        case "ru": tempname = "俄语"; break;

                        case "es": tempname = "西班牙语"; break;

                        case "ja": tempname = "日语"; break;

                        case "en": tempname = "英语"; break;

                        case "ko": tempname = "韩语"; break;

                        case "zh-cn": tempname = "中文(简)"; break;

                        case "zh-tw": tempname = "中文(繁)"; break;
                        }
                        TabPage tpage = new TabPage();
                        tpage.Text = tempname;
                        tpage.Name = "New List " + Data.selectlist;
                        ListView lv2 = new ListView();
                        lv2.Name = "List" + Data.selectlist;
                        lv2.Columns.Add("标题", 150, HorizontalAlignment.Center);
                        lv2.Columns.Add("长度(秒)", 65, HorizontalAlignment.Center);
                        lv2.Columns.Add("路径", 260, HorizontalAlignment.Center);
                        lv2.View               = System.Windows.Forms.View.Details;
                        lv2.FullRowSelect      = true;
                        lv2.MultiSelect        = true;
                        lv2.GridLines          = true;
                        lv2.AllowColumnReorder = true;
                        lv2.Dock               = DockStyle.Fill;
                        lv2.Location           = new System.Drawing.Point(0, 0);
                        tpage.Controls.Add(lv2);
                        select.SelectControl.TabPages.Add(tpage);
                        lv2.BeginUpdate();           //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
                        for (int k = 0; k < tempnum; k++)
                        {
                            ListViewItem lvi = new ListViewItem();
                            lvi.Text = itemdic[k].SubItems[0].Text;                     //标题
                            lvi.SubItems.Add(itemdic[k].SubItems[1].Text);              //长度
                            lvi.SubItems.Add(itemdic[k].SubItems[6].Text.Remove(0, 9)); //路径
                            lv2.Items.Add(lvi);
                        }
                        lv2.EndUpdate();
                    }
                }
                return;

                break;
            }
            }
            select.Show();
            Dictionary <int, ListViewItem> selectdic = new Dictionary <int, ListViewItem>();
            int i = 0;

            foreach (ListViewItem lvi in lv.Items)
            {
                selectdic.Add(i, lvi);
                i++;
            }
            for (int x = 0; x < lv.Items.Count; x++)
            {
                int    tempnum  = 0;
                string tempname = null;
                Dictionary <int, ListViewItem> itemdic = new Dictionary <int, ListViewItem>();
                if (selectdic.ContainsKey(x))
                {
                    int selectindex = 0;
                    for (int y = x; y < lv.Items.Count; y++)
                    {
                        if (selectdic.ContainsKey(y))
                        {
                            if (num == 6)
                            {
                                string[] index  = selectdic[x].SubItems[num].Text.Split(new char[] { '\\' });
                                string[] index2 = selectdic[y].SubItems[num].Text.Split(new char[] { '\\' });
                                if (index[index.Length - 2] == index2[index2.Length - 2])
                                {
                                    tempnum++;
                                    tempname = index2[index2.Length - 2];
                                    itemdic.Add(selectindex, selectdic[y]);
                                    if (x != y)
                                    {
                                        selectdic.Remove(y);
                                    }
                                    selectindex++;
                                }
                            }
                            else
                            {
                                string[] index  = selectdic[x].SubItems[num].Text.Split(new char[] { '\\' });
                                string[] index2 = selectdic[y].SubItems[num].Text.Split(new char[] { '\\' });
                                if (selectdic[x].SubItems[num].Text == selectdic[y].SubItems[num].Text)
                                {
                                    tempnum++;
                                    tempname = selectdic[y].SubItems[num].Text;
                                    itemdic.Add(selectindex, selectdic[y]);
                                    if (x != y)
                                    {
                                        selectdic.Remove(y);
                                    }
                                    selectindex++;
                                }
                            }
                        }
                    }
                }
                if (tempnum > protect)
                {
                    if (tempname == "")
                    {
                        tempname = "Unknown";
                    }
                    TabPage tpage = new TabPage();
                    tpage.Text = tempname;
                    tpage.Name = "New List " + Data.selectlist;
                    ListView lv1 = new ListView();
                    lv1.Name = "List" + Data.selectlist;
                    lv1.Columns.Add("标题", 150, HorizontalAlignment.Center);
                    lv1.Columns.Add("长度(秒)", 65, HorizontalAlignment.Center);
                    lv1.Columns.Add("路径", 260, HorizontalAlignment.Center);
                    lv1.View               = System.Windows.Forms.View.Details;
                    lv1.FullRowSelect      = true;
                    lv1.MultiSelect        = true;
                    lv1.GridLines          = true;
                    lv1.AllowColumnReorder = true;
                    lv1.Dock               = DockStyle.Fill;
                    lv1.Location           = new System.Drawing.Point(0, 0);
                    tpage.Controls.Add(lv1);
                    select.SelectControl.TabPages.Add(tpage);
                    lv1.BeginUpdate();
                    for (int j = 0; j < tempnum; j++)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = itemdic[j].SubItems[0].Text;                     //标题
                        lvi.SubItems.Add(itemdic[j].SubItems[1].Text);              //长度
                        lvi.SubItems.Add(itemdic[j].SubItems[6].Text.Remove(0, 9)); //路径
                        lv1.Items.Add(lvi);
                    }
                    lv1.EndUpdate();
                }
            }
        }
Exemple #18
0
 public void AssignDetector(string detector)
 {
     _detector = DetectorFactory.GetDetector(detector).Value;
 }
Exemple #19
0
 public void AssignCaptureSource(string source, string detector)
 {
     _detector = DetectorFactory.GetDetector(detector).Value;
     _capture  = SourceFactory.GetCaptureDevice(source, FrameProcessor).Value;
 }
Exemple #20
0
        /// <summary>
        /// Class that takes in SimulationInput and methods to initialize and execute Monte Carlo simulation
        /// </summary>
        /// <param name="input">SimulationInput</param>
        public MonteCarloSimulation(SimulationInput input)
        {
            _outputPath = "";

            // all field/property defaults should be set here
            _input = input;

            var result = SimulationInputValidation.ValidateInput(_input);

            if (result.IsValid == false)
            {
                throw new ArgumentException(result.ValidationRule + (!string.IsNullOrEmpty(result.Remarks) ? "; " + result.Remarks : ""));
            }

            _numberOfPhotons = input.N;

            AbsorptionWeightingType = input.Options.AbsorptionWeightingType; // CKH add 12/14/09
            TrackStatistics         = input.Options.TrackStatistics;
            if (TrackStatistics)
            {
                _simulationStatistics = new SimulationStatistics();
            }
            _rng = RandomNumberGeneratorFactory.GetRandomNumberGenerator(
                input.Options.RandomNumberGeneratorType, input.Options.Seed);

            this.SimulationIndex = input.Options.SimulationIndex;

            _tissue = TissueFactory.GetTissue(input.TissueInput, input.Options.AbsorptionWeightingType, input.Options.PhaseFunctionType, input.Options.RussianRouletteWeightThreshold);
            _source = SourceFactory.GetSource(input.SourceInput, _rng);

            // instantiate vb (and associated detectors) for each vb group
            _virtualBoundaryController = new VirtualBoundaryController(new List <IVirtualBoundary>());

            List <VirtualBoundaryType> dbVirtualBoundaries =
                input.Options.Databases.Select(db => db.GetCorrespondingVirtualBoundaryType()).ToList();


            foreach (var vbType in EnumHelper.GetValues <VirtualBoundaryType>())
            {
                IEnumerable <IDetectorInput> detectorInputs = null;

                switch (vbType)
                {
                case VirtualBoundaryType.DiffuseReflectance:
                default:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IsReflectanceTally).ToList();
                    break;

                case VirtualBoundaryType.DiffuseTransmittance:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IsTransmittanceTally).ToList();
                    break;

                case VirtualBoundaryType.SpecularReflectance:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IsSpecularReflectanceTally).ToList();
                    break;

                case VirtualBoundaryType.GenericVolumeBoundary:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IsVolumeTally).ToList();
                    break;

                case VirtualBoundaryType.SurfaceRadiance:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IsInternalSurfaceTally).ToList();
                    break;

                case VirtualBoundaryType.pMCDiffuseReflectance:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IspMCReflectanceTally).ToList();
                    break;

                case VirtualBoundaryType.BoundingCylinderVolume:
                    detectorInputs = input.DetectorInputs.Where(d => d.TallyDetails.IsBoundingVolumeTally).ToList();
                    break;
                }

                // make sure VB Controller has at least diffuse reflectance and diffuse transmittance
                // may change this in future if tissue OnDomainBoundary changes
                if ((detectorInputs.Count() > 0) || (vbType == VirtualBoundaryType.DiffuseReflectance) ||
                    (vbType == VirtualBoundaryType.DiffuseTransmittance) || (dbVirtualBoundaries.Any(vb => vb == vbType)))
                {
                    var detectors          = DetectorFactory.GetDetectors(detectorInputs, _tissue, _rng);
                    var detectorController = DetectorControllerFactory.GetDetectorController(vbType, detectors, _tissue);
                    // var detectorController = new DetectorController(detectors);
                    var virtualBoundary = VirtualBoundaryFactory.GetVirtualBoundary(vbType, _tissue, detectorController);
                    _virtualBoundaryController.VirtualBoundaries.Add(virtualBoundary);
                }
            }

            // needed?
            //_detectorControllers = _virtualBoundaryController.VirtualBoundaries.Select(vb=>vb.DetectorController).ToList();

            // set doPMC flag
            if (input.Options.Databases.Any(d => d.IspMCDatabase()))
            {
                doPMC = true;
            }

            _isCancelled      = false;
            _isRunning        = false;
            _resultsAvailable = false;
        }
Exemple #21
0
 public CreateLocationSourceCommand(Panel userListContainer, DetectorFactory detectorFactory)
 {
     this.userListContainer = userListContainer;
     this.detectorFactory   = detectorFactory;
 }
        /// <summary>
        /// 按标题语言进行分类
        /// </summary>
        public void ByTitle(bool fristInit)
        {
            if (fristInit)
            {
                try
                {
                    DetectorFactory.loadProfile(@"profiles\");
                    Detector test = DetectorFactory.create();
                    test.append("test");
                }
                catch (BadImageFormatException)
                {
                    MessageBox.Show(
                        "检测到您未安装相关依赖包,如果需要请前往以下地址下载\n32位:http://www.microsoft.com/en-us/download/details.aspx?id=18084 \n64位:http://www.microsoft.com/en-us/download/details.aspx?id=15468");
                    return;
                }
            }

            for (int i = 0; i < infobase.Count; i++)
            {
                MusicInfo info = infobase[i];
                infoFlags[i] = new InfoFlag();
                Detector detector = DetectorFactory.create();
                string   tag      = info.Title;
                if (Setting.Default.isScanLyric)
                {
                    if (File.Exists(Path.ChangeExtension(info.Path, "lrc")))
                    {
                        try
                        {
                            StreamReader reader1 =
                                new StreamReader(
                                    new FileStream(Path.ChangeExtension(info.Path, "lrc"), FileMode.Open,
                                                   FileAccess.Read), EncodingType.GetType(Path.ChangeExtension(info.Path, "lrc")));
                            tag += Format.LyricDelTime(reader1.ReadToEnd());
                        }
                        catch (IOException e)
                        {
                            MessageBox.Show("无法读取歌词文件:" + Path.ChangeExtension(info.Path, "lrc") + "。" + e.Message);
                        }
                    }
                }

                try
                {
                    detector.append(tag);
                    switch (detector.detect())
                    {
                    case "th": infoFlags[i].Flag = "泰语"; break;

                    case "fi": infoFlags[i].Flag = "芬兰语"; break;

                    case "fr": infoFlags[i].Flag = "法语"; break;

                    case "it": infoFlags[i].Flag = "意大利语"; break;

                    case "ru": infoFlags[i].Flag = "俄语"; break;

                    case "es": infoFlags[i].Flag = "西班牙语"; break;

                    case "ja": infoFlags[i].Flag = "日语"; break;

                    case "en": infoFlags[i].Flag = "英语"; break;

                    case "ko": infoFlags[i].Flag = "韩语"; break;

                    case "zh-cn": infoFlags[i].Flag = "中文(简)"; break;

                    case "zh-tw": infoFlags[i].Flag = "中文(繁)"; break;
                    }
                }
                catch (BadImageFormatException)
                {
                    MessageBox.Show("检测到您未安装相关依赖包,如果需要请前往以下地址下载\n32位:http://www.microsoft.com/en-us/download/details.aspx?id=18084 \n64位:http://www.microsoft.com/en-us/download/details.aspx?id=15468");
                    return;
                }
                catch (LangDetectException)
                {
                    infoFlags[i].Flag = "检测失败的项目";
                }
                infoFlags[i].MusicInfo = info;
            }
            StartSort();
            MoveToTab(Setting.Default.LeastCountry);
        }
Exemple #23
0
        /// <summary>
        /// Batch Test of Language Detection (--batchtest option)
        /// <pre>
        /// usage: --batchtest -d [profile directory] -a [alpha] -s [seed] [test data(s)]
        /// </pre>
        /// The format of test data(s):
        /// <pre>
        ///   [correct language name]\t[text body for test]\n
        /// </pre>
        public void BatchTest()
        {
            if (LoadProfile())
            {
                return;
            }
            Dictionary <string, List <string> > result = new Dictionary <string, List <string> >();

            foreach (string filename in arglist)
            {
                StreamReader strm = null;
                try
                {
                    strm = new StreamReader(File.OpenRead(filename));
                    while (!strm.EndOfStream)
                    {
                        string line = strm.ReadLine();
                        int    idx  = line.IndexOf('\t');
                        if (idx <= 0)
                        {
                            continue;
                        }
                        string correctLang = line.Substring(0, idx);
                        string text        = line.Substring(idx + 1);

                        Detector detector = DetectorFactory.Create(GetDouble("alpha", DEFAULT_ALPHA));
                        detector.Append(text);
                        string lang = "";
                        try
                        {
                            lang = detector.Detect();
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e);
                        }
                        if (!result.ContainsKey(correctLang))
                        {
                            result[correctLang] = new List <string>();
                        }
                        result[correctLang].Add(lang);
                        if (HasOpt("--debug"))
                        {
                            Console.WriteLine(correctLang + "," + lang + "," + (text.Length > 100 ? text.Substring(0, 100) : text));
                        }
                    }
                }
                catch (IOException e)
                {
                    Debug.WriteLine(e);
                }
                catch (LangDetectException e)
                {
                    Debug.WriteLine(e);
                }
                finally
                {
                    try
                    {
                        if (strm != null)
                        {
                            strm.Close();
                        }
                    }
                    catch (IOException e) { }
                }

                List <string> langlist = new List <string>(result.Keys);
                langlist.Sort();

                int totalCount = 0, totalCorrect = 0;
                foreach (string lang in langlist)
                {
                    Dictionary <string, int> resultCount = new Dictionary <string, int>();
                    int           count = 0;
                    List <string> list  = result[lang];
                    foreach (string detectedLang in list)
                    {
                        ++count;
                        if (resultCount.ContainsKey(detectedLang))
                        {
                            resultCount[detectedLang] = resultCount[detectedLang] + 1;
                        }
                        else
                        {
                            resultCount[detectedLang] = 1;
                        }
                    }
                    int    correct = resultCount.ContainsKey(lang) ? resultCount[lang] : 0;
                    double rate    = correct / (double)count;
                    Console.WriteLine(string.Format("%s (%d/%d=%.2f): %s", lang, correct, count, rate, resultCount));
                    totalCorrect += correct;
                    totalCount   += count;
                }
                Console.WriteLine(string.Format("total: %d/%d = %.3f", totalCorrect, totalCount, totalCorrect / (double)totalCount));
            }
        }