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();
            }
        }
Пример #2
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");
        }
Пример #3
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();
        }
        /// <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);
        }