Ejemplo n.º 1
0
        public void testDetector4()
        {
            Detector detect = DetectorFactory.create();

            detect.append("\u3042\u3042\u3042\u3042a");
            Assert.AreEqual(detect.detect(), "ja");
        }
Ejemplo n.º 2
0
        public void testDetector3()
        {
            Detector detect = DetectorFactory.create();

            detect.append("d e");
            Assert.AreEqual(detect.detect(), "en");
        }
Ejemplo n.º 3
0
        public void testDetector2()
        {
            Detector detect = DetectorFactory.create();

            detect.append("b d");
            Assert.AreEqual(detect.detect(), "fr");
        }
        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();
            }
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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();
                }
            }
        }
        /// <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);
        }